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">
1162 <row bottomline="true">
1163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1190 <row bottomline="true">
1191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1242 \begin_inset Quotes srd
1246 \begin_inset Quotes srd
1260 \begin_inset Quotes srd
1264 \begin_inset Quotes srd
1292 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1301 \begin_inset Quotes srd
1304 i586-mingw32msvc-gcc
1305 \begin_inset Quotes srd
1309 \begin_inset Quotes srd
1312 i586-mingw32msvc-g++
1313 \begin_inset Quotes srd
1321 \begin_inset Quotes srd
1324 i586-mingw32msvc-ranlib
1325 \begin_inset Quotes srd
1333 \begin_inset Quotes srd
1336 i586-mingw32msvc-strip
1337 \begin_inset Quotes srd
1355 \begin_inset Quotes srd
1359 \begin_inset Quotes srd
1377 \begin_inset Quotes srd
1381 \begin_inset Quotes srd
1389 \begin_inset Quotes srd
1393 \begin_inset Quotes srd
1401 \begin_inset Quotes srd
1405 \begin_inset Quotes srd
1413 \begin_inset Quotes srd
1417 \begin_inset Quotes srd
1424 sdccconf_h_dir_separator=
1425 \begin_inset Quotes srd
1437 \begin_inset Quotes srd
1454 -disable-device-lib-build
1482 -host=i586-mingw32msvc -
1492 -build=unknown-unknown-linux-gnu
1496 \begin_inset Quotes sld
1500 \begin_inset Quotes srd
1503 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1512 \begin_inset Quotes srd
1516 \begin_inset Quotes srd
1524 \begin_inset Quotes srd
1528 \begin_inset Quotes srd
1546 \begin_inset Quotes srd
1550 \begin_inset Quotes srd
1568 \begin_inset Quotes srd
1572 \begin_inset Quotes srd
1580 \begin_inset Quotes srd
1584 \begin_inset Quotes srd
1592 \begin_inset Quotes srd
1596 \begin_inset Quotes srd
1604 \begin_inset Quotes srd
1608 \begin_inset Quotes srd
1615 sdccconf_h_dir_separator=
1616 \begin_inset Quotes srd
1628 \begin_inset Quotes srd
1648 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1659 -C' turns on caching, which gives a little bit extra speed.
1660 However if options are changed, it can be necessary to delete the config.cache
1665 \begin_inset LatexCommand \index{Install paths}
1671 \added_space_top medskip \align center
1673 \begin_inset Tabular
1674 <lyxtabular version="3" rows="5" columns="4">
1676 <column alignment="left" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
1680 <row topline="true" bottomline="true">
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1722 <row topline="true">
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1762 <row topline="true">
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1778 $DATADIR/ $INCLUDE_DIR_SUFFIX
1781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1786 /usr/local/share/sdcc/include
1789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 <row topline="true">
1803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1818 $DATADIR/$LIB_DIR_SUFFIX
1821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 /usr/local/share/sdcc/lib
1829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1842 <row topline="true" bottomline="true">
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1866 /usr/local/share/sdcc/doc
1869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1891 *compiler, preprocessor, assembler, and linker
1897 is auto-appended by the compiler, e.g.
1898 small, large, z80, ds390 etc
1901 The install paths can still be changed during `make install` with e.g.:
1904 make install prefix=$(HOME)/local/sdcc
1907 Of course this doesn't change the search paths compiled into the binaries.
1911 \begin_inset LatexCommand \index{Search path}
1918 Some search paths or parts of them are determined by configure variables
1923 , see section above).
1924 Further search paths are determined by environment variables during runtime.
1927 The paths searched when running the compiler are as follows (the first catch
1933 Binary files (preprocessor, assembler and linker)
1939 \begin_inset Tabular
1940 <lyxtabular version="3" rows="4" columns="3">
1942 <column alignment="block" valignment="top" leftline="true" width="0in">
1943 <column alignment="block" valignment="top" leftline="true" width="0in">
1944 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1945 <row topline="true" bottomline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1971 <row topline="true">
1972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2001 <row topline="true">
2002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 Path of argv[0] (if available)
2010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2027 <row topline="true" bottomline="true">
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2069 \begin_inset Tabular
2070 <lyxtabular version="3" rows="6" columns="3">
2072 <column alignment="left" valignment="top" leftline="true" width="0">
2073 <column alignment="left" valignment="top" leftline="true" width="0">
2074 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
2075 <row topline="true" bottomline="true">
2076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2101 <row topline="true">
2102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2157 <row topline="true">
2158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2185 <row topline="true">
2186 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2195 $PREFIX2DATA_DIR/$INCLUDE_DIR_SUFFIX
2198 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2205 $SDCC_ HOME/share/sdcc/include
2208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2221 <row topline="true">
2222 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2231 $BIN2DATADIR/$INCLUDE_DIR_SUFFIX
2234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2239 path(argv[0])/../sdcc/include
2242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2255 <row topline="true" bottomline="true">
2256 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2264 $DATADIR/$INCLUDE_DIR_SUFFIX
2267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2272 /usr/local/share/sdcc/include
2275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2303 -nostdinc disables the last two search paths.
2313 With the exception of
2314 \begin_inset Quotes sld
2328 \begin_inset Quotes srd
2335 is auto-appended by the compiler (e.g.
2336 small, large, z80, ds390 etc.).
2343 \begin_inset Tabular
2344 <lyxtabular version="3" rows="6" columns="3">
2346 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2347 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2348 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2349 <row topline="true" bottomline="true">
2350 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2358 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2375 <row topline="true">
2376 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2431 <row topline="true">
2432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2444 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2471 <row topline="true">
2472 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2483 $LIB_DIR_SUFFIX/<model>
2486 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2500 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2517 <row topline="true">
2518 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2533 $LIB_DIR_SUFFIX/<model>
2536 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2645 <row topline="true" bottomline="true">
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2655 $LIB_DIR_SUFFIX/<model>
2658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2663 /usr/local/share/sdcc/
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2688 Don't delete any of the stray spaces in the table above without checking
2689 the HTML output (last line)!
2705 -nostdlib disables the last two search paths.
2709 \begin_inset LatexCommand \index{Building SDCC}
2714 \layout Subsubsection
2716 Building SDCC on Linux
2717 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2726 Download the source package
2728 either from the SDCC CVS repository or from the
2729 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2735 , it will be named something like sdcc
2748 Bring up a command line terminal, such as xterm.
2753 Unpack the file using a command like:
2756 "tar -xzf sdcc.src.tar.gz
2761 , this will create a sub-directory called sdcc with all of the sources.
2764 Change directory into the main SDCC directory, for example type:
2781 This configures the package for compilation on your system.
2797 All of the source packages will compile, this can take a while.
2813 This copies the binary executables, the include files, the libraries and
2814 the documentation to the install directories.
2815 \layout Subsubsection
2817 Building SDCC on OSX 2.x
2820 Follow the instruction for Linux.
2824 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2825 )) fails to compile SDCC.
2826 Fortunately there's also gcc 2.9.x installed, which works fine.
2827 This compiler can be selected by running 'configure' with:
2830 ./configure CC=gcc2 CXX=g++2
2831 \layout Subsubsection
2833 Cross compiling SDCC on Linux for Windows
2836 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2837 See section 'Configure Options'.
2838 \layout Subsubsection
2840 Building SDCC on Windows
2843 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2845 They use Unix-sockets, which are not available on Win32.
2846 \layout Subsubsection
2848 Building SDCC using Cygwin and Mingw32
2851 For building and installing a Cygwin executable follow the instructions
2857 \begin_inset Quotes sld
2861 \begin_inset Quotes srd
2864 Win32-binary can be built, which will not need the Cygwin-DLL.
2865 For the necessary 'configure' options see section 'configure options' or
2866 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2870 In order to install Cygwin on Windows download setup.exe from
2871 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2877 \begin_inset Quotes sld
2880 default text file type
2881 \begin_inset Quotes srd
2885 \begin_inset Quotes sld
2889 \begin_inset Quotes srd
2892 and download/install at least the following packages.
2893 Some packages are selected by default, others will be automatically selected
2894 because of dependencies with the manually selected packages.
2895 Never deselect these packages!
2904 gcc ; version 3.x is fine, no need to use the old 2.9x
2907 binutils ; selected with gcc
2913 rxvt ; a nice console, which makes life much easier under windoze (see below)
2916 man ; not really needed for building SDCC, but you'll miss it sooner or
2920 less ; not really needed for building SDCC, but you'll miss it sooner or
2924 cvs ; only if you use CVS access
2927 If you want to develop something you'll need:
2930 python ; for the regression tests
2933 gdb ; the gnu debugger, together with the nice GUI
2934 \begin_inset Quotes sld
2938 \begin_inset Quotes srd
2944 openssh ; to access the CF or commit changes
2947 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
2948 use autoconf-stable!
2951 rxvt is a nice console with history.
2952 Replace in your cygwin.bat the line
2971 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
2974 -bg black -fg white -geometry 100x65 -e bash -
2987 Text selected with the mouse is automatically copied to the clipboard, pasting
2988 works with shift-insert.
2992 The other good tip is to make sure you have no //c/-style paths anywhere,
2993 use /cygdrive/c/ instead.
2994 Using // invokes a network lookup which is very slow.
2996 \begin_inset Quotes sld
3000 \begin_inset Quotes srd
3003 is too long, you can change it with e.g.
3009 SDCC sources use the unix line ending LF.
3010 Life is much easier, if you store the source tree on a drive which is mounted
3012 And use an editor which can handle LF-only line endings.
3013 Make sure not to commit files with windows line endings.
3014 The tabulator spacing used in the project is 8.
3015 \layout Subsubsection
3017 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3022 Download the source package
3024 either from the SDCC CVS repository or from the
3025 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3031 , it will be named something like sdcc
3038 SDCC is distributed with all the projects, workspaces, and files you need
3039 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3040 doesn't build under MSVC).
3041 The workspace name is 'sdcc.dsw'.
3042 Please note that as it is now, all the executables are created in a folder
3046 Once built you need to copy the executables from sdcc
3050 bin before running SDCC.
3055 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3056 flex.exe, and gawk.exe.
3057 One good place to get them is
3058 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3066 Download the file UnxUtils
3067 \begin_inset LatexCommand \index{UnxUtils}
3072 Now you have to install the utilities and setup MSVC so it can locate the
3074 Here there are two alternatives (choose one!):
3081 a) Extract UnxUtils.zip to your C:
3083 hard disk PRESERVING the original paths, otherwise bison won't work.
3084 (If you are using WinZip make certain that 'Use folder names' is selected)
3088 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3089 in 'Show directories for:' select 'Executable files', and in the directories
3090 window add a new path: 'C:
3100 (As a side effect, you get a bunch of Unix utilities that could be useful,
3101 such as diff and patch.)
3108 This one avoids extracting a bunch of files you may not use, but requires
3113 a) Create a directory were to put the tools needed, or use a directory already
3121 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3122 to such directory WITHOUT preserving the original paths.
3123 (If you are using WinZip make certain that 'Use folder names' is not selected)
3127 c) Rename bison.exe to '_bison.exe'.
3131 d) Create a batch file 'bison.bat' in 'C:
3135 ' and add these lines:
3155 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3159 Steps 'c' and 'd' are needed because bison requires by default that the
3160 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3161 '/usr/local/share/' I think.
3162 So it is necessary to tell bison where those files are located if they
3163 are not in such directory.
3164 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3168 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3169 in 'Show directories for:' select 'Executable files', and in the directories
3170 window add a new path: 'c:
3173 Note that you can use any other path instead of 'c:
3175 util', even the path where the Visual C++ tools are, probably: 'C:
3179 Microsoft Visual Studio
3184 So you don't have to execute step 'e' :)
3188 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3189 the executables from sdcc
3193 bin, and you can compile using sdcc.
3194 \layout Subsubsection
3196 Building SDCC Using Borland
3199 From the sdcc directory, run the command "make -f Makefile.bcc".
3200 This should regenerate all the .exe files in the bin directory except for
3201 sdcdb.exe (which currently doesn't build under Borland C++).
3204 If you modify any source files and need to rebuild, be aware that the dependenci
3205 es may not be correctly calculated.
3206 The safest option is to delete all .obj files and run the build again.
3207 From a Cygwin BASH prompt, this can easily be done with the command (be
3208 sure you are in the sdcc directory):
3218 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3220 ) -print -exec rm {}
3229 or on Windows NT/2000/XP from the command prompt with the command:
3236 del /s *.obj *.lib *.rul
3239 from the sdcc directory.
3240 \layout Subsubsection
3242 Windows Install Using a Binary Package
3243 \begin_inset LatexCommand \label{sub:Windows-Install}
3250 Download the binary package from
3251 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3255 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3256 This should unpack to a group of sub-directories.
3257 An example directory structure after unpacking the mingw32 package is:
3262 bin for the executables, c:
3270 lib for the include and libraries.
3273 Adjust your environment variable PATH to include the location of the bin
3274 directory or start sdcc using the full path.
3277 Building the Documentation
3280 If the necessary tools are installed it is as easy as changing into the
3281 doc directory and typing
3285 \begin_inset Quotes srd
3289 \begin_inset Quotes srd
3296 If you want to avoid installing the tools you will have some success with
3297 a bootable Knoppix CD
3298 \begin_inset LatexCommand \url{http://www.knopper.net}
3305 Testing the SDCC Compiler
3308 The first thing you should do after installing your SDCC compiler is to
3324 \begin_inset LatexCommand \index{version}
3331 at the prompt, and the program should run and tell you the version.
3332 If it doesn't run, or gives a message about not finding sdcc program, then
3333 you need to check over your installation.
3334 Make sure that the sdcc bin directory is in your executable search path
3335 defined by the PATH environment setting (see the Trouble-shooting section
3337 Make sure that the sdcc program is in the bin folder, if not perhaps something
3338 did not install correctly.
3346 is commonly installed as described in section
3347 \begin_inset Quotes sld
3350 Install and search paths
3351 \begin_inset Quotes srd
3360 Make sure the compiler works on a very simple example.
3361 Type in the following test.c program using your favorite
3387 Compile this using the following command:
3396 If all goes well, the compiler will generate a test.asm and test.rel file.
3397 Congratulations, you've just compiled your first program with SDCC.
3398 We used the -c option to tell SDCC not to link the generated code, just
3399 to keep things simple for this step.
3407 The next step is to try it with the linker.
3417 If all goes well the compiler will link with the libraries and produce
3418 a test.ihx output file.
3423 (no test.ihx, and the linker generates warnings), then the problem is most
3424 likely that sdcc cannot find the
3428 usr/local/share/sdcc/lib directory
3432 (see the Install trouble-shooting section for suggestions).
3440 The final test is to ensure sdcc can use the
3444 header files and libraries.
3445 Edit test.c and change it to the following:
3462 strcpy(str1, "testing");
3469 Compile this by typing
3476 This should generate a test.ihx output file, and it should give no warnings
3477 such as not finding the string.h file.
3478 If it cannot find the string.h file, then the problem is that sdcc cannot
3479 find the /usr/local/share/sdcc/include directory
3483 (see the Install trouble-shooting section for suggestions).
3501 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3505 to find exactly where SDCC is looking for the include and lib files.
3508 Install Trouble-shooting
3509 \begin_inset LatexCommand \index{Install trouble-shooting}
3514 \layout Subsubsection
3516 SDCC does not build correctly.
3519 A thing to try is starting from scratch by unpacking the .tgz source package
3520 again in an empty directory.
3528 ./configure 2>&1 | tee configure.log
3542 make 2>&1 | tee make.log
3549 If anything goes wrong, you can review the log files to locate the problem.
3550 Or a relevant part of this can be attached to an email that could be helpful
3551 when requesting help from the mailing list.
3552 \layout Subsubsection
3555 \begin_inset Quotes sld
3559 \begin_inset Quotes srd
3566 \begin_inset Quotes sld
3570 \begin_inset Quotes srd
3573 command is a script that analyzes your system and performs some configuration
3574 to ensure the source package compiles on your system.
3575 It will take a few minutes to run, and will compile a few tests to determine
3576 what compiler features are installed.
3577 \layout Subsubsection
3580 \begin_inset Quotes sld
3584 \begin_inset Quotes srd
3590 This runs the GNU make tool, which automatically compiles all the source
3591 packages into the final installed binary executables.
3592 \layout Subsubsection
3595 \begin_inset Quotes sld
3599 \begin_inset Quotes erd
3605 This will install the compiler, other executables libraries and include
3606 files into the appropriate directories.
3608 \begin_inset Quotes sld
3611 Install and Search PATHS
3612 \begin_inset Quotes srd
3617 On most systems you will need super-user privileges to do this.
3623 SDCC is not just a compiler, but a collection of tools by various developers.
3624 These include linkers, assemblers, simulators and other components.
3625 Here is a summary of some of the components.
3626 Note that the included simulator and assembler have separate documentation
3627 which you can find in the source package in their respective directories.
3628 As SDCC grows to include support for other processors, other packages from
3629 various developers are included and may have their own sets of documentation.
3633 You might want to look at the files which are installed in <installdir>.
3634 At the time of this writing, we find the following programs for gcc-builds:
3638 In <installdir>/bin:
3641 sdcc - The compiler.
3644 sdcpp - The C preprocessor.
3647 asx8051 - The assembler for 8051 type processors.
3654 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3657 aslink -The linker for 8051 type processors.
3664 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3667 s51 - The ucSim 8051 simulator.
3670 sdcdb - The source debugger.
3673 packihx - A tool to pack (compress) Intel hex files.
3676 In <installdir>/share/sdcc/include
3682 In <installdir>/share/sdcc/lib
3685 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3689 In <installdir>/share/sdcc/doc
3695 As development for other processors proceeds, this list will expand to include
3696 executables to support processors like AVR, PIC, etc.
3697 \layout Subsubsection
3702 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3703 the assembler and linkage editor.
3704 \layout Subsubsection
3707 \begin_inset LatexCommand \index{sdcpp}
3711 - The C-Preprocessor
3714 The preprocessor is a modified version of the GNU preprocessor.
3715 The C preprocessor is used to pull in #include sources, process #ifdef
3716 statements, #defines and so on.
3717 \layout Subsubsection
3719 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3723 This is retargettable assembler & linkage editor, it was developed by Alan
3725 John Hartman created the version for 8051, and I (Sandeep) have made some
3726 enhancements and bug fixes for it to work properly with SDCC.
3727 \layout Subsubsection
3730 \begin_inset LatexCommand \index{s51}
3737 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3738 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3743 The simulator is built as part of the build process.
3744 For more information visit Daniel's web site at:
3745 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3750 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3752 \layout Subsubsection
3755 \begin_inset LatexCommand \index{sdcdb}
3759 - Source Level Debugger
3762 Sdcdb is the companion source level debugger.
3763 The current version of the debugger uses Daniel's Simulator S51
3764 \begin_inset LatexCommand \index{s51}
3768 , but can be easily changed to use other simulators.
3775 \layout Subsubsection
3777 Single Source File Projects
3780 For single source file 8051 projects the process is very simple.
3781 Compile your programs with the following command
3784 "sdcc sourcefile.c".
3788 This will compile, assemble and link your source file.
3789 Output files are as follows
3793 \begin_inset LatexCommand \index{.asm}
3798 \begin_inset LatexCommand \index{Assembler source}
3802 file created by the compiler
3806 \begin_inset LatexCommand \index{.lst}
3811 \begin_inset LatexCommand \index{Assembler listing}
3815 file created by the Assembler
3819 \begin_inset LatexCommand \index{.rst}
3824 \begin_inset LatexCommand \index{Assembler listing}
3828 file updated with linkedit information, created by linkage editor
3832 \begin_inset LatexCommand \index{.sym}
3837 \begin_inset LatexCommand \index{Symbol listing}
3841 for the sourcefile, created by the assembler
3845 \begin_inset LatexCommand \index{.rel}
3850 \begin_inset LatexCommand \index{Object file}
3854 created by the assembler, input to Linkage editor
3858 \begin_inset LatexCommand \index{.map}
3863 \begin_inset LatexCommand \index{Memory map}
3867 for the load module, created by the Linker
3871 \begin_inset LatexCommand \index{.mem}
3875 - A file with a summary of the memory usage
3879 \begin_inset LatexCommand \index{.ihx}
3883 - The load module in Intel hex format
3884 \begin_inset LatexCommand \index{Intel hex format}
3888 (you can select the Motorola S19 format
3889 \begin_inset LatexCommand \index{Motorola S19 format}
3904 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3909 If you need another format you might want to use
3916 \begin_inset LatexCommand \index{objdump}
3927 \begin_inset LatexCommand \index{srecord}
3935 \begin_inset LatexCommand \index{.adb}
3939 - An intermediate file containing debug information needed to create the
3951 \begin_inset LatexCommand \index{-\/-debug}
3959 \begin_inset LatexCommand \index{.cdb}
3963 - An optional file (with -
3973 -debug) containing debug information
3978 \begin_inset LatexCommand \index{. (no extension)}
3983 \begin_inset LatexCommand \index{AOMF51}
3987 file containing debug information (with -
3998 This format is commonly used by third party tools (debuggers
3999 \begin_inset LatexCommand \index{Debugger}
4003 , simulators, emulators)
4007 \begin_inset LatexCommand \index{.dump*}
4011 - Dump file to debug the compiler it self (with -
4021 -dumpall) (see section
4022 \begin_inset Quotes sld
4025 Anatomy of the compiler
4026 \begin_inset Quotes srd
4030 \layout Subsubsection
4032 Projects with Multiple Source Files
4035 SDCC can compile only ONE file at a time.
4036 Let us for example assume that you have a project containing the following
4041 foo1.c (contains some functions)
4043 foo2.c (contains some more functions)
4045 foomain.c (contains more functions and the function main)
4053 The first two files will need to be compiled separately with the commands:
4085 Then compile the source file containing the
4090 \begin_inset LatexCommand \index{Linker}
4094 the files together with the following command:
4102 foomain.c\SpecialChar ~
4103 foo1.rel\SpecialChar ~
4108 \begin_inset LatexCommand \index{.rel}
4120 can be separately compiled as well:
4131 sdcc foomain.rel foo1.rel foo2.rel
4138 The file containing the
4153 file specified in the command line, since the linkage editor processes
4154 file in the order they are presented to it.
4155 The linker is invoked from sdcc using a script file with extension .lnk
4156 \begin_inset LatexCommand \index{.lnk}
4161 You can view this file to troubleshoot linking problems such as those arising
4162 from missing libraries.
4163 \layout Subsubsection
4165 Projects with Additional Libraries
4166 \begin_inset LatexCommand \index{Libraries}
4173 Some reusable routines may be compiled into a library, see the documentation
4174 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4178 \begin_inset LatexCommand \index{.lib}
4185 Libraries created in this manner can be included in the command line.
4186 Make sure you include the -L <library-path> option to tell the linker where
4187 to look for these files if they are not in the current directory.
4188 Here is an example, assuming you have the source file
4200 (if that is not the same as your current project):
4207 sdcc foomain.c foolib.lib -L mylib
4218 must be an absolute path name.
4222 The most efficient way to use libraries is to keep separate modules in separate
4224 The lib file now should name all the modules.rel
4225 \begin_inset LatexCommand \index{rel}
4230 For an example see the standard library file
4234 in the directory <installdir>/share/lib/small.
4237 Command Line Options
4238 \begin_inset LatexCommand \index{Command Line Options}
4243 \layout Subsubsection
4245 Processor Selection Options
4246 \begin_inset LatexCommand \index{Options processor selection}
4251 \begin_inset LatexCommand \index{Processor selection options}
4257 \labelwidthstring 00.00.0000
4262 \begin_inset LatexCommand \index{-mmcs51}
4268 Generate code for the Intel MCS51
4269 \begin_inset LatexCommand \index{MCS51}
4273 family of processors.
4274 This is the default processor target.
4276 \labelwidthstring 00.00.0000
4281 \begin_inset LatexCommand \index{-mds390}
4287 Generate code for the Dallas DS80C390
4288 \begin_inset LatexCommand \index{DS80C390}
4294 \labelwidthstring 00.00.0000
4299 \begin_inset LatexCommand \index{-mds400}
4305 Generate code for the Dallas DS80C400
4306 \begin_inset LatexCommand \index{DS80C400}
4312 \labelwidthstring 00.00.0000
4317 \begin_inset LatexCommand \index{-mz80}
4323 Generate code for the Zilog Z80
4324 \begin_inset LatexCommand \index{Z80}
4328 family of processors.
4330 \labelwidthstring 00.00.0000
4335 \begin_inset LatexCommand \index{-mgbz80}
4341 Generate code for the GameBoy Z80
4342 \begin_inset LatexCommand \index{GameBoy Z80}
4348 \labelwidthstring 00.00.0000
4353 \begin_inset LatexCommand \index{-mavr}
4359 Generate code for the Atmel AVR
4360 \begin_inset LatexCommand \index{AVR}
4364 processor (In development, not complete).
4365 AVR users should probably have a look at avr-gcc
4366 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4373 I think it is fair to direct users there for now.
4374 Open source is also about avoiding unnecessary work .
4375 But I didn't find the 'official' link.
4377 \labelwidthstring 00.00.0000
4382 \begin_inset LatexCommand \index{-mpic14}
4388 Generate code for the Microchip PIC 14
4389 \begin_inset LatexCommand \index{PIC14}
4393 -bit processors (p16f84 and variants).
4396 p16f627 p16f628 p16f84 p16f873 p16f877?
4398 \labelwidthstring 00.00.0000
4403 \begin_inset LatexCommand \index{-mpic16}
4409 Generate code for the Microchip PIC 16
4410 \begin_inset LatexCommand \index{PIC16}
4414 -bit processors (p18f452 and variants).
4416 \labelwidthstring 00.00.0000
4422 Generate code for the Toshiba TLCS-900H
4423 \begin_inset LatexCommand \index{TLCS-900H}
4427 processor (In development, not complete).
4429 \labelwidthstring 00.00.0000
4434 \begin_inset LatexCommand \index{-mxa51}
4440 Generate code for the Phillips XA51
4441 \begin_inset LatexCommand \index{XA51}
4445 processor (In development, not complete).
4446 \layout Subsubsection
4448 Preprocessor Options
4449 \begin_inset LatexCommand \index{Options preprocessor}
4454 \begin_inset LatexCommand \index{Preprocessor options}
4460 \labelwidthstring 00.00.0000
4465 \begin_inset LatexCommand \index{-I<path>}
4471 The additional location where the pre processor will look for <..h> or
4472 \begin_inset Quotes eld
4476 \begin_inset Quotes erd
4481 \labelwidthstring 00.00.0000
4486 \begin_inset LatexCommand \index{-D<macro[=value]>}
4492 Command line definition of macros.
4493 Passed to the preprocessor.
4495 \labelwidthstring 00.00.0000
4500 \begin_inset LatexCommand \index{-M}
4506 Tell the preprocessor to output a rule suitable for make describing the
4507 dependencies of each object file.
4508 For each source file, the preprocessor outputs one make-rule whose target
4509 is the object file name for that source file and whose dependencies are
4510 all the files `#include'd in it.
4511 This rule may be a single line or may be continued with `
4513 '-newline if it is long.
4514 The list of rules is printed on standard output instead of the preprocessed
4517 \begin_inset LatexCommand \index{-E}
4523 \labelwidthstring 00.00.0000
4528 \begin_inset LatexCommand \index{-C}
4534 Tell the preprocessor not to discard comments.
4535 Used with the `-E' option.
4537 \labelwidthstring 00.00.0000
4542 \begin_inset LatexCommand \index{-MM}
4553 Like `-M' but the output mentions only the user header files included with
4555 \begin_inset Quotes eld
4559 System header files included with `#include <file>' are omitted.
4561 \labelwidthstring 00.00.0000
4566 \begin_inset LatexCommand \index{-Aquestion(answer)}
4572 Assert the answer answer for question, in case it is tested with a preprocessor
4573 conditional such as `#if #question(answer)'.
4574 `-A-' disables the standard assertions that normally describe the target
4577 \labelwidthstring 00.00.0000
4582 \begin_inset LatexCommand \index{-Umacro}
4588 Undefine macro macro.
4589 `-U' options are evaluated after all `-D' options, but before any `-include'
4590 and `-imacros' options.
4592 \labelwidthstring 00.00.0000
4597 \begin_inset LatexCommand \index{-dM}
4603 Tell the preprocessor to output only a list of the macro definitions that
4604 are in effect at the end of preprocessing.
4605 Used with the `-E' option.
4607 \labelwidthstring 00.00.0000
4612 \begin_inset LatexCommand \index{-dD}
4618 Tell the preprocessor to pass all macro definitions into the output, in
4619 their proper sequence in the rest of the output.
4621 \labelwidthstring 00.00.0000
4626 \begin_inset LatexCommand \index{-dN}
4637 Like `-dD' except that the macro arguments and contents are omitted.
4638 Only `#define name' is included in the output.
4639 \layout Subsubsection
4642 \begin_inset LatexCommand \index{Options linker}
4647 \begin_inset LatexCommand \index{Linker options}
4653 \labelwidthstring 00.00.0000
4673 \begin_inset LatexCommand \index{-\/-lib-path}
4678 \begin_inset LatexCommand \index{-L -\/-lib-path}
4687 <absolute path to additional libraries> This option is passed to the linkage
4688 editor's additional libraries
4689 \begin_inset LatexCommand \index{Libraries}
4694 The path name must be absolute.
4695 Additional library files may be specified in the command line.
4696 See section Compiling programs for more details.
4698 \labelwidthstring 00.00.0000
4715 \begin_inset LatexCommand \index{-\/-xram-loc}
4719 <Value> The start location of the external ram
4720 \begin_inset LatexCommand \index{xdata}
4724 , default value is 0.
4725 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4735 -xram-loc 0x8000 or -
4747 \labelwidthstring 00.00.0000
4764 \begin_inset LatexCommand \index{-\/-code-loc}
4768 <Value> The start location of the code
4769 \begin_inset LatexCommand \index{code}
4773 segment, default value 0.
4774 Note when this option is used the interrupt vector table is also relocated
4775 to the given address.
4776 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4786 -code-loc 0x8000 or -
4798 \labelwidthstring 00.00.0000
4815 \begin_inset LatexCommand \index{-\/-stack-loc}
4819 <Value> By default the stack
4820 \begin_inset LatexCommand \index{stack}
4824 is placed after the data segment.
4825 Using this option the stack can be placed anywhere in the internal memory
4827 The value entered can be in Hexadecimal or Decimal format, e.g.
4838 -stack-loc 0x20 or -
4849 Since the sp register is incremented before a push or call, the initial
4850 sp will be set to one byte prior the provided value.
4851 The provided value should not overlap any other memory areas such as used
4852 register banks or the data segment and with enough space for the current
4855 \labelwidthstring 00.00.0000
4872 \begin_inset LatexCommand \index{-\/-data-loc}
4876 <Value> The start location of the internal ram data
4877 \begin_inset LatexCommand \index{data}
4882 The value entered can be in Hexadecimal or Decimal format, eg.
4904 (By default, the start location of the internal ram data segment is set
4905 as low as possible in memory, taking into account the used register banks
4906 and the bit segment at address 0x20.
4907 For example if register banks 0 and 1 are used without bit variables, the
4908 data segment will be set, if -
4918 -data-loc is not used, to location 0x10.)
4920 \labelwidthstring 00.00.0000
4937 \begin_inset LatexCommand \index{-\/-idata-loc}
4941 <Value> The start location of the indirectly addressable internal ram
4942 \begin_inset LatexCommand \index{idata}
4946 , default value is 0x80.
4947 The value entered can be in Hexadecimal or Decimal format, eg.
4958 -idata-loc 0x88 or -
4970 \labelwidthstring 00.00.0000
4985 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4994 The linker output (final object code) is in Intel Hex format.
4995 \begin_inset LatexCommand \index{Intel hex format}
4999 (This is the default option).
5001 \labelwidthstring 00.00.0000
5016 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5025 The linker output (final object code) is in Motorola S19 format
5026 \begin_inset LatexCommand \index{Motorola S19 format}
5031 \layout Subsubsection
5034 \begin_inset LatexCommand \index{Options MCS51}
5039 \begin_inset LatexCommand \index{MCS51 options}
5045 \labelwidthstring 00.00.0000
5060 \begin_inset LatexCommand \index{-\/-model-small}
5071 Generate code for Small Model programs see section Memory Models for more
5073 This is the default model.
5075 \labelwidthstring 00.00.0000
5090 \begin_inset LatexCommand \index{-\/-model-large}
5096 Generate code for Large model programs see section Memory Models for more
5098 If this option is used all source files in the project should be compiled
5101 \labelwidthstring 00.00.0000
5116 \begin_inset LatexCommand \index{-\/-xstack}
5122 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5123 variables and passing parameters.
5124 See section on external stack for more details.
5126 \labelwidthstring 00.00.0000
5143 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5147 Causes the linker to check if the internal ram usage is within limits of
5150 \labelwidthstring 00.00.0000
5167 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5171 Causes the linker to check if the external ram usage is within limits of
5174 \labelwidthstring 00.00.0000
5191 \begin_inset LatexCommand \index{-\/-data-loc}
5195 Causes the linker to check if the code memory usage is within limits of
5197 \layout Subsubsection
5200 \begin_inset LatexCommand \index{Options DS390}
5205 \begin_inset LatexCommand \index{DS390 options}
5211 \labelwidthstring 00.00.0000
5228 \begin_inset LatexCommand \index{-\/-model-flat24}
5238 Generate 24-bit flat mode code.
5239 This is the one and only that the ds390 code generator supports right now
5240 and is default when using
5245 See section Memory Models for more details.
5247 \labelwidthstring 00.00.0000
5264 \begin_inset LatexCommand \index{-\/-stack-10bit}
5268 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5269 This is the one and only that the ds390 code generator supports right now
5270 and is default when using
5275 In this mode, the stack is located in the lower 1K of the internal RAM,
5276 which is mapped to 0x400000.
5277 Note that the support is incomplete, since it still uses a single byte
5278 as the stack pointer.
5279 This means that only the lower 256 bytes of the potential 1K stack space
5280 will actually be used.
5281 However, this does allow you to reclaim the precious 256 bytes of low RAM
5282 for use for the DATA and IDATA segments.
5283 The compiler will not generate any code to put the processor into 10 bit
5285 It is important to ensure that the processor is in this mode before calling
5286 any re-entrant functions compiled with this option.
5287 In principle, this should work with the
5300 \begin_inset LatexCommand \index{-\/-stack-auto}
5306 option, but that has not been tested.
5307 It is incompatible with the
5320 \begin_inset LatexCommand \index{-\/-xstack}
5327 It also only makes sense if the processor is in 24 bit contiguous addressing
5340 -model-flat24 option
5343 \layout Subsubsection
5346 \begin_inset LatexCommand \index{Options Z80}
5351 \begin_inset LatexCommand \index{Z80 options}
5357 \labelwidthstring 00.00.0000
5374 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5384 Force a called function to always save BC.
5386 \labelwidthstring 00.00.0000
5403 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5407 When linking, skip the standard crt0.o object file.
5408 You must provide your own crt0.o for your system when linking.
5410 \layout Subsubsection
5412 Optimization Options
5413 \begin_inset LatexCommand \index{Options optimization}
5418 \begin_inset LatexCommand \index{Optimization options}
5424 \labelwidthstring 00.00.0000
5439 \begin_inset LatexCommand \index{-\/-nogcse}
5445 Will not do global subexpression elimination, this option may be used when
5446 the compiler creates undesirably large stack/data spaces to store compiler
5448 A warning message will be generated when this happens and the compiler
5449 will indicate the number of extra bytes it allocated.
5450 It recommended that this option NOT be used, #pragma\SpecialChar ~
5452 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5456 can be used to turn off global subexpression elimination
5457 \begin_inset LatexCommand \index{Subexpression elimination}
5461 for a given function only.
5463 \labelwidthstring 00.00.0000
5478 \begin_inset LatexCommand \index{-\/-noinvariant}
5484 Will not do loop invariant optimizations, this may be turned off for reasons
5485 explained for the previous option.
5486 For more details of loop optimizations performed see section Loop Invariants.It
5487 recommended that this option NOT be used, #pragma\SpecialChar ~
5489 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5493 can be used to turn off invariant optimizations for a given function only.
5495 \labelwidthstring 00.00.0000
5510 \begin_inset LatexCommand \index{-\/-noinduction}
5516 Will not do loop induction optimizations, see section strength reduction
5517 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5520 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5524 can be used to turn off induction optimizations for a given function only.
5526 \labelwidthstring 00.00.0000
5541 \begin_inset LatexCommand \index{-\/-nojtbound}
5552 Will not generate boundary condition check when switch statements
5553 \begin_inset LatexCommand \index{switch statement}
5557 are implemented using jump-tables.
5558 See section Switch Statements for more details.
5559 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5561 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5565 can be used to turn off boundary checking for jump tables for a given function
5568 \labelwidthstring 00.00.0000
5583 \begin_inset LatexCommand \index{-\/-noloopreverse}
5592 Will not do loop reversal
5593 \begin_inset LatexCommand \index{Loop reversing}
5599 \labelwidthstring 00.00.0000
5616 \begin_inset LatexCommand \index{-\/-nolabelopt }
5620 Will not optimize labels (makes the dumpfiles more readable).
5622 \labelwidthstring 00.00.0000
5637 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5643 Will not memcpy initialized data from code space into xdata space.
5644 This saves a few bytes in code space if you don't have initialized data.
5645 \layout Subsubsection
5648 \begin_inset LatexCommand \index{Options other}
5654 \labelwidthstring 00.00.0000
5670 \begin_inset LatexCommand \index{-\/-compile-only}
5675 \begin_inset LatexCommand \index{-c -\/-compile-only}
5681 will compile and assemble the source, but will not call the linkage editor.
5683 \labelwidthstring 00.00.0000
5702 \begin_inset LatexCommand \index{-\/-c1mode}
5708 reads the preprocessed source from standard input and compiles it.
5709 The file name for the assembler output must be specified using the -o option.
5711 \labelwidthstring 00.00.0000
5716 \begin_inset LatexCommand \index{-E}
5722 Run only the C preprocessor.
5723 Preprocess all the C source files specified and output the results to standard
5726 \labelwidthstring 00.00.0000
5732 \begin_inset LatexCommand \index{-o <path/file>}
5738 The output path resp.
5739 file where everything will be placed.
5740 If the parameter is a path, it must have a trailing slash (or backslash
5741 for the Windows binaries) to be recognized as a path.
5744 \labelwidthstring 00.00.0000
5759 \begin_inset LatexCommand \index{-\/-stack-auto}
5770 All functions in the source file will be compiled as
5775 \begin_inset LatexCommand \index{reentrant}
5780 the parameters and local variables will be allocated on the stack
5781 \begin_inset LatexCommand \index{stack}
5786 see section Parameters and Local Variables for more details.
5787 If this option is used all source files in the project should be compiled
5791 \labelwidthstring 00.00.0000
5806 \begin_inset LatexCommand \index{-\/-callee-saves}
5810 function1[,function2][,function3]....
5813 The compiler by default uses a caller saves convention for register saving
5814 across function calls, however this can cause unnecessary register pushing
5815 & popping when calling small functions from larger functions.
5816 This option can be used to switch the register saving convention for the
5817 function names specified.
5818 The compiler will not save registers when calling these functions, no extra
5819 code will be generated at the entry & exit (function prologue
5822 \begin_inset LatexCommand \index{function prologue}
5831 \begin_inset LatexCommand \index{function epilogue}
5837 ) for these functions to save & restore the registers used by these functions,
5838 this can SUBSTANTIALLY reduce code & improve run time performance of the
5840 In the future the compiler (with inter procedural analysis) will be able
5841 to determine the appropriate scheme to use for each function call.
5842 DO NOT use this option for built-in functions such as _mulint..., if this
5843 option is used for a library function the appropriate library function
5844 needs to be recompiled with the same option.
5845 If the project consists of multiple source files then all the source file
5846 should be compiled with the same -
5856 -callee-saves option string.
5857 Also see #pragma\SpecialChar ~
5859 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5865 \labelwidthstring 00.00.0000
5880 \begin_inset LatexCommand \index{-\/-debug}
5889 When this option is used the compiler will generate debug information, that
5890 can be used with the SDCDB.
5891 The debug information is collected in a file with .cdb extension.
5892 For more information see documentation for SDCDB.
5894 \labelwidthstring 00.00.0000
5899 \begin_inset LatexCommand \index{-S}
5910 Stop after the stage of compilation proper; do not assemble.
5911 The output is an assembler code file for the input file specified.
5913 \labelwidthstring 00.00.0000
5917 -Wa_asmOption[,asmOption]
5920 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5925 Pass the asmOption to the assembler.
5927 \labelwidthstring 00.00.0000
5931 -Wl_linkOption[,linkOption]
5934 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5939 Pass the linkOption to the linker.
5941 \labelwidthstring 00.00.0000
5956 \begin_inset LatexCommand \index{-\/-int-long-reent}
5962 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5963 Note by default these libraries are compiled as non-reentrant.
5964 See section Installation for more details.
5966 \labelwidthstring 00.00.0000
5981 \begin_inset LatexCommand \index{-\/-cyclomatic}
5990 This option will cause the compiler to generate an information message for
5991 each function in the source file.
5992 The message contains some
5996 information about the function.
5997 The number of edges and nodes the compiler detected in the control flow
5998 graph of the function, and most importantly the
6000 cyclomatic complexity
6001 \begin_inset LatexCommand \index{Cyclomatic complexity}
6007 see section on Cyclomatic Complexity for more details.
6009 \labelwidthstring 00.00.0000
6024 \begin_inset LatexCommand \index{-\/-float-reent}
6033 Floating point library is compiled as reentrant
6034 \begin_inset LatexCommand \index{reentrant}
6039 See section Installation for more details.
6041 \labelwidthstring 00.00.0000
6056 \begin_inset LatexCommand \index{-\/-nooverlay}
6062 The compiler will not overlay parameters and local variables of any function,
6063 see section Parameters and local variables for more details.
6065 \labelwidthstring 00.00.0000
6080 \begin_inset LatexCommand \index{-\/-main-return}
6086 This option can be used when the code generated is called by a monitor
6088 The compiler will generate a 'ret' upon return from the 'main'
6089 \begin_inset LatexCommand \index{main return}
6094 The default option is to lock up i.e.
6101 \labelwidthstring 00.00.0000
6118 \begin_inset LatexCommand \index{-\/-peep-file}
6122 <filename> This option can be used to use additional rules to be used by
6123 the peep hole optimizer.
6124 See section Peep Hole optimizations for details on how to write these rules.
6126 \labelwidthstring 00.00.0000
6141 \begin_inset LatexCommand \index{-\/-no-peep}
6147 Disable peep-hole optimization.
6149 \labelwidthstring 00.00.0000
6164 \begin_inset LatexCommand \index{-\/-peep-asm}
6170 Pass the inline assembler code through the peep hole optimizer.
6171 This can cause unexpected changes to inline assembler code, please go through
6172 the peephole optimizer
6173 \begin_inset LatexCommand \index{Peephole optimizer}
6177 rules defined in the source file tree '<target>/peeph.def' before using
6180 \labelwidthstring 00.00.0000
6195 \begin_inset LatexCommand \index{-\/-nostdincl}
6201 This will prevent the compiler from passing on the default include path
6202 to the preprocessor.
6204 \labelwidthstring 00.00.0000
6219 \begin_inset LatexCommand \index{-\/-nostdlib}
6225 This will prevent the compiler from passing on the default library
6226 \begin_inset LatexCommand \index{Libraries}
6232 \labelwidthstring 00.00.0000
6247 \begin_inset LatexCommand \index{-\/-verbose}
6253 Shows the various actions the compiler is performing.
6255 \labelwidthstring 00.00.0000
6260 \begin_inset LatexCommand \index{-V}
6266 Shows the actual commands the compiler is executing.
6268 \labelwidthstring 00.00.0000
6283 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6289 Hides your ugly and inefficient c-code from the asm file, so you can always
6290 blame the compiler :).
6292 \labelwidthstring 00.00.0000
6307 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6313 Include i-codes in the asm file.
6314 Sounds like noise but is most helpful for debugging the compiler itself.
6316 \labelwidthstring 00.00.0000
6331 \begin_inset LatexCommand \index{-\/-less-pedantic}
6337 Disable some of the more pedantic warnings (jwk burps: please be more specific
6340 \labelwidthstring 00.00.0000
6355 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6361 Display the directories in the compiler's search path
6363 \labelwidthstring 00.00.0000
6378 \begin_inset LatexCommand \index{-\/-vc}
6384 Display errors and warnings using MSVC style, so you can use SDCC with
6387 \labelwidthstring 00.00.0000
6402 \begin_inset LatexCommand \index{-\/-use-stdout}
6408 Send errors and warnings to stdout instead of stderr.
6409 \layout Subsubsection
6411 Intermediate Dump Options
6412 \begin_inset LatexCommand \index{Options intermediate dump}
6417 \begin_inset LatexCommand \index{Intermediate dump options}
6424 The following options are provided for the purpose of retargetting and debugging
6426 These provided a means to dump the intermediate code (iCode
6427 \begin_inset LatexCommand \index{iCode}
6431 ) generated by the compiler in human readable form at various stages of
6432 the compilation process.
6435 \labelwidthstring 00.00.0000
6450 \begin_inset LatexCommand \index{-\/-dumpraw}
6456 This option will cause the compiler to dump the intermediate code into
6459 <source filename>.dumpraw
6461 just after the intermediate code has been generated for a function, i.e.
6462 before any optimizations are done.
6464 \begin_inset LatexCommand \index{Basic blocks}
6468 at this stage ordered in the depth first number, so they may not be in
6469 sequence of execution.
6471 \labelwidthstring 00.00.0000
6486 \begin_inset LatexCommand \index{-\/-dumpgcse}
6492 Will create a dump of iCode's, after global subexpression elimination
6493 \begin_inset LatexCommand \index{Global subexpression elimination}
6499 <source filename>.dumpgcse.
6501 \labelwidthstring 00.00.0000
6516 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6522 Will create a dump of iCode's, after deadcode elimination
6523 \begin_inset LatexCommand \index{Dead-code elimination}
6529 <source filename>.dumpdeadcode.
6531 \labelwidthstring 00.00.0000
6546 \begin_inset LatexCommand \index{-\/-dumploop}
6555 Will create a dump of iCode's, after loop optimizations
6556 \begin_inset LatexCommand \index{Loop optimization}
6562 <source filename>.dumploop.
6564 \labelwidthstring 00.00.0000
6579 \begin_inset LatexCommand \index{-\/-dumprange}
6588 Will create a dump of iCode's, after live range analysis
6589 \begin_inset LatexCommand \index{Live range analysis}
6595 <source filename>.dumprange.
6597 \labelwidthstring 00.00.0000
6612 \begin_inset LatexCommand \index{-\/-dumlrange}
6618 Will dump the life ranges
6619 \begin_inset LatexCommand \index{Live range analysis}
6625 \labelwidthstring 00.00.0000
6640 \begin_inset LatexCommand \index{-\/-dumpregassign}
6649 Will create a dump of iCode's, after register assignment
6650 \begin_inset LatexCommand \index{Register assignment}
6656 <source filename>.dumprassgn.
6658 \labelwidthstring 00.00.0000
6673 \begin_inset LatexCommand \index{-\/-dumplrange}
6679 Will create a dump of the live ranges of iTemp's
6681 \labelwidthstring 00.00.0000
6696 \begin_inset LatexCommand \index{-\/-dumpall}
6707 Will cause all the above mentioned dumps to be created.
6708 \layout Subsubsection
6710 Redirecting output on Windows Shells
6713 By default SDCC writes it's error messages to
6714 \begin_inset Quotes sld
6718 \begin_inset Quotes srd
6722 To force all messages to
6723 \begin_inset Quotes sld
6727 \begin_inset Quotes srd
6751 \begin_inset LatexCommand \index{-\/-use-stdout}
6756 Aditionaly, if you happen to have visual studio installed in your windows
6757 machine, you can use it to compile your sources using a custom build and
6773 \begin_inset LatexCommand \index{-\/-vc}
6778 Something like this should work:
6822 -model-large -c $(InputPath)
6825 Environment variables
6826 \begin_inset LatexCommand \index{Environment variables}
6833 SDCC recognizes the following environment variables:
6835 \labelwidthstring 00.00.0000
6840 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6846 SDCC installs a signal handler
6847 \begin_inset LatexCommand \index{signal handler}
6851 to be able to delete temporary files after an user break (^C) or an exception.
6852 If this environment variable is set, SDCC won't install the signal handler
6853 in order to be able to debug SDCC.
6855 \labelwidthstring 00.00.0000
6862 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
6868 Path, where temporary files will be created.
6869 The order of the variables is the search order.
6870 In a standard *nix environment these variables are not set, and there's
6871 no need to set them.
6872 On Windows it's recommended to set one of them.
6874 \labelwidthstring 00.00.0000
6879 \begin_inset LatexCommand \index{SDCC\_HOME}
6886 \begin_inset Quotes sld
6889 2.3 Install and search paths
6890 \begin_inset Quotes srd
6895 \labelwidthstring 00.00.0000
6900 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6907 \begin_inset Quotes sld
6910 2.3 Install and search paths
6911 \begin_inset Quotes srd
6916 \labelwidthstring 00.00.0000
6921 \begin_inset LatexCommand \index{SDCC\_LIB}
6928 \begin_inset Quotes sld
6931 2.3 Install and search paths
6932 \begin_inset Quotes srd
6938 There are some more environment variables recognized by SDCC, but these
6939 are solely used for debugging purposes.
6940 They can change or disappear very quickly, and will never be documented.
6943 MCS51/DS390 Storage Class
6944 \begin_inset LatexCommand \index{Storage class}
6951 In addition to the ANSI storage classes SDCC allows the following MCS51
6952 specific storage classes.
6953 \layout Subsubsection
6956 \begin_inset LatexCommand \index{data}
6967 storage class for Small Memory model.
6968 Variables declared with this storage class will be allocated in the directly
6969 addressable portion of the internal RAM of a 8051, e.g.:
6974 data unsigned char test_data;
6977 Writing 0x01 to this variable generates the assembly code:
6982 75*00 01\SpecialChar ~
6988 \layout Subsubsection
6991 \begin_inset LatexCommand \index{xdata}
6998 Variables declared with this storage class will be placed in the external
7004 storage class for Large Memory model, e.g.:
7009 xdata unsigned char test_xdata;
7012 Writing 0x01 to this variable generates the assembly code:
7017 90s00r00\SpecialChar ~
7046 \layout Subsubsection
7049 \begin_inset LatexCommand \index{idata}
7056 Variables declared with this storage class will be allocated into the indirectly
7057 addressable portion of the internal ram of a 8051, e.g.:
7062 idata unsigned char test_idata;
7065 Writing 0x01 to this variable generates the assembly code:
7092 \layout Subsubsection
7095 \begin_inset LatexCommand \index{pdata}
7102 Paged xdata access is currently not as straightforward as using the other
7103 addressing modes of a 8051.
7104 The following example writes 0x01 to the address pointed to.
7105 Please note, pdata access physically accesses xdata memory.
7106 The high byte of the address is determined by port P2 (or in case of some
7107 8051 variants by a separate Special Function Register).
7112 pdata unsigned char *test_pdata_ptr;
7124 test_pdata_ptr = (pdata *)0xfe;
7130 *test_pdata_ptr = 1;
7135 Generates the assembly code:
7140 75*01 FE\SpecialChar ~
7144 _test_pdata_ptr,#0xFE
7176 Be extremely carefull if you use pdata together with the -
7187 \begin_inset LatexCommand \index{-\/-xstack}
7192 \layout Subsubsection
7195 \begin_inset LatexCommand \index{code}
7202 'Variables' declared with this storage class will be placed in the code
7208 code unsigned char test_code;
7211 Read access to this variable generates the assembly code:
7216 90s00r6F\SpecialChar ~
7219 mov dptr,#_test_code
7242 \layout Subsubsection
7245 \begin_inset LatexCommand \index{bit}
7252 This is a data-type and a storage class specifier.
7253 When a variable is declared as a bit, it is allocated into the bit addressable
7254 memory of 8051, e.g.:
7262 Writing 1 to this variable generates the assembly code:
7276 \layout Subsubsection
7279 \begin_inset LatexCommand \index{sfr}
7284 \begin_inset LatexCommand \index{sbit}
7291 Like the bit keyword,
7295 signifies both a data-type and storage class, they are used to describe
7296 the special function registers and special bit variables of a 8051, eg:
7302 \begin_inset LatexCommand \index{at}
7306 0x80 P0;\SpecialChar ~
7307 /* special function register P0 at location 0x80 */
7309 sbit at 0xd7 CY; /* CY (Carry Flag
7310 \begin_inset LatexCommand \index{Flags}
7315 \begin_inset LatexCommand \index{Carry flag}
7320 \layout Subsubsection
7323 \begin_inset LatexCommand \index{Pointers}
7327 to MCS51/DS390 specific memory spaces
7330 SDCC allows (via language extensions) pointers to explicitly point to any
7331 of the memory spaces
7332 \begin_inset LatexCommand \index{Memory model}
7337 In addition to the explicit pointers, the compiler uses (by default) generic
7338 pointers which can be used to point to any of the memory spaces.
7342 Pointer declaration examples:
7347 /* pointer physically in internal ram pointing to object in external ram
7350 xdata unsigned char * data p;
7354 /* pointer physically in external ram pointing to object in internal ram
7357 data unsigned char * xdata p;
7361 /* pointer physically in code rom pointing to data in xdata space */
7363 xdata unsigned char * code p;
7367 /* pointer physically in code space pointing to data in code space */
7369 code unsigned char * code p;
7373 /* the following is a generic pointer physically located in xdata space
7379 Well you get the idea.
7384 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7397 The highest order byte of the
7401 pointers contains the data space information.
7402 Assembler support routines are called whenever data is stored or retrieved
7408 These are useful for developing reusable library
7409 \begin_inset LatexCommand \index{Libraries}
7414 Explicitly specifying the pointer type will generate the most efficient
7419 \begin_inset LatexCommand \index{Absolute addressing}
7426 Data items can be assigned an absolute address with the
7429 \begin_inset LatexCommand \index{at}
7435 keyword, in addition to a storage class, e.g.:
7441 \begin_inset LatexCommand \index{xdata}
7446 \begin_inset LatexCommand \index{at}
7450 0x7ffe unsigned int chksum;
7453 In the above example the variable chksum will located at 0x7ffe and 0x7fff
7454 of the external ram.
7455 The compiler does not actually reserve any space for variables declared
7456 in this way (they are implemented with an equate in the assembler).
7457 Thus it is left to the programmer to make sure there are no overlaps with
7458 other variables that are declared without the absolute address.
7459 The assembler listing file (.lst
7460 \begin_inset LatexCommand \index{.lst}
7464 ) and the linker output files (.rst
7465 \begin_inset LatexCommand \index{.rst}
7470 \begin_inset LatexCommand \index{.map}
7474 ) are good places to look for such overlaps.
7477 In case of memory mapped I/O devices the keyword
7481 should be used to tell the compiler that accesses might not be optimized
7488 \begin_inset LatexCommand \index{volatile}
7493 \begin_inset LatexCommand \index{xdata}
7498 \begin_inset LatexCommand \index{at}
7502 0x8000 unsigned char PORTA_8255;
7505 Absolute address can be specified for variables in all storage classes,
7512 \begin_inset LatexCommand \index{bit}
7517 \begin_inset LatexCommand \index{at}
7524 The above example will allocate the variable at offset 0x02 in the bit-addressab
7526 There is no real advantage to assigning absolute addresses to variables
7527 in this manner, unless you want strict control over all the variables allocated.
7528 One possible use would be to write hardware portable code.
7529 For example, if you have a routine that uses one or more of the microcontroller
7530 I/O pins, and such pins are different for two different hardwares, you
7531 can declare the I/O pins in your routine using:
7536 extern volatile bit SDI;
7538 extern volatile bit SCLK;
7540 extern volatile bit CPOL;
7544 void DS1306_put(unsigned char value)
7552 unsigned char mask=0x80;
7576 SDI=(value & mask)?1:0;
7617 Then, someplace in the code for the first hardware you would use
7622 bit at 0x80 SDI;\SpecialChar ~
7626 /* I/O port 0, bit 0 */
7628 bit at 0x81 SCLK;\SpecialChar ~
7631 /* I/O port 0, bit 1 */
7633 bit CPOL;\SpecialChar ~
7644 /* This is a variable, let the linker allocate this one */
7647 Similarly, for the second hardware you would use
7652 bit at 0x83 SDI;\SpecialChar ~
7656 /* I/O port 0, bit 3 */
7658 bit at 0x91 SCLK;\SpecialChar ~
7661 /* I/O port 1, bit 1 */
7663 bit CPOL;\SpecialChar ~
7674 /* This is a variable, let the linker allocate this one */
7677 and you can use the same hardware dependent routine without changes, as
7678 for example in a library.
7679 This is somehow similar to sbit, but only one absolute address has to be
7680 specified in the whole project.
7684 \begin_inset LatexCommand \index{Parameters}
7689 \begin_inset LatexCommand \index{Local variable}
7696 Automatic (local) variables and parameters to functions can either be placed
7697 on the stack or in data-space.
7698 The default action of the compiler is to place these variables in the internal
7699 RAM (for small model) or external RAM (for large model).
7700 This in fact makes them
7703 \begin_inset LatexCommand \index{static}
7709 so by default functions are non-reentrant
7710 \begin_inset LatexCommand \index{reentrant}
7718 They can be placed on the stack
7719 \begin_inset LatexCommand \index{stack}
7736 \begin_inset LatexCommand \index{-\/-stack-auto}
7742 option or by using the
7745 \begin_inset LatexCommand \index{reentrant}
7751 keyword in the function declaration, e.g.:
7756 unsigned char foo(char i) reentrant
7770 Since stack space on 8051 is limited, the
7788 option should be used sparingly.
7789 Note that the reentrant keyword just means that the parameters & local
7790 variables will be allocated to the stack, it
7794 mean that the function is register bank independent.
7798 Local variables can be assigned storage classes and absolute
7799 \begin_inset LatexCommand \index{Absolute addressing}
7816 xdata unsigned char i;
7828 data at 0x31 unsigned char j;
7840 In the above example the variable
7844 will be allocated in the external ram,
7848 in bit addressable space and
7867 or when a function is declared as
7871 this should only be done for static variables.
7874 Parameters however are not allowed any storage class, (storage classes for
7875 parameters will be ignored), their allocation is governed by the memory
7876 model in use, and the reentrancy options.
7880 \begin_inset LatexCommand \label{sub:Overlaying}
7885 \begin_inset LatexCommand \index{Overlaying}
7893 \begin_inset LatexCommand \index{reentrant}
7897 functions SDCC will try to reduce internal ram space usage by overlaying
7898 parameters and local variables of a function (if possible).
7899 Parameters and local variables of a function will be allocated to an overlayabl
7900 e segment if the function has
7902 no other function calls and the function is non-reentrant and the memory
7904 \begin_inset LatexCommand \index{Memory model}
7911 If an explicit storage class
7912 \begin_inset LatexCommand \index{Storage class}
7916 is specified for a local variable, it will NOT be overlayed.
7919 Note that the compiler (not the linkage editor) makes the decision for overlayin
7921 Functions that are called from an interrupt service routine should be preceded
7922 by a #pragma\SpecialChar ~
7924 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7928 if they are not reentrant.
7931 Also note that the compiler does not do any processing of inline
7932 \begin_inset LatexCommand \index{inline}
7936 assembler code, so the compiler might incorrectly assign local variables
7937 and parameters of a function into the overlay segment if the inline assembler
7938 code calls other c-functions that might use the overlay.
7939 In that case the #pragma\SpecialChar ~
7940 NOOVERLAY should be used.
7943 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7945 \begin_inset LatexCommand \index{Multiplication}
7950 \begin_inset LatexCommand \index{Division}
7954 will NOT be overlayed since these are implemented using external functions,
7963 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7969 void set_error(unsigned char errcd)
7985 void some_isr () interrupt
7986 \begin_inset LatexCommand \index{interrupt}
8016 In the above example the parameter
8024 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8026 not present, this could cause unpredictable runtime behavior when called
8028 The #pragma\SpecialChar ~
8029 NOOVERLAY ensures that the parameters and local variables for
8030 the function are NOT overlayed.
8033 Interrupt Service Routines
8036 SDCC allows interrupt service routines to be coded in C, with some extended
8042 void timer_isr (void) interrupt 1 using 1
8056 The optional number following the
8059 \begin_inset LatexCommand \index{interrupt}
8065 keyword is the interrupt number this routine will service.
8066 When present, the compiler will insert a call to this routine in the interrupt
8067 vector table for the interrupt number specified.
8072 keyword can be used to tell the compiler to use the specified register
8073 bank (8051 specific) when generating code for this function.
8074 Note that when some function is called from an interrupt service routine
8075 it should be preceded by a #pragma\SpecialChar ~
8077 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8081 if it is not reentrant.
8082 Furthermore nonreentrant functions should not be called from the main program
8083 while the interrupt service routine might be active.
8084 If the interrupt service routines changes variables which are accessed
8085 by other functions these variables should be declared
8090 \begin_inset LatexCommand \index{volatile}
8098 A special note here, int (16 bit) and long (32 bit) integer division
8099 \begin_inset LatexCommand \index{Division}
8104 \begin_inset LatexCommand \index{Multiplication}
8109 \begin_inset LatexCommand \index{Modulus}
8113 operations are implemented using external support routines developed in
8114 ANSI-C, if an interrupt service routine needs to do any of these operations
8115 then the support routines (as mentioned in a following section) will have
8116 to be recompiled using the
8129 \begin_inset LatexCommand \index{-\/-stack-auto}
8135 option and the source file will need to be compiled using the
8150 \begin_inset LatexCommand \index{-\/-int-long-rent}
8157 If you have multiple source files in your project, interrupt service routines
8158 can be present in any of them, but a prototype of the isr MUST be present
8159 or included in the file that contains the function
8166 Interrupt numbers and the corresponding address & descriptions for the Standard
8167 8051/8052 are listed below.
8168 SDCC will automatically adjust the interrupt vector table to the maximum
8169 interrupt number specified.
8175 \begin_inset Tabular
8176 <lyxtabular version="3" rows="7" columns="3">
8178 <column alignment="center" valignment="top" leftline="true" width="0in">
8179 <column alignment="left" valignment="top" leftline="true" width="0in">
8180 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
8181 <row topline="true" bottomline="true">
8182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8207 <row topline="true">
8208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8233 <row topline="true">
8234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8259 <row topline="true">
8260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8285 <row topline="true">
8286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8311 <row topline="true">
8312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8337 <row topline="true" bottomline="true">
8338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8372 If the interrupt service routine is defined without
8375 \begin_inset LatexCommand \index{using}
8381 a register bank or with register bank 0 (using 0), the compiler will save
8382 the registers used by itself on the stack upon entry and restore them at
8383 exit, however if such an interrupt service routine calls another function
8384 then the entire register bank will be saved on the stack.
8385 This scheme may be advantageous for small interrupt service routines which
8386 have low register usage.
8389 If the interrupt service routine is defined to be using a specific register
8394 are save and restored, if such an interrupt service routine calls another
8395 function (using another register bank) then the entire register bank of
8396 the called function will be saved on the stack.
8397 This scheme is recommended for larger interrupt service routines.
8400 Calling other functions from an interrupt service routine is not recommended,
8401 avoid it if possible.
8403 For some pitfalls see section
8404 \begin_inset LatexCommand \ref{sub:Overlaying}
8408 about Overlaying and section
8409 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8413 about Functions using private banks.
8423 <TODO: this isn't implemented at all!>
8429 A special keyword may be associated with a function declaring it as
8434 SDCC will generate code to disable all interrupts upon entry to a critical
8435 function and enable them back before returning.
8436 Note that nesting critical functions may cause unpredictable results.
8462 The critical attribute maybe used with other attributes like
8468 \begin_inset LatexCommand \label{sub:Naked-Functions}
8473 \begin_inset LatexCommand \index{Naked functions}
8480 A special keyword may be associated with a function declaring it as
8483 \begin_inset LatexCommand \index{\_naked}
8494 function modifier attribute prevents the compiler from generating prologue
8495 \begin_inset LatexCommand \index{function prologue}
8500 \begin_inset LatexCommand \index{function epilogue}
8504 code for that function.
8505 This means that the user is entirely responsible for such things as saving
8506 any registers that may need to be preserved, selecting the proper register
8507 bank, generating the
8511 instruction at the end, etc.
8512 Practically, this means that the contents of the function must be written
8513 in inline assembler.
8514 This is particularly useful for interrupt functions, which can have a large
8515 (and often unnecessary) prologue/epilogue.
8516 For example, compare the code generated by these two functions:
8522 \begin_inset LatexCommand \index{volatile}
8526 data unsigned char counter;
8530 void simpleInterrupt(void) interrupt
8531 \begin_inset LatexCommand \index{interrupt}
8549 void nakedInterrupt(void) interrupt 2 _naked
8558 \begin_inset LatexCommand \index{\_asm}
8587 ; MUST explicitly include ret or reti in _naked function.
8594 \begin_inset LatexCommand \index{\_endasm}
8603 For an 8051 target, the generated simpleInterrupt looks like:
8744 whereas nakedInterrupt looks like:
8768 ; MUST explicitly include ret or reti in _naked function.
8771 The #pragma directive EXCLUDE
8772 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
8776 also allows to reduce pushing & popping the registers.
8779 While there is nothing preventing you from writing C code inside a _naked
8780 function, there are many ways to shoot yourself in the foot doing this,
8781 and it is recommended that you stick to inline assembler.
8784 Functions using private banks
8785 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
8790 \begin_inset LatexCommand \index{bank}
8800 \begin_inset LatexCommand \index{using}
8806 attribute (which tells the compiler to use a register bank other than the
8807 default bank zero) should only be applied to
8810 \begin_inset LatexCommand \index{interrupt}
8816 functions (see note 1 below).
8817 This will in most circumstances make the generated ISR code more efficient
8818 since it will not have to save registers on the stack.
8825 attribute will have no effect on the generated code for a
8829 function (but may occasionally be useful anyway
8835 possible exception: if a function is called ONLY from 'interrupt' functions
8836 using a particular bank, it can be declared with the same 'using' attribute
8837 as the calling 'interrupt' functions.
8838 For instance, if you have several ISRs using bank one, and all of them
8839 call memcpy(), it might make sense to create a specialized version of memcpy()
8840 'using 1', since this would prevent the ISR from having to save bank zero
8841 to the stack on entry and switch to bank zero before calling the function
8848 (pending: I don't think this has been done yet)
8855 function using a non-zero bank will assume that it can trash that register
8856 bank, and will not save it.
8857 Since high-priority interrupts
8858 \begin_inset LatexCommand \index{interrupt priority}
8862 can interrupt low-priority ones on the 8051 and friends, this means that
8863 if a high-priority ISR
8867 a particular bank occurs while processing a low-priority ISR
8871 the same bank, terrible and bad things can happen.
8872 To prevent this, no single register bank should be
8876 by both a high priority and a low priority ISR.
8877 This is probably most easily done by having all high priority ISRs use
8878 one bank and all low priority ISRs use another.
8879 If you have an ISR which can change priority at runtime, you're on your
8880 own: I suggest using the default bank zero and taking the small performance
8884 It is most efficient if your ISR calls no other functions.
8885 If your ISR must call other functions, it is most efficient if those functions
8886 use the same bank as the ISR (see note 1 below); the next best is if the
8887 called functions use bank zero.
8888 It is very inefficient to call a function using a different, non-zero bank
8894 \begin_inset LatexCommand \label{sub:Startup-Code}
8899 \begin_inset LatexCommand \index{Startup code}
8906 The compiler inserts a call to the C routine
8908 _sdcc_external_startup()
8909 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8918 at the start of the CODE area.
8919 This routine is in the runtime library
8920 \begin_inset LatexCommand \index{Runtime library}
8925 By default this routine returns 0, if this routine returns a non-zero value,
8926 the static & global variable initialization will be skipped and the function
8927 main will be invoked.
8928 Otherwise static & global variables will be initialized before the function
8932 _sdcc_external_startup()
8934 routine to your program to override the default if you need to setup hardware
8935 or perform some other critical operation prior to static & global variable
8937 See also the compiler option
8956 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8963 Inline Assembler Code
8964 \begin_inset LatexCommand \index{Assembler routines}
8971 SDCC allows the use of in-line assembler with a few restriction as regards
8973 All labels defined within inline assembler code
8981 where nnnn is a number less than 100 (which implies a limit of utmost 100
8982 inline assembler labels
8990 It is strongly recommended that each assembly instruction (including labels)
8991 be placed in a separate line (as the example shows).
9005 \begin_inset LatexCommand \index{-\/-peep-asm}
9011 command line option is used, the inline assembler code will be passed through
9012 the peephole optimizer
9013 \begin_inset LatexCommand \index{Peephole optimizer}
9018 This might cause some unexpected changes in the inline assembler code.
9019 Please go through the peephole optimizer rules defined in file
9023 carefully before using this option.
9029 \begin_inset LatexCommand \index{\_asm}
9059 \begin_inset LatexCommand \index{\_endasm}
9066 The inline assembler code can contain any valid code understood by the assembler
9067 , this includes any assembler directives and comment lines.
9068 The compiler does not do any validation of the code within the
9078 Inline assembler code cannot reference any C-Labels, however it can reference
9080 \begin_inset LatexCommand \index{Labels}
9084 defined by the inline assembler, e.g.:
9109 ; some assembler code
9129 /* some more c code */
9131 clabel:\SpecialChar ~
9133 /* inline assembler cannot reference this label */
9145 $0003: ;label (can be reference by inline assembler only)
9157 /* some more c code */
9162 In other words inline assembly code can access labels defined in inline
9163 assembly within the scope of the function.
9164 The same goes the other way, ie.
9165 labels defines in inline assembly CANNOT be accessed by C statements.
9168 An example acessing a C variable is in section
9169 \begin_inset LatexCommand \ref{sub:Naked-Functions}
9176 Interfacing with Assembler Code
9177 \begin_inset LatexCommand \index{Assembler routines}
9182 \layout Subsubsection
9184 Global Registers used for Parameter Passing
9185 \begin_inset LatexCommand \index{Parameter passing}
9192 The compiler always uses the global registers
9195 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9200 \begin_inset LatexCommand \index{B (register)}
9209 \begin_inset LatexCommand \index{ACC}
9215 to pass the first parameter to a routine.
9216 The second parameter onwards is either allocated on the stack (for reentrant
9227 -stack-auto is used) or in data / xdata memory (depending on the memory
9230 \layout Subsubsection
9232 Assembler Routine(non-reentrant
9233 \begin_inset LatexCommand \index{reentrant}
9238 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
9245 In the following example the function c_func calls an assembler routine
9246 asm_func, which takes two parameters.
9251 extern int asm_func(unsigned char, unsigned char);
9255 int c_func (unsigned char i, unsigned char j)
9263 return asm_func(i,j);
9277 return c_func(10,9);
9282 The corresponding assembler function is:
9287 .globl _asm_func_PARM_2
9351 add a,_asm_func_PARM_2
9376 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9393 Note here that the return values are placed in 'dpl' - One byte return value,
9394 'dpl' LSB & 'dph' MSB for two byte values.
9395 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9396 b' & 'acc' for four byte values.
9399 The parameter naming convention is _<function_name>_PARM_<n>, where n is
9400 the parameter number starting from 1, and counting from the left.
9401 The first parameter is passed in
9402 \begin_inset Quotes eld
9406 \begin_inset Quotes erd
9409 for One bye parameter,
9410 \begin_inset Quotes eld
9414 \begin_inset Quotes erd
9418 \begin_inset Quotes eld
9422 \begin_inset Quotes erd
9426 \begin_inset Quotes eld
9430 \begin_inset Quotes erd
9433 for four bytes, the variable name for the second parameter will be _<function_n
9438 Assemble the assembler routine with the following command:
9445 asx8051 -losg asmfunc.asm
9452 Then compile and link the assembler routine to the C source file with the
9460 sdcc cfunc.c asmfunc.rel
9461 \layout Subsubsection
9463 Assembler Routine(reentrant
9464 \begin_inset LatexCommand \index{reentrant}
9469 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
9476 In this case the second parameter onwards will be passed on the stack, the
9477 parameters are pushed from right to left i.e.
9478 after the call the left most parameter will be on the top of the stack.
9484 extern int asm_func(unsigned char, unsigned char);
9488 int c_func (unsigned char i, unsigned char j) reentrant
9496 return asm_func(i,j);
9510 return c_func(10,9);
9515 The corresponding assembler routine is:
9621 The compiling and linking procedure remains the same, however note the extra
9622 entry & exit linkage required for the assembler code, _bp is the stack
9623 frame pointer and is used to compute the offset into the stack for parameters
9624 and local variables.
9628 \begin_inset LatexCommand \index{int (16 bit)}
9633 \begin_inset LatexCommand \index{long (32 bit)}
9640 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
9641 multiplication and modulus operations are implemented by support routines.
9642 These support routines are all developed in ANSI-C to facilitate porting
9643 to other MCUs, although some model specific assembler optimizations are
9645 The following files contain the described routines, all of them can be
9646 found in <installdir>/share/sdcc/lib.
9652 \begin_inset Tabular
9653 <lyxtabular version="3" rows="11" columns="2">
9655 <column alignment="left" valignment="top" leftline="true" width="0">
9656 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
9657 <row topline="true" bottomline="true">
9658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9679 <row topline="true">
9680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9693 16 bit multiplication
9697 <row topline="true">
9698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9711 signed 16 bit division (calls _divuint)
9715 <row topline="true">
9716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9729 unsigned 16 bit division
9733 <row topline="true">
9734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9747 signed 16 bit modulus (calls _moduint)
9751 <row topline="true">
9752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9765 unsigned 16 bit modulus
9769 <row topline="true">
9770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9783 32 bit multiplication
9787 <row topline="true">
9788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9801 signed 32 division (calls _divulong)
9805 <row topline="true">
9806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9819 unsigned 32 division
9823 <row topline="true">
9824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9837 signed 32 bit modulus (calls _modulong)
9841 <row topline="true" bottomline="true">
9842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9855 unsigned 32 bit modulus
9868 Since they are compiled as
9873 \begin_inset LatexCommand \index{reentrant}
9878 \begin_inset LatexCommand \index{interrupt}
9882 service routines should not do any of the above operations.
9883 If this is unavoidable then the above routines will need to be compiled
9897 \begin_inset LatexCommand \index{-\/-stack-auto}
9903 option, after which the source program will have to be compiled with
9916 \begin_inset LatexCommand \index{-\/-int-long-rent}
9923 Notice that you don't have to call this routines directly.
9924 The compiler will use them automatically every time a integer operation
9928 Floating Point Support
9929 \begin_inset LatexCommand \index{Floating point support}
9936 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9937 floating point support routines are derived from gcc's floatlib.c and consists
9938 of the following routines:
9946 \begin_inset Tabular
9947 <lyxtabular version="3" rows="17" columns="2">
9949 <column alignment="left" valignment="top" leftline="true" width="0">
9950 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
9951 <row topline="true" bottomline="true">
9952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9978 <row topline="true">
9979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10010 add floating point numbers
10014 <row topline="true">
10015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10046 subtract floating point numbers
10050 <row topline="true">
10051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10082 divide floating point numbers
10086 <row topline="true">
10087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10118 multiply floating point numbers
10122 <row topline="true">
10123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10154 convert floating point to unsigned char
10158 <row topline="true">
10159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10190 convert floating point to signed char
10194 <row topline="true">
10195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10226 convert floating point to unsigned int
10230 <row topline="true">
10231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10262 convert floating point to signed int
10266 <row topline="true">
10267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10307 convert floating point to unsigned long
10311 <row topline="true">
10312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10343 convert floating point to signed long
10347 <row topline="true">
10348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10379 convert unsigned char to floating point
10383 <row topline="true">
10384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10415 convert char to floating point number
10419 <row topline="true">
10420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10451 convert unsigned int to floating point
10455 <row topline="true">
10456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10487 convert int to floating point numbers
10491 <row topline="true">
10492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10523 convert unsigned long to floating point number
10527 <row topline="true" bottomline="true">
10528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10559 convert long to floating point number
10572 Note if all these routines are used simultaneously the data space might
10574 For serious floating point usage it is strongly recommended that the large
10576 Also notice that you don't have to call this routines directly.
10577 The compiler will use them automatically every time a floating point operation
10581 MCS51 Memory Models
10582 \begin_inset LatexCommand \index{Memory model}
10587 \begin_inset LatexCommand \index{MCS51 memory}
10594 SDCC allows two memory models for MCS51 code,
10603 Modules compiled with different memory models should
10607 be combined together or the results would be unpredictable.
10608 The library routines supplied with the compiler are compiled as both small
10610 The compiled library modules are contained in separate directories as small
10611 and large so that you can link to either set.
10615 When the large model is used all variables declared without a storage class
10616 will be allocated into the external ram, this includes all parameters and
10617 local variables (for non-reentrant
10618 \begin_inset LatexCommand \index{reentrant}
10623 When the small model is used variables without storage class are allocated
10624 in the internal ram.
10627 Judicious usage of the processor specific storage classes
10628 \begin_inset LatexCommand \index{Storage class}
10632 and the 'reentrant' function type will yield much more efficient code,
10633 than using the large model.
10634 Several optimizations are disabled when the program is compiled using the
10635 large model, it is therefore strongly recommended that the small model
10636 be used unless absolutely required.
10639 DS390 Memory Models
10640 \begin_inset LatexCommand \index{Memory model}
10645 \begin_inset LatexCommand \index{DS390 memory model}
10652 The only model supported is Flat 24
10653 \begin_inset LatexCommand \index{Flat 24 (memory model)}
10658 This generates code for the 24 bit contiguous addressing mode of the Dallas
10660 In this mode, up to four meg of external RAM or code space can be directly
10662 See the data sheets at www.dalsemi.com for further information on this part.
10666 Note that the compiler does not generate any code to place the processor
10667 into 24 bitmode (although
10671 in the ds390 libraries will do that for you).
10677 \begin_inset LatexCommand \index{Tinibios (DS390)}
10681 , the boot loader or similar code must ensure that the processor is in 24
10682 bit contiguous addressing mode before calling the SDCC startup code.
10700 option, variables will by default be placed into the XDATA segment.
10705 Segments may be placed anywhere in the 4 meg address space using the usual
10717 Note that if any segments are located above 64K, the -r flag must be passed
10718 to the linker to generate the proper segment relocations, and the Intel
10719 HEX output format must be used.
10720 The -r flag can be passed to the linker by using the option
10724 on the sdcc command line.
10725 However, currently the linker can not handle code segments > 64k.
10729 \begin_inset LatexCommand \index{Pragmas}
10736 SDCC supports the following #pragma directives.
10740 \begin_inset LatexCommand \index{\#pragma SAVE}
10744 - this will save all current options to the SAVE/RESTORE stack.
10749 \begin_inset LatexCommand \index{\#pragma RESTORE}
10753 - will restore saved options from the last save.
10754 SAVEs & RESTOREs can be nested.
10755 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
10756 RESTORE pulls current options from the stack.
10761 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10765 - will stop global common subexpression elimination.
10769 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10773 - will stop loop induction optimizations.
10777 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
10781 - will not generate code for boundary value checking, when switch statements
10782 are turned into jump-tables (dangerous).
10787 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
10791 - the compiler will not overlay the parameters and local variables of a
10796 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
10800 - the compiler will not warn you anymore for obvious mistakes, you'r on
10805 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
10809 - Will not do loop reversal optimization
10813 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10817 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
10819 \begin_inset LatexCommand \index{push/pop}
10823 instruction in ISR function (using interrupt
10824 \begin_inset LatexCommand \index{interrupt}
10829 The directive should be placed immediately before the ISR function definition
10830 and it affects ALL ISR functions following it.
10831 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
10832 EXCLUDE\SpecialChar ~
10834 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10842 \begin_inset LatexCommand \index{\#pragma NOIV}
10846 - Do not generate interrupt vector table entries for all ISR functions
10847 defined after the pragma.
10848 This is useful in cases where the interrupt vector table must be defined
10849 manually, or when there is a secondary, manually defined interrupt vector
10851 for the autovector feature of the Cypress EZ-USB FX2).
10855 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10860 \begin_inset LatexCommand \index{function prologue}
10864 function1[,function2[,function3...]] - The compiler by default uses a caller
10865 saves convention for register saving across function calls, however this
10866 can cause unnecessary register pushing & popping when calling small functions
10867 from larger functions.
10868 This option can be used to switch off the register saving convention for
10869 the function names specified.
10870 The compiler will not save registers when calling these functions, extra
10871 code need to be manually inserted at the entry & exit for these functions
10872 to save & restore the registers used by these functions, this can SUBSTANTIALLY
10873 reduce code & improve run time performance of the generated code.
10874 In the future the compiler (with inter procedural analysis) may be able
10875 to determine the appropriate scheme to use for each function call.
10886 -callee-saves command line option is used, the function names specified
10887 in #pragma\SpecialChar ~
10889 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10893 is appended to the list of functions specified in the command line.
10896 The pragma's are intended to be used to turn-off certain optimizations which
10897 might cause the compiler to generate extra stack / data space to store
10898 compiler generated temporary variables.
10899 This usually happens in large functions.
10900 Pragma directives should be used as shown in the following example, they
10901 are used to control options & optimizations for a given function; pragmas
10902 should be placed before and/or after a function, placing pragma's inside
10903 a function body could have unpredictable results.
10909 \begin_inset LatexCommand \index{\#pragma SAVE}
10920 /* save the current settings */
10923 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10932 /* turnoff global subexpression elimination */
10934 #pragma NOINDUCTION
10935 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10939 /* turn off induction optimizations */
10962 \begin_inset LatexCommand \index{\#pragma RESTORE}
10966 /* turn the optimizations back on */
10969 The compiler will generate a warning message when extra space is allocated.
10970 It is strongly recommended that the SAVE and RESTORE pragma's be used when
10971 changing options for a function.
10974 Defines Created by the Compiler
10975 \begin_inset LatexCommand \index{Defines created by the compiler}
10982 The compiler creates the following #defines
10983 \begin_inset LatexCommand \index{\#defines}
10993 \begin_inset Tabular
10994 <lyxtabular version="3" rows="10" columns="2">
10996 <column alignment="left" valignment="top" leftline="true" width="0">
10997 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
10998 <row topline="true" bottomline="true">
10999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11020 <row topline="true">
11021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11027 \begin_inset LatexCommand \index{SDCC}
11034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11039 this Symbol is always defined
11043 <row topline="true">
11044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11050 \begin_inset LatexCommand \index{SDCC\_mcs51}
11055 \begin_inset LatexCommand \index{SDCC\_ds390}
11060 \begin_inset LatexCommand \index{SDCC\_z80}
11067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11072 depending on the model used (e.g.: -mds390
11076 <row topline="true">
11077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11083 \begin_inset LatexCommand \index{\_\_mcs51}
11088 \begin_inset LatexCommand \index{\_\_ds390}
11093 \begin_inset LatexCommand \index{\_\_z80}
11100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11105 depending on the model used (e.g.
11110 <row topline="true">
11111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11117 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
11124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11147 <row topline="true">
11148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11154 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
11161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11184 <row topline="true">
11185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11191 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
11198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11221 <row topline="true">
11222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11228 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
11235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11258 <row topline="true">
11259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11265 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
11272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11285 <row topline="true" bottomline="true">
11286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11292 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
11299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11321 Debugging with SDCDB
11322 \begin_inset LatexCommand \index{sdcdb}
11329 SDCC is distributed with a source level debugger
11330 \begin_inset LatexCommand \index{Debugger}
11335 The debugger uses a command line interface, the command repertoire of the
11336 debugger has been kept as close to gdb
11337 \begin_inset LatexCommand \index{gdb}
11341 (the GNU debugger) as possible.
11342 The configuration and build process is part of the standard compiler installati
11343 on, which also builds and installs the debugger in the target directory
11344 specified during configuration.
11345 The debugger allows you debug BOTH at the C source and at the ASM source
11347 Sdcdb is available on Unix platforms only.
11350 Compiling for Debugging
11353 The \SpecialChar \-
11355 debug option must be specified for all files for which debug information
11356 is to be generated.
11357 The complier generates a .adb file for each of these files.
11358 The linker creates the .cdb file from the .adb files and the address information.
11359 This .cdb is used by the debugger.
11362 How the Debugger Works
11375 -debug option is specified the compiler generates extra symbol information
11376 some of which are put into the the assembler source and some are put into
11378 Then the linker creates the .cdb file from the individual .adb files with
11379 the address information for the symbols.
11380 The debugger reads the symbolic information generated by the compiler &
11381 the address information generated by the linker.
11382 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
11383 execution is controlled by the debugger.
11384 When a command is issued for the debugger, it translates it into appropriate
11385 commands for the simulator.
11388 Starting the Debugger
11391 The debugger can be started using the following command line.
11392 (Assume the file you are debugging has the file name foo).
11406 The debugger will look for the following files.
11409 foo.c - the source file.
11412 foo.cdb - the debugger symbol information file.
11415 foo.ihx - the Intel hex format
11416 \begin_inset LatexCommand \index{Intel hex format}
11423 Command Line Options.
11436 -directory=<source file directory> this option can used to specify the directory
11438 The debugger will look into the directory list specified for source, cdb
11440 The items in the directory list must be separated by ':', e.g.
11441 if the source files can be in the directories /home/src1 and /home/src2,
11452 -directory option should be -
11462 -directory=/home/src1:/home/src2.
11463 Note there can be no spaces in the option.
11467 -cd <directory> - change to the <directory>.
11470 -fullname - used by GUI front ends.
11473 -cpu <cpu-type> - this argument is passed to the simulator please see the
11474 simulator docs for details.
11477 -X <Clock frequency > this options is passed to the simulator please see
11478 the simulator docs for details.
11481 -s <serial port file> passed to simulator see the simulator docs for details.
11484 -S <serial in,out> passed to simulator see the simulator docs for details.
11490 As mentioned earlier the command interface for the debugger has been deliberatel
11491 y kept as close the GNU debugger gdb, as possible.
11492 This will help the integration with existing graphical user interfaces
11493 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
11494 If you use a graphical user interface for the debugger you can skip the
11496 \layout Subsubsection*
11498 break [line | file:line | function | file:function]
11501 Set breakpoint at specified line or function:
11510 sdcdb>break foo.c:100
11512 sdcdb>break funcfoo
11514 sdcdb>break foo.c:funcfoo
11515 \layout Subsubsection*
11517 clear [line | file:line | function | file:function ]
11520 Clear breakpoint at specified line or function:
11529 sdcdb>clear foo.c:100
11531 sdcdb>clear funcfoo
11533 sdcdb>clear foo.c:funcfoo
11534 \layout Subsubsection*
11539 Continue program being debugged, after breakpoint.
11540 \layout Subsubsection*
11545 Execute till the end of the current function.
11546 \layout Subsubsection*
11551 Delete breakpoint number 'n'.
11552 If used without any option clear ALL user defined break points.
11553 \layout Subsubsection*
11555 info [break | stack | frame | registers ]
11558 info break - list all breakpoints
11561 info stack - show the function call stack.
11564 info frame - show information about the current execution frame.
11567 info registers - show content of all registers.
11568 \layout Subsubsection*
11573 Step program until it reaches a different source line.
11574 \layout Subsubsection*
11579 Step program, proceeding through subroutine calls.
11580 \layout Subsubsection*
11585 Start debugged program.
11586 \layout Subsubsection*
11591 Print type information of the variable.
11592 \layout Subsubsection*
11597 print value of variable.
11598 \layout Subsubsection*
11603 load the given file name.
11604 Note this is an alternate method of loading file for debugging.
11605 \layout Subsubsection*
11610 print information about current frame.
11611 \layout Subsubsection*
11616 Toggle between C source & assembly source.
11617 \layout Subsubsection*
11619 ! simulator command
11622 Send the string following '!' to the simulator, the simulator response is
11624 Note the debugger does not interpret the command being sent to the simulator,
11625 so if a command like 'go' is sent the debugger can loose its execution
11626 context and may display incorrect values.
11627 \layout Subsubsection*
11634 My name is Bobby Brown"
11637 Interfacing with XEmacs
11638 \begin_inset LatexCommand \index{XEmacs}
11643 \begin_inset LatexCommand \index{Emacs}
11650 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
11651 sdcdb.el and sdcdbsrc.el.
11652 These two files can be found in the $(prefix)/bin directory after the installat
11654 These files need to be loaded into XEmacs for the interface to work.
11655 This can be done at XEmacs startup time by inserting the following into
11656 your '.xemacs' file (which can be found in your HOME directory):
11662 (load-file sdcdbsrc.el)
11668 .xemacs is a lisp file so the () around the command is REQUIRED.
11669 The files can also be loaded dynamically while XEmacs is running, set the
11670 environment variable 'EMACSLOADPATH' to the installation bin directory
11671 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
11672 To start the interface enter the following command:
11686 You will prompted to enter the file name to be debugged.
11691 The command line options that are passed to the simulator directly are bound
11692 to default values in the file sdcdbsrc.el.
11693 The variables are listed below, these values maybe changed as required.
11696 sdcdbsrc-cpu-type '51
11699 sdcdbsrc-frequency '11059200
11702 sdcdbsrc-serial nil
11705 The following is a list of key mapping for the debugger interface.
11713 ;; Current Listing ::
11715 ;;key\SpecialChar ~
11730 binding\SpecialChar ~
11754 ;;---\SpecialChar ~
11769 ------\SpecialChar ~
11809 sdcdb-next-from-src\SpecialChar ~
11835 sdcdb-back-from-src\SpecialChar ~
11861 sdcdb-cont-from-src\SpecialChar ~
11871 SDCDB continue command
11887 sdcdb-step-from-src\SpecialChar ~
11913 sdcdb-whatis-c-sexp\SpecialChar ~
11923 SDCDB ptypecommand for data at
11987 sdcdbsrc-delete\SpecialChar ~
12001 SDCDB Delete all breakpoints if no arg
12049 given or delete arg (C-u arg x)
12065 sdcdbsrc-frame\SpecialChar ~
12080 SDCDB Display current frame if no arg,
12129 given or display frame arg
12194 sdcdbsrc-goto-sdcdb\SpecialChar ~
12204 Goto the SDCDB output buffer
12220 sdcdb-print-c-sexp\SpecialChar ~
12231 SDCDB print command for data at
12295 sdcdbsrc-goto-sdcdb\SpecialChar ~
12305 Goto the SDCDB output buffer
12321 sdcdbsrc-mode\SpecialChar ~
12337 Toggles Sdcdbsrc mode (turns it off)
12341 ;; C-c C-f\SpecialChar ~
12349 sdcdb-finish-from-src\SpecialChar ~
12357 SDCDB finish command
12361 ;; C-x SPC\SpecialChar ~
12369 sdcdb-break\SpecialChar ~
12387 Set break for line with point
12389 ;; ESC t\SpecialChar ~
12399 sdcdbsrc-mode\SpecialChar ~
12415 Toggle Sdcdbsrc mode
12417 ;; ESC m\SpecialChar ~
12427 sdcdbsrc-srcmode\SpecialChar ~
12449 Here are a few guidelines that will help the compiler generate more efficient
12450 code, some of the tips are specific to this compiler others are generally
12451 good programming practice.
12454 Use the smallest data type to represent your data-value.
12455 If it is known in advance that the value is going to be less than 256 then
12456 use an 'unsigned char' instead of a 'short' or 'int'.
12459 Use unsigned when it is known in advance that the value is not going to
12461 This helps especially if you are doing division or multiplication.
12464 NEVER jump into a LOOP.
12467 Declare the variables to be local whenever possible, especially loop control
12468 variables (induction).
12471 Since the compiler does not always do implicit integral promotion, the programme
12472 r should do an explicit cast when integral promotion is required.
12475 Reducing the size of division, multiplication & modulus operations can reduce
12476 code size substantially.
12477 Take the following code for example.
12483 foobar(unsigned int p1, unsigned char ch)
12491 unsigned char ch1 = p1 % ch ;
12502 For the modulus operation the variable ch will be promoted to unsigned int
12503 first then the modulus operation will be performed (this will lead to a
12504 call to support routine _moduint()), and the result will be casted to a
12506 If the code is changed to
12511 foobar(unsigned int p1, unsigned char ch)
12519 unsigned char ch1 = (unsigned char)p1 % ch ;
12530 It would substantially reduce the code generated (future versions of the
12531 compiler will be smart enough to detect such optimization opportunities).
12535 Have a look at the assembly listing to get a
12536 \begin_inset Quotes sld
12540 \begin_inset Quotes srd
12543 for the code generation.
12546 Notes on MCS51 memory
12547 \begin_inset LatexCommand \index{MCS51 memory}
12554 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12555 RAM memory which is structured as follows
12559 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12562 - Bytes 20-2F - 16 bytes to hold 128 bit
12563 \begin_inset LatexCommand \index{bit}
12569 - Bytes 30-7F - 80 bytes for general purpose use.
12574 Additionally some members of the MCS51 family may have up to 128 bytes of
12575 additional, indirectly addressable, internal RAM memory (
12580 \begin_inset LatexCommand \index{idata}
12585 Furthermore, some chips may have some built in external memory (
12590 \begin_inset LatexCommand \index{xdata}
12594 ) which should not be confused with the internal, directly addressable RAM
12600 \begin_inset LatexCommand \index{data}
12605 Sometimes this built in
12609 memory has to be activated before using it (you can probably find this
12610 information on the datasheet of the microcontroller your are using).
12613 Normally SDCC will only use the first bank
12614 \begin_inset LatexCommand \index{bank}
12618 of registers (register bank 0), but it is possible to specify that other
12619 banks of registers should be used in interrupt
12620 \begin_inset LatexCommand \index{interrupt}
12625 By default, the compiler will place the stack after the last byte of allocated
12626 memory for variables.
12627 For example, if the first 2 banks of registers are used, and only four
12632 variables, it will position the base of the internal stack at address 20
12634 This implies that as the stack
12635 \begin_inset LatexCommand \index{stack}
12639 grows, it will use up the remaining register banks, and the 16 bytes used
12640 by the 128 bit variables, and 80 bytes for general purpose use.
12641 If any bit variables are used, the data variables will be placed after
12642 the byte holding the last bit variable.
12643 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12648 variables will be placed starting at address 0x22.
12660 \begin_inset LatexCommand \index{-\/-data-loc}
12664 to specify the start address of the
12678 -iram-size to specify the size of the total internal RAM (
12690 By default the 8051 linker will place the stack after the last byte of data
12703 \begin_inset LatexCommand \index{-\/-stack-loc}
12707 allows you to specify the start of the stack, i.e.
12708 you could start it after any data in the general purpose area.
12709 If your microcontroller has additional indirectly addressable internal
12714 ) you can place the stack on it.
12715 You may also need to use -
12726 \begin_inset LatexCommand \index{-\/-data-loc}
12730 to set the start address of the external RAM (
12745 \begin_inset LatexCommand \index{-\/-data-loc}
12749 to specify its size.
12750 Same goes for the code memory, using -
12761 \begin_inset LatexCommand \index{-\/-data-loc}
12776 \begin_inset LatexCommand \index{-\/-data-loc}
12781 If in doubt, don't specify any options and see if the resulting memory
12782 layout is appropriate, then you can adjust it.
12785 The 8051 linker generates two files with memory allocation information.
12786 The first, with extension .map shows all the variables and segments.
12787 The second with extension .mem shows the final memory layout.
12788 The linker will complaint either if memory segments overlap, there is not
12789 enough memory, or there is not enough space for stack.
12790 If you get any linking warnings and/or errors related to stack or segments
12791 allocation, take a look at either the .map or .mem files to find out what
12793 The .mem file may even suggest a solution to the problem.
12797 \begin_inset LatexCommand \index{Tools}
12801 included in the distribution
12805 \begin_inset Tabular
12806 <lyxtabular version="3" rows="12" columns="3">
12808 <column alignment="left" valignment="top" leftline="true" width="0pt">
12809 <column alignment="left" valignment="top" leftline="true" width="0pt">
12810 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
12811 <row topline="true" bottomline="true">
12812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12837 <row topline="true">
12838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12851 Simulator for various architectures
12854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12863 <row topline="true">
12864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12877 header file conversion
12880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12885 sdcc/support/scripts
12889 <row topline="true">
12890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12903 header file conversion
12906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12911 sdcc/support/scripts
12915 <row topline="true">
12916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12950 <row topline="true">
12951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12985 <row topline="true">
12986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13020 <row topline="true">
13021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13055 <row topline="true">
13056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13090 <row topline="true">
13091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13125 <row topline="true">
13126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13160 <row topline="true" bottomline="true">
13161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13204 Related open source tools
13205 \begin_inset LatexCommand \index{Related tools}
13213 \begin_inset Tabular
13214 <lyxtabular version="3" rows="8" columns="3">
13216 <column alignment="left" valignment="top" leftline="true" width="0pt">
13217 <column alignment="left" valignment="top" leftline="true" width="30line%">
13218 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
13219 <row topline="true" bottomline="true">
13220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13245 <row topline="true">
13246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13252 \begin_inset LatexCommand \index{gpsim}
13259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13273 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13281 <row topline="true">
13282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13304 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
13312 <row topline="true">
13313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13319 \begin_inset LatexCommand \index{srecord}
13326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13331 Object file conversion, checksumming, ...
13334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13340 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13348 <row topline="true">
13349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13355 \begin_inset LatexCommand \index{objdump}
13362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13367 Object file conversion, ...
13370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13375 Part of binutils (should be there anyway)
13379 <row topline="true">
13380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13386 \begin_inset LatexCommand \index{doxygen}
13393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13398 Source code documentation system
13401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13407 \begin_inset LatexCommand \url{http://www.doxygen.org}
13415 <row topline="true">
13416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13422 \begin_inset LatexCommand \index{splint}
13429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13434 Statically checks c sources
13437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13443 \begin_inset LatexCommand \url{http://www.splint.org}
13451 <row topline="true" bottomline="true">
13452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13458 \begin_inset LatexCommand \index{ddd}
13465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13470 Debugger, serves nicely as GUI to sdcdb
13471 \begin_inset LatexCommand \index{sdcdb}
13478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13484 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13501 Related documentation / recommended reading
13505 \begin_inset Tabular
13506 <lyxtabular version="3" rows="5" columns="3">
13508 <column alignment="left" valignment="top" leftline="true" width="0pt">
13509 <column alignment="left" valignment="top" leftline="true" width="30line%">
13510 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
13511 <row topline="true" bottomline="true">
13512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13537 <row topline="true">
13538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13553 Advanced Compiler Design and Implementation
13556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13565 <row topline="true">
13566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13589 \begin_inset LatexCommand \index{C Reference card}
13596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13602 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13610 <row topline="true">
13611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13616 test_suite_spec.pdf
13619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13624 sdcc regression test
13625 \begin_inset LatexCommand \index{Regression test}
13632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13641 <row topline="true" bottomline="true">
13642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13673 sdcc internal documentation
13676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13695 \begin_inset LatexCommand \index{Support}
13702 SDCC has grown to be a large project.
13703 The compiler alone (without the preprocessor, assembler and linker) is
13704 well over 100,000 lines of code (blank stripped).
13705 The open source nature of this project is a key to its continued growth
13707 You gain the benefit and support of many active software developers and
13709 Is SDCC perfect? No, that's why we need your help.
13710 The developers take pride in fixing reported bugs.
13711 You can help by reporting the bugs and helping other SDCC users.
13712 There are lots of ways to contribute, and we encourage you to take part
13713 in making SDCC a great software package.
13717 The SDCC project is hosted on the sdcc sourceforge site at
13718 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
13723 You'll find the complete set of mailing lists
13724 \begin_inset LatexCommand \index{Mailing list}
13728 , forums, bug reporting system, patch submission
13729 \begin_inset LatexCommand \index{Patch submission}
13734 \begin_inset LatexCommand \index{download}
13738 area and cvs code repository
13739 \begin_inset LatexCommand \index{cvs code repository}
13747 \begin_inset LatexCommand \index{Bugs}
13752 \begin_inset LatexCommand \index{Reporting bugs}
13759 The recommended way of reporting bugs is using the infrastructure of the
13761 You can follow the status of bug reports there and have an overview about
13765 Bug reports are automatically forwarded to the developer mailing list and
13766 will be fixed ASAP.
13767 When reporting a bug, it is very useful to include a small test program
13768 (the smaller the better) which reproduces the problem.
13769 If you can isolate the problem by looking at the generated assembly code,
13770 this can be very helpful.
13771 Compiling your program with the -
13782 \begin_inset LatexCommand \index{-\/-dumpall}
13786 option can sometimes be useful in locating optimization problems.
13787 When reporting a bug please maker sure you:
13790 Attach the code you are compiling with SDCC.
13794 Specify the exact command you use to run SDCC, or attach your Makefile.
13798 Specify the SDCC version (type "sdcc -v"), your platform, and operating
13803 Provide an exact copy of any error message or incorrect output.
13807 Put something meaningful in the subject of your message.
13810 Please attempt to include these 5 important parts, as applicable, in all
13811 requests for support or when reporting any problems or bugs with SDCC.
13812 Though this will make your message lengthy, it will greatly improve your
13813 chance that SDCC users and developers will be able to help you.
13814 Some SDCC developers are frustrated by bug reports without code provided
13815 that they can use to reproduce and ultimately fix the problem, so please
13816 be sure to provide sample code if you are reporting a bug!
13819 Please have a short check that you are using a recent version of SDCC and
13820 the bug is not yet known.
13821 This is the link for reporting bugs:
13822 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
13829 Requesting Features
13830 \begin_inset LatexCommand \label{sub:Requesting-Features}
13835 \begin_inset LatexCommand \index{Feature request}
13840 \begin_inset LatexCommand \index{Requesting features}
13847 Like bug reports feature requests are forwarded to the developer mailing
13849 This is the link for requesting features:
13850 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
13860 These links should take you directly to the
13861 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
13871 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
13872 automated messages (mid 2003)
13876 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
13880 , lists and forums are archived so if you are lucky someone already had
13885 \begin_inset LatexCommand \index{Changelog}
13892 You can follow the status of the cvs version
13893 \begin_inset LatexCommand \index{version}
13897 of SDCC by watching the file
13898 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
13902 in the cvs-repository.
13906 \begin_inset LatexCommand \index{Release policy}
13913 Historically there often were long delays between official releases and
13914 the sourceforge download area tends to get not updated at all.
13915 Current excuses might refer to problems with live range analysis, but if
13916 this is fixed, the next problem rising is that another excuse will have
13918 Kidding aside, we have to get better there! On the other hand there are
13919 daily snapshots available at
13920 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
13924 , and you can always built the very last version (hopefully with many bugs
13925 fixed, and features added) from the source code available at
13926 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
13934 \begin_inset LatexCommand \index{Examples}
13941 You'll find some small examples in the directory sdcc/device/examples/
13944 Maybe we should include some links to real world applications.
13945 Preferably pointer to pointers (one for each architecture) so this stays
13950 \begin_inset LatexCommand \index{Quality control}
13957 The compiler is passed through nightly compile and build checks.
13963 \begin_inset LatexCommand \index{Regression test}
13967 check that SDCC itself compiles flawlessly on several platforms and checks
13968 the quality of the code generated by SDCC by running the code through simulator
13970 There is a separate document
13973 \begin_inset LatexCommand \index{Test suite}
13982 You'll find the test code in the directory
13984 sdcc/support/regression
13987 You can run these tests manually by running
13991 in this directory (or f.e.
13996 if you don't want to run the complete tests).
13997 The test code might also be interesting if you want to look for examples
13998 \begin_inset LatexCommand \index{Examples}
14002 checking corner cases of SDCC or if you plan to submit patches
14003 \begin_inset LatexCommand \index{Patch submission}
14010 The pic port uses a different set of regression tests, you'll find them
14013 sdcc/src/regression
14018 SDCC Technical Data
14022 \begin_inset LatexCommand \index{Optimizations}
14029 SDCC performs a host of standard optimizations in addition to some MCU specific
14032 \layout Subsubsection
14034 Sub-expression Elimination
14035 \begin_inset LatexCommand \index{Subexpression elimination}
14042 The compiler does local and global common subexpression elimination, e.g.:
14053 will be translated to
14065 Some subexpressions are not as obvious as the above example, e.g.:
14075 In this case the address arithmetic a->b[i] will be computed only once;
14076 the equivalent code in C would be.
14088 The compiler will try to keep these temporary variables in registers.
14089 \layout Subsubsection
14091 Dead-Code Elimination
14092 \begin_inset LatexCommand \index{Dead-code elimination}
14113 i = 1; \SpecialChar ~
14122 global = 1;\SpecialChar ~
14135 global = 3;\SpecialChar ~
14161 \layout Subsubsection
14164 \begin_inset LatexCommand \index{Copy propagation}
14220 Note: the dead stores created by this copy propagation will be eliminated
14221 by dead-code elimination.
14222 \layout Subsubsection
14225 \begin_inset LatexCommand \index{Loop optimization}
14232 Two types of loop optimizations are done by SDCC loop invariant lifting
14233 and strength reduction of loop induction variables.
14234 In addition to the strength reduction the optimizer marks the induction
14235 variables and the register allocator tries to keep the induction variables
14236 in registers for the duration of the loop.
14237 Because of this preference of the register allocator
14238 \begin_inset LatexCommand \index{Register allocation}
14242 , loop induction optimization causes an increase in register pressure, which
14243 may cause unwanted spilling of other temporary variables into the stack
14244 \begin_inset LatexCommand \index{stack}
14249 The compiler will generate a warning message when it is forced to allocate
14250 extra space either on the stack or data space.
14251 If this extra space allocation is undesirable then induction optimization
14252 can be eliminated either for the entire source file (with -
14262 -noinduction option) or for a given function only using #pragma\SpecialChar ~
14264 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
14277 for (i = 0 ; i < 100 ; i ++)
14293 for (i = 0; i < 100; i++)
14302 As mentioned previously some loop invariants are not as apparent, all static
14303 address computations are also moved out of the loop.
14308 \begin_inset LatexCommand \index{Strength reduction}
14312 , this optimization substitutes an expression by a cheaper expression:
14317 for (i=0;i < 100; i++)
14335 for (i=0;i< 100;i++) {
14341 ar[itemp1] = itemp2;
14358 The more expensive multiplication
14359 \begin_inset LatexCommand \index{Multiplication}
14363 is changed to a less expensive addition.
14364 \layout Subsubsection
14367 \begin_inset LatexCommand \index{Loop reversing}
14374 This optimization is done to reduce the overhead of checking loop boundaries
14375 for every iteration.
14376 Some simple loops can be reversed and implemented using a
14377 \begin_inset Quotes eld
14380 decrement and jump if not zero
14381 \begin_inset Quotes erd
14385 SDCC checks for the following criterion to determine if a loop is reversible
14386 (note: more sophisticated compilers use data-dependency analysis to make
14387 this determination, SDCC uses a more simple minded analysis).
14390 The 'for' loop is of the form
14396 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
14406 The <for body> does not contain
14407 \begin_inset Quotes eld
14411 \begin_inset Quotes erd
14415 \begin_inset Quotes erd
14421 All goto's are contained within the loop.
14424 No function calls within the loop.
14427 The loop control variable <sym> is not assigned any value within the loop
14430 The loop control variable does NOT participate in any arithmetic operation
14434 There are NO switch statements in the loop.
14435 \layout Subsubsection
14437 Algebraic Simplifications
14440 SDCC does numerous algebraic simplifications, the following is a small sub-set
14441 of these optimizations.
14446 i = j + 0 ; /* changed to */ i = j;
14448 i /= 2;\SpecialChar ~
14452 /* changed to */ i >>= 1;
14454 i = j - j ; /* changed to */ i = 0;
14456 i = j / 1 ; /* changed to */ i = j;
14459 Note the subexpressions
14460 \begin_inset LatexCommand \index{Subexpression}
14464 given above are generally introduced by macro expansions or as a result
14465 of copy/constant propagation.
14466 \layout Subsubsection
14468 'switch' Statements
14469 \begin_inset LatexCommand \index{switch statement}
14476 SDCC changes switch statements to jump tables
14477 \begin_inset LatexCommand \index{jump tables}
14481 when the following conditions are true.
14485 The case labels are in numerical sequence, the labels need not be in order,
14486 and the starting number need not be one or zero.
14492 switch(i) {\SpecialChar ~
14523 case 4: ...\SpecialChar ~
14555 case 5: ...\SpecialChar ~
14587 case 3: ...\SpecialChar ~
14619 case 6: ...\SpecialChar ~
14687 Both the above switch statements will be implemented using a jump-table.
14688 The example to the right side is slightly more efficient as the check for
14689 the lower boundary of the jump-table is not needed.
14693 The number of case labels is at least three, since it takes two conditional
14694 statements to handle the boundary conditions.
14697 The number of case labels is less than 84, since each label takes 3 bytes
14698 and a jump-table can be utmost 256 bytes long.
14701 Switch statements which have gaps in the numeric sequence or those that
14702 have more that 84 case labels can be split into more than one switch statement
14703 for efficient code generation, e.g.:
14753 If the above switch statement is broken down into two switch statements
14792 case 9:\SpecialChar ~
14799 case 10:\SpecialChar ~
14805 case 11:\SpecialChar ~
14811 case 12:\SpecialChar ~
14818 then both the switch statements will be implemented using jump-tables whereas
14819 the unmodified switch statement will not be.
14820 You might also consider dummy cases 0 and 5 to 8 in this example.
14821 The pragma NOJTBOUND
14822 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
14826 can be used to turn off checking the
14839 \layout Subsubsection
14841 Bit-shifting Operations
14842 \begin_inset LatexCommand \index{Bit shifting}
14849 Bit shifting is one of the most frequently used operation in embedded programmin
14851 SDCC tries to implement bit-shift operations in the most efficient way
14867 generates the following code:
14884 In general SDCC will never setup a loop if the shift count is known.
14926 Note that SDCC stores numbers in little-endian
14927 \begin_inset LatexCommand \index{little-endian}
14932 \begin_inset LatexCommand \index{Endianness}
14937 lowest order first).
14938 \layout Subsubsection
14941 \begin_inset LatexCommand \index{Bit rotation}
14948 A special case of the bit-shift operation is bit rotation, SDCC recognizes
14949 the following expression to be a left bit-rotation:
14959 i = ((i << 1) | (i >> 7));
14968 will generate the following code:
14987 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
14988 ns of this case will also be recognized as bit-rotation, i.e.:
14993 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
14994 \layout Subsubsection
14997 \begin_inset LatexCommand \index{Highest Order Bit}
15004 It is frequently required to obtain the highest order bit of an integral
15005 type (long, int, short or char types).
15006 SDCC recognizes the following expression to yield the highest order bit
15007 and generates optimized code for it, e.g.:
15029 hob = (gint >> 15) & 1;
15039 will generate the following code:
15072 000A E5*01\SpecialChar ~
15099 000C 23\SpecialChar ~
15130 000D 54 01\SpecialChar ~
15157 000F F5*02\SpecialChar ~
15185 Variations of this case however will
15190 It is a standard C expression, so I heartily recommend this be the only
15191 way to get the highest order bit, (it is portable).
15192 Of course it will be recognized even if it is embedded in other expressions,
15198 xyz = gint + ((gint >> 15) & 1);
15201 will still be recognized.
15202 \layout Subsubsection
15205 \begin_inset LatexCommand \index{Peephole optimizer}
15212 The compiler uses a rule based, pattern matching and re-writing mechanism
15213 for peep-hole optimization.
15218 a peep-hole optimizer by Christopher W.
15219 Fraser (cwfraser@microsoft.com).
15220 A default set of rules are compiled into the compiler, additional rules
15221 may be added with the
15234 \begin_inset LatexCommand \index{-\/-peep-file}
15241 The rule language is best illustrated with examples.
15265 The above rule will change the following assembly
15266 \begin_inset LatexCommand \index{Assembler routines}
15288 Note: All occurrences of a
15292 (pattern variable) must denote the same string.
15293 With the above rule, the assembly sequence:
15303 will remain unmodified.
15307 Other special case optimizations may be added by the user (via
15323 some variants of the 8051 MCU allow only
15332 The following two rules will change all
15351 replace { lcall %1 } by { acall %1 }
15353 replace { ljmp %1 } by { ajmp %1 }
15358 inline-assembler code
15360 is also passed through the peep hole optimizer, thus the peephole optimizer
15361 can also be used as an assembly level macro expander.
15362 The rules themselves are MCU dependent whereas the rule language infra-structur
15363 e is MCU independent.
15364 Peephole optimization rules for other MCU can be easily programmed using
15369 The syntax for a rule is as follows:
15374 rule := replace [ restart ] '{' <assembly sequence> '
15412 <assembly sequence> '
15430 '}' [if <functionName> ] '
15435 <assembly sequence> := assembly instruction (each instruction including
15436 labels must be on a separate line).
15440 The optimizer will apply to the rules one by one from the top in the sequence
15441 of their appearance, it will terminate when all rules are exhausted.
15442 If the 'restart' option is specified, then the optimizer will start matching
15443 the rules again from the top, this option for a rule is expensive (performance)
15444 , it is intended to be used in situations where a transformation will trigger
15445 the same rule again.
15446 An example of this (not a good one, it has side effects) is the following
15469 Note that the replace pattern cannot be a blank, but can be a comment line.
15470 Without the 'restart' option only the inner most 'pop' 'push' pair would
15471 be eliminated, i.e.:
15501 the restart option the rule will be applied again to the resulting code
15502 and then all the pop-push pairs will be eliminated to yield:
15512 A conditional function can be attached to a rule.
15513 Attaching rules are somewhat more involved, let me illustrate this with
15540 The optimizer does a look-up of a function name table defined in function
15545 in the source file SDCCpeeph.c, with the name
15550 If it finds a corresponding entry the function is called.
15551 Note there can be no parameters specified for these functions, in this
15556 is crucial, since the function
15560 expects to find the label in that particular variable (the hash table containin
15561 g the variable bindings is passed as a parameter).
15562 If you want to code more such functions, take a close look at the function
15563 labelInRange and the calling mechanism in source file SDCCpeeph.c.
15564 Currently implemented are
15566 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
15567 24bitMode, portIsDS390, 24bitModeAndPortDS390
15576 I know this whole thing is a little kludgey, but maybe some day we will
15577 have some better means.
15578 If you are looking at this file, you will see the default rules that are
15579 compiled into the compiler, you can add your own rules in the default set
15580 there if you get tired of specifying the -
15600 <pending: this is messy and incomplete>
15605 Compiler support routines (_gptrget, _mulint etc)
15608 Stdclib functions (puts, printf, strcat etc)
15611 Math functions (sin, pow, sqrt etc)
15615 \begin_inset LatexCommand \index{Libraries}
15619 included in SDCC should have a license at least as liberal as the GNU Lesser
15620 General Public License
15621 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15632 license statements for the libraries are missing.
15633 sdcc/device/lib/ser_ir.c
15637 come with a GPL (as opposed to LGPL) License - this will not be liberal
15638 enough for many embedded programmers.
15642 \begin_inset LatexCommand \label{sub:External-Stack}
15647 \begin_inset LatexCommand \index{stack}
15652 \begin_inset LatexCommand \index{External stack}
15659 The external stack (-
15670 \begin_inset LatexCommand \index{-\/-xstack}
15674 ) is located at the start of the external ram segment, and is 256 bytes
15686 -xstack option is used to compile the program, the parameters and local
15687 variables of all reentrant functions are allocated in this area.
15688 This option is provided for programs with large stack space requirements.
15689 When used with the -
15700 \begin_inset LatexCommand \index{-\/-stack-auto}
15704 option, all parameters and local variables are allocated on the external
15705 stack (note support libraries will need to be recompiled with the same
15709 The compiler outputs the higher order address byte of the external ram segment
15710 into PORT P2, therefore when using the External Stack option, this port
15711 MAY NOT be used by the application program.
15715 \begin_inset LatexCommand \index{ANSI-compliance}
15722 Deviations from the compliance:
15725 functions are not always reentrant.
15728 structures cannot be assigned values directly, cannot be passed as function
15729 parameters or assigned to each other and cannot be a return value from
15756 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
15767 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
15789 return rets;/* is invalid in SDCC although allowed in ANSI */
15796 \begin_inset LatexCommand \index{long long (not supported)}
15801 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
15809 \begin_inset LatexCommand \index{double (not supported)}
15813 ' precision floating point
15814 \begin_inset LatexCommand \index{Floating point support}
15821 No support for setjmp and longjmp (for now).
15825 \begin_inset LatexCommand \index{K\&R style}
15829 function declarations are NOT allowed.
15835 foo(i,j) /* this old style of function declarations */
15837 int i,j; /* are valid in ANSI but not valid in SDCC */
15852 functions declared as pointers must be dereferenced during the call.
15863 /* has to be called like this */
15865 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
15869 Cyclomatic Complexity
15870 \begin_inset LatexCommand \index{Cyclomatic complexity}
15877 Cyclomatic complexity of a function is defined as the number of independent
15878 paths the program can take during execution of the function.
15879 This is an important number since it defines the number test cases you
15880 have to generate to validate the function.
15881 The accepted industry standard for complexity number is 10, if the cyclomatic
15882 complexity reported by SDCC exceeds 10 you should think about simplification
15883 of the function logic.
15884 Note that the complexity level is not related to the number of lines of
15885 code in a function.
15886 Large functions can have low complexity, and small functions can have large
15892 SDCC uses the following formula to compute the complexity:
15897 complexity = (number of edges in control flow graph) - (number of nodes
15898 in control flow graph) + 2;
15902 Having said that the industry standard is 10, you should be aware that in
15903 some cases it be may unavoidable to have a complexity level of less than
15905 For example if you have switch statement with more than 10 case labels,
15906 each case label adds one to the complexity level.
15907 The complexity level is by no means an absolute measure of the algorithmic
15908 complexity of the function, it does however provide a good starting point
15909 for which functions you might look at for further optimization.
15913 \layout Subsubsection
15916 \begin_inset LatexCommand \index{MCS51 variants}
15923 MCS51 processors are available from many vendors and come in many different
15925 While they might differ considerably in respect to Special Function Registers
15926 the core MCS51 is usually not modified or is kept compatible.
15928 \layout Subsubsection*
15930 pdata access by SFR
15933 With the upcome of devices with internal xdata and flash memory devices
15934 using port P2 as dedicated I/O port is becoming more popular.
15935 Switching the high byte for pdata
15936 \begin_inset LatexCommand \index{pdata}
15940 access which was formerly done by port P2 is then achieved by a Special
15942 In well-established MCS51 tradition the address of this
15946 is where the chip designers decided to put it.
15947 As pdata addressing is used in the startup code for the initialization
15948 of xdata variables a separate startup code should be used as described
15950 \begin_inset LatexCommand \ref{sub:Startup-Code}
15955 \layout Subsubsection*
15957 Other Features available by SFR
15960 Some MCS51 variants offer features like Double DPTR
15961 \begin_inset LatexCommand \index{DPTR}
15965 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
15966 These are currently not used for the MCS51 port.
15967 If you absolutely need them you can fall back to inline assembly or submit
15969 \layout Subsubsection
15971 The Z80 and gbz80 port
15974 SDCC can target both the Zilog
15975 \begin_inset LatexCommand \index{Z80}
15979 and the Nintendo Gameboy's Z80-like gbz80
15980 \begin_inset LatexCommand \index{GameBoy Z80}
15985 The Z80 port is passed through the same
15988 \begin_inset LatexCommand \index{Regression test}
15994 as MCS51 and DS390 ports, so floating point support, support for long variables
15995 and bitfield support is fine.
15998 As always, the code is the authoritative reference - see z80/ralloc.c and
16000 The stack frame is similar to that generated by the IAR Z80 compiler.
16001 IX is used as the base pointer, HL is used as a temporary register, and
16002 BC and DE are available for holding variables.
16003 IY is currently unused.
16004 Return values are stored in HL.
16005 One bad side effect of using IX as the base pointer is that a functions
16006 stack frame is limited to 127 bytes - this will be fixed in a later version.
16009 Retargetting for other MCUs.
16012 The issues for retargetting the compiler are far too numerous to be covered
16014 What follows is a brief description of each of the seven phases of the
16015 compiler and its MCU dependency.
16018 Parsing the source and building the annotated parse tree.
16019 This phase is largely MCU independent (except for the language extensions).
16020 Syntax & semantic checks are also done in this phase, along with some initial
16021 optimizations like back patching labels and the pattern matching optimizations
16022 like bit-rotation etc.
16025 The second phase involves generating an intermediate code which can be easy
16026 manipulated during the later phases.
16027 This phase is entirely MCU independent.
16028 The intermediate code generation assumes the target machine has unlimited
16029 number of registers, and designates them with the name iTemp.
16030 The compiler can be made to dump a human readable form of the code generated
16044 This phase does the bulk of the standard optimizations and is also MCU independe
16046 This phase can be broken down into several sub-phases:
16050 Break down intermediate code (iCode) into basic blocks.
16052 Do control flow & data flow analysis on the basic blocks.
16054 Do local common subexpression elimination, then global subexpression elimination
16056 Dead code elimination
16060 If loop optimizations caused any changes then do 'global subexpression eliminati
16061 on' and 'dead code elimination' again.
16064 This phase determines the live-ranges; by live range I mean those iTemp
16065 variables defined by the compiler that still survive after all the optimization
16067 Live range analysis
16068 \begin_inset LatexCommand \index{Live range analysis}
16072 is essential for register allocation, since these computation determines
16073 which of these iTemps will be assigned to registers, and for how long.
16076 Phase five is register allocation.
16077 There are two parts to this process.
16081 The first part I call 'register packing' (for lack of a better term).
16082 In this case several MCU specific expression folding is done to reduce
16087 The second part is more MCU independent and deals with allocating registers
16088 to the remaining live ranges.
16089 A lot of MCU specific code does creep into this phase because of the limited
16090 number of index registers available in the 8051.
16093 The Code generation phase is (unhappily), entirely MCU dependent and very
16094 little (if any at all) of this code can be reused for other MCU.
16095 However the scheme for allocating a homogenized assembler operand for each
16096 iCode operand may be reused.
16099 As mentioned in the optimization section the peep-hole optimizer is rule
16100 based system, which can reprogrammed for other MCUs.
16104 \begin_inset LatexCommand \index{Compiler internals}
16111 The anatomy of the compiler
16116 This is an excerpt from an article published in Circuit Cellar Magazine
16118 It's a little outdated (the compiler is much more efficient now and user/develo
16119 per friendly), but pretty well exposes the guts of it all.
16125 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
16126 It is fairly easy to retarget for other 8-bit MCU.
16127 Here we take a look at some of the internals of the compiler.
16132 \begin_inset LatexCommand \index{Parsing}
16139 Parsing the input source file and creating an AST (Annotated Syntax Tree
16140 \begin_inset LatexCommand \index{Annotated syntax tree}
16145 This phase also involves propagating types (annotating each node of the
16146 parse tree with type information) and semantic analysis.
16147 There are some MCU specific parsing rules.
16148 For example the storage classes, the extended storage classes are MCU specific
16149 while there may be a xdata storage class for 8051 there is no such storage
16150 class for z80 or Atmel AVR.
16151 SDCC allows MCU specific storage class extensions, i.e.
16152 xdata will be treated as a storage class specifier when parsing 8051 C
16153 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
16158 \begin_inset LatexCommand \index{iCode}
16165 Intermediate code generation.
16166 In this phase the AST is broken down into three-operand form (iCode).
16167 These three operand forms are represented as doubly linked lists.
16168 ICode is the term given to the intermediate form generated by the compiler.
16169 ICode example section shows some examples of iCode generated for some simple
16170 C source functions.
16174 \begin_inset LatexCommand \index{Optimizations}
16181 Bulk of the target independent optimizations is performed in this phase.
16182 The optimizations include constant propagation, common sub-expression eliminati
16183 on, loop invariant code movement, strength reduction of loop induction variables
16184 and dead-code elimination.
16187 Live range analysis
16188 \begin_inset LatexCommand \index{Live range analysis}
16195 During intermediate code generation phase, the compiler assumes the target
16196 machine has infinite number of registers and generates a lot of temporary
16198 The live range computation determines the lifetime of each of these compiler-ge
16199 nerated temporaries.
16200 A picture speaks a thousand words.
16201 ICode example sections show the live range annotations for each of the
16203 It is important to note here, each iCode is assigned a number in the order
16204 of its execution in the function.
16205 The live ranges are computed in terms of these numbers.
16206 The from number is the number of the iCode which first defines the operand
16207 and the to number signifies the iCode which uses this operand last.
16210 Register Allocation
16211 \begin_inset LatexCommand \index{Register allocation}
16218 The register allocation determines the type and number of registers needed
16220 In most MCUs only a few registers can be used for indirect addressing.
16221 In case of 8051 for example the registers R0 & R1 can be used to indirectly
16222 address the internal ram and DPTR to indirectly address the external ram.
16223 The compiler will try to allocate the appropriate register to pointer variables
16225 ICode example section shows the operands annotated with the registers assigned
16227 The compiler will try to keep operands in registers as much as possible;
16228 there are several schemes the compiler uses to do achieve this.
16229 When the compiler runs out of registers the compiler will check to see
16230 if there are any live operands which is not used or defined in the current
16231 basic block being processed, if there are any found then it will push that
16232 operand and use the registers in this block, the operand will then be popped
16233 at the end of the basic block.
16237 There are other MCU specific considerations in this phase.
16238 Some MCUs have an accumulator; very short-lived operands could be assigned
16239 to the accumulator instead of general-purpose register.
16245 Figure II gives a table of iCode operations supported by the compiler.
16246 The code generation involves translating these operations into corresponding
16247 assembly code for the processor.
16248 This sounds overly simple but that is the essence of code generation.
16249 Some of the iCode operations are generated on a MCU specific manner for
16250 example, the z80 port does not use registers to pass parameters so the
16251 SEND and RECV iCode operations will not be generated, and it also does
16252 not support JUMPTABLES.
16259 <Where is Figure II ?>
16263 \begin_inset LatexCommand \index{iCode}
16270 This section shows some details of iCode.
16271 The example C code does not do anything useful; it is used as an example
16272 to illustrate the intermediate code generated by the compiler.
16284 /* This function does nothing useful.
16291 for the purpose of explaining iCode */
16294 short function (data int *x)
16302 short i=10; /* dead initialization eliminated */
16307 short sum=10; /* dead initialization eliminated */
16320 while (*x) *x++ = *p++;
16334 /* compiler detects i,j to be induction variables */
16338 for (i = 0, j = 10 ; i < 10 ; i++, j
16364 mul += i * 3; /* this multiplication remains */
16370 gint += j * 3;/* this multiplication changed to addition */
16384 In addition to the operands each iCode contains information about the filename
16385 and line it corresponds to in the source file.
16386 The first field in the listing should be interpreted as follows:
16391 Filename(linenumber: iCode Execution sequence number : ICode hash table
16392 key : loop depth of the iCode).
16397 Then follows the human readable form of the ICode operation.
16398 Each operand of this triplet form can be of three basic types a) compiler
16399 generated temporary b) user defined variable c) a constant value.
16400 Note that local variables and parameters are replaced by compiler generated
16403 \begin_inset LatexCommand \index{Live range analysis}
16407 are computed only for temporaries (i.e.
16408 live ranges are not computed for global variables).
16410 \begin_inset LatexCommand \index{Register allocation}
16414 are allocated for temporaries only.
16415 Operands are formatted in the following manner:
16420 Operand Name [lr live-from : live-to ] { type information } [ registers
16426 As mentioned earlier the live ranges are computed in terms of the execution
16427 sequence number of the iCodes, for example
16429 the iTemp0 is live from (i.e.
16430 first defined in iCode with execution sequence number 3, and is last used
16431 in the iCode with sequence number 5).
16432 For induction variables such as iTemp21 the live range computation extends
16433 the lifetime from the start to the end of the loop.
16435 The register allocator used the live range information to allocate registers,
16436 the same registers may be used for different temporaries if their live
16437 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
16438 iTemp17 since their live ranges do not overlap.
16439 In addition the allocator also takes into consideration the type and usage
16440 of a temporary, for example itemp6 is a pointer to near space and is used
16441 as to fetch data from (i.e.
16442 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
16443 Some short lived temporaries are allocated to special registers which have
16444 meaning to the code generator e.g.
16445 iTemp13 is allocated to a pseudo register CC which tells the back end that
16446 the temporary is used only for a conditional jump the code generation makes
16447 use of this information to optimize a compare and jump ICode.
16449 There are several loop optimizations
16450 \begin_inset LatexCommand \index{Loop optimization}
16454 performed by the compiler.
16455 It can detect induction variables iTemp21(i) and iTemp23(j).
16456 Also note the compiler does selective strength reduction
16457 \begin_inset LatexCommand \index{Strength reduction}
16462 the multiplication of an induction variable in line 18 (gint = j * 3) is
16463 changed to addition, a new temporary iTemp17 is allocated and assigned
16464 a initial value, a constant 3 is then added for each iteration of the loop.
16465 The compiler does not change the multiplication
16466 \begin_inset LatexCommand \index{Multiplication}
16470 in line 17 however since the processor does support an 8 * 8 bit multiplication.
16472 Note the dead code elimination
16473 \begin_inset LatexCommand \index{Dead-code elimination}
16477 optimization eliminated the dead assignments in line 7 & 8 to I and sum
16485 Sample.c (5:1:0:0) _entry($9) :
16490 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
16495 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
16500 Sample.c(11:4:53:0) preHeaderLbl0($11) :
16505 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
16511 Sample.c(11:6:5:1) _whilecontinue_0($1) :
16516 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
16522 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16527 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
16533 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
16539 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
16545 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
16551 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
16552 * int}[r0] + 0x2 {short}
16557 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
16562 Sample.c(11:17:21:0)_whilebreak_0($3) :
16567 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16572 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16577 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16582 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16587 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16592 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16597 Sample.c(15:24:26:1)_forcond_0($4) :
16602 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16608 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16613 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16614 + ITemp21 [lr21:38]{short}[r4]
16619 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16625 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16626 + iTemp15 [lr29:30]{short}[r1]
16631 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16637 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16643 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16649 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16655 Sample.c(19:38:47:1) goto _forcond_0($4)
16660 Sample.c(19:39:48:0)_forbreak_0($7) :
16665 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16666 + ITemp11 [lr19:40]{short}[r3]
16671 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16676 Sample.c(20:42:51:0)_return($8) :
16681 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16687 Finally the code generated for this function:
16728 ; ----------------------------------------------
16733 ; function function
16738 ; ----------------------------------------------
16748 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16760 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16772 ;_whilecontinue_0($1) :
16782 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16787 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16846 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16865 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16912 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16952 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16978 ; iTemp6 [lr5:16]{_near * int}[r0] =
16983 ; iTemp6 [lr5:16]{_near * int}[r0] +
17000 ; goto _whilecontinue_0($1)
17012 ; _whilebreak_0($3) :
17022 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
17034 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
17046 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
17058 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
17077 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
17106 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
17111 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
17156 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
17161 ; iTemp21 [lr21:38]{short}[r4]
17187 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
17220 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
17225 ; iTemp15 [lr29:30]{short}[r1]
17244 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
17291 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
17338 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
17350 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
17364 cjne r5,#0xff,00104$
17376 ; goto _forcond_0($4)
17388 ; _forbreak_0($7) :
17398 ; ret iTemp24 [lr40:41]{short}
17441 A few words about basic block successors, predecessors and dominators
17444 Successors are basic blocks
17445 \begin_inset LatexCommand \index{Basic blocks}
17449 that might execute after this basic block.
17451 Predecessors are basic blocks that might execute before reaching this basic
17454 Dominators are basic blocks that WILL execute before reaching this basic
17488 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
17491 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
17494 c) domVect of [BB4] = BB1 ...
17495 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
17503 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
17513 Thanks to all the other volunteer developers who have helped with coding,
17514 testing, web-page creation, distribution sets, etc.
17515 You know who you are :-)
17522 This document was initially written by Sandeep Dutta
17525 All product names mentioned herein may be trademarks
17526 \begin_inset LatexCommand \index{Trademarks}
17530 of their respective companies.
17537 To avoid confusion, the installation and building options for sdcc itself
17538 (chapter 2) are not part of the index.
17542 \begin_inset LatexCommand \printindex{}