1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
6 pdftitle={SDCC Compiler User Guide},
7 pdfauthor={SDCC development team},
8 pdfsubject={installation, user manual},
9 pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
10 embedded, GPL, manual, mcs51, PIC, small, Z80},
12 linkcolor=blue] {hyperref}
16 \inputencoding default
19 \paperfontsize default
21 \papersize letterpaper
26 \use_numerical_citations 0
27 \paperorientation portrait
34 \paragraph_separation indent
36 \quotes_language swedish
44 Please note: double dashed longoptions (e.g.
45 --version) are written this way: -
59 three consecutive dashes simply result in a long resp.
63 Architecture specific stuff (like memory models, code examples) should maybe
67 into seperate sections/chapters/appendices (it is hard to document PIC or
71 a 8051 centered document)
74 SDCC Compiler User Guide
77 The strings enclosed in $ are automatically updated by cvs:
91 \begin_inset LatexCommand \tableofcontents{}
108 is a Freeware, retargettable, optimizing ANSI-C compiler by
112 designed for 8 bit Microprocessors.
113 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
115 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052 CPU}
119 , etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
120 It can be retargetted for other microprocessors, support for Microchip
121 PIC, Atmel AVR is under development.
122 The entire source code for the compiler is distributed under GPL.
123 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
124 SDCC has extensive language extensions suitable for utilizing various microcont
125 rollers and underlying hardware effectively.
130 In addition to the MCU specific optimizations SDCC also does a host of standard
134 global sub expression elimination,
137 loop optimizations (loop invariant, strength reduction of induction variables
141 constant folding & propagation,
147 dead code elimination
157 For the back-end SDCC uses a global register allocation scheme which should
158 be well suited for other 8 bit MCUs.
163 The peep hole optimizer uses a rule based substitution mechanism which is
169 Supported data-types are:
172 char (8 bits, 1 byte),
175 short and int (16 bits, 2 bytes),
178 long (32 bit, 4 bytes)
185 The compiler also allows
187 inline assembler code
189 to be embedded anywhere in a function.
190 In addition, routines developed in assembly can also be called.
194 SDCC also provides an option (-
204 -cyclomatic) to report the relative complexity of a function.
205 These functions can then be further optimized, or hand coded in assembly
211 SDCC also comes with a companion source level debugger SDCDB, the debugger
212 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
217 The latest version can be downloaded from
218 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
228 Please note: the compiler will probably always be some steps ahead of this
233 \begin_inset LatexCommand \index{Status of documentation}
243 Obviously this has pros and cons
252 All packages used in this compiler system are
260 ; source code for all the sub-packages (pre-processor, assemblers, linkers
261 etc) is distributed with the package.
262 This documentation is maintained using a freeware word processor (LyX).
264 This program is free software; you can redistribute it and/or modify it
265 under the terms of the GNU General Public License
266 \begin_inset LatexCommand \index{GNU General Public License, GPL}
270 as published by the Free Software Foundation; either version 2, or (at
271 your option) any later version.
272 This program is distributed in the hope that it will be useful, but WITHOUT
273 ANY WARRANTY; without even the implied warranty
274 \begin_inset LatexCommand \index{warranty}
278 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
279 See the GNU General Public License for more details.
280 You should have received a copy of the GNU General Public License along
281 with this program; if not, write to the Free Software Foundation, 59 Temple
282 Place - Suite 330, Boston, MA 02111-1307, USA.
283 In other words, you are welcome to use, share and improve this program.
284 You are forbidden to forbid anyone else to use, share and improve what
286 Help stamp out software-hoarding!
289 Typographic conventions
290 \begin_inset LatexCommand \index{Typographic conventions}
297 Throughout this manual, we will use the following convention.
298 Commands you have to type in are printed in
306 Code samples are printed in
311 Interesting items and new terms are printed in
316 Compatibility with previous versions
319 This version has numerous bug fixes compared with the previous version.
320 But we also introduced some incompatibilities with older versions.
321 Not just for the fun of it, but to make the compiler more stable, efficient
323 \begin_inset LatexCommand \index{ANSI-compliance}
333 short is now equivalent to int (16 bits), it used to be equivalent to char
334 (8 bits) which is not ANSI compliant
337 the default directory for gcc-builds where include, library and documentation
338 files are stored is now in /usr/local/share
341 char type parameters to vararg functions are casted to int unless explicitly
358 will push a as an int and as a char resp.
371 -regextend has been removed
384 -noregparms has been removed
397 -stack-after-data has been removed
402 <pending: more incompatibilities?>
408 What do you need before you start installation of SDCC? A computer, and
410 The preferred method of installation is to compile SDCC from source using
412 For Windows some pre-compiled binary distributions are available for your
414 You should have some experience with command line tools and compiler use.
420 The SDCC home page at
421 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
425 is a great place to find distribution sets.
426 You can also find links to the user mailing lists that offer help or discuss
427 SDCC with other SDCC users.
428 Web links to other SDCC related sites can also be found here.
429 This document can be found in the DOC directory of the source package as
431 Some of the other tools (simulator and assembler) included with SDCC contain
432 their own documentation and can be found in the source distribution.
433 If you want the latest unreleased software, the complete source package
434 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
437 Wishes for the future
440 There are (and always will be) some things that could be done.
441 Here are some I can think of:
448 char KernelFunction3(char p) at 0x340;
456 \begin_inset LatexCommand \index{code banking (not supported)}
466 If you can think of some more, please see the chapter
467 \begin_inset LatexCommand \ref{sub:Requesting-Features}
471 about filing feature requests
472 \begin_inset LatexCommand \index{Requesting features}
477 \begin_inset LatexCommand \index{Feature request}
487 \begin_inset LatexCommand \index{Installation}
494 For most users it is sufficient to skip to either section
495 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
500 \begin_inset LatexCommand \ref{sub:Windows-Install}
505 More detailled instructions follow below.
509 \begin_inset LatexCommand \index{Options SDCC configuration}
516 The install paths, search paths and other options are defined when running
518 The defaults can be overridden by:
520 \labelwidthstring 00.00.0000
532 -prefix see table below
534 \labelwidthstring 00.00.0000
546 -exec_prefix see table below
548 \labelwidthstring 00.00.0000
560 -bindir see table below
562 \labelwidthstring 00.00.0000
574 -datadir see table below
576 \labelwidthstring 00.00.0000
578 docdir environment variable, see table below
580 \labelwidthstring 00.00.0000
582 include_dir_suffix environment variable, see table below
584 \labelwidthstring 00.00.0000
586 lib_dir_suffix environment variable, see table below
588 \labelwidthstring 00.00.0000
590 sdccconf_h_dir_separator environment variable, either / or
595 This character will only be used in sdccconf.h; don't forget it's a C-header,
596 therefore a double-backslash is needed there.
598 \labelwidthstring 00.00.0000
610 -disable-mcs51-port Excludes the Intel mcs51 port
612 \labelwidthstring 00.00.0000
624 -disable-gbz80-port Excludes the Gameboy gbz80 port
626 \labelwidthstring 00.00.0000
638 -z80-port Excludes the z80 port
640 \labelwidthstring 00.00.0000
652 -disable-avr-port Excludes the AVR port
654 \labelwidthstring 00.00.0000
666 -disable-ds390-port Excludes the DS390 port
668 \labelwidthstring 00.00.0000
680 -disable-pic-port Excludes the PIC port
682 \labelwidthstring 00.00.0000
694 -disable-xa51-port Excludes the XA51 port
696 \labelwidthstring 00.00.0000
708 -disable-ucsim Disables configuring and building of ucsim
710 \labelwidthstring 00.00.0000
722 -disable-device-lib-build Disables automatically building device libraries
724 \labelwidthstring 00.00.0000
736 -disable-packihx Disables building packihx
738 \labelwidthstring 00.00.0000
750 -enable-libgc Use the Bohem memory allocator.
751 Lower runtime footprint.
754 Furthermore the environment variables CC, CFLAGS, ...
755 the tools and their arguments can be influenced.
756 Please see `configure -
766 -help` and the man/info pages of `configure` for details.
770 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
771 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
772 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
773 At the moment it's not possible to change the default settings (it was
774 simply never required.
778 These configure options are compiled into the binaries, and can only be
779 changed by rerunning 'configure' and recompiling SDCC.
780 The configure options are written in
784 to distinguish them from run time environment variables (see section search
790 \begin_inset Quotes sld
794 \begin_inset Quotes srd
797 are used by the SDCC team to build the official Win32 binaries.
798 The SDCC team uses Mingw32 to build the official Windows binaries, because
805 a gcc compiler and last but not least
808 the binaries can be built by cross compiling on Sourceforge's compile farm.
811 See the examples, how to pass the Win32 settings to 'configure'.
812 The other Win32 builds using Borland, VC or whatever don't use 'configure',
813 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
825 <lyxtabular version="3" rows="8" columns="3">
827 <column alignment="block" valignment="top" leftline="true" width="0in">
828 <column alignment="block" valignment="top" leftline="true" width="0in">
829 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
830 <row topline="true" bottomline="true">
831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1028 <row topline="true">
1029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1056 <row topline="true" bottomline="true">
1057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1093 'configure' also computes relative paths.
1094 This is needed for full relocatability of a binary package and to complete
1095 search paths (see section search paths below):
1101 \begin_inset Tabular
1102 <lyxtabular version="3" rows="4" columns="3">
1104 <column alignment="block" valignment="top" leftline="true" width="0in">
1105 <column alignment="block" valignment="top" leftline="true" width="0in">
1106 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1107 <row topline="true" bottomline="true">
1108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1133 <row topline="true" bottomline="true">
1134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1163 <row bottomline="true">
1164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1191 <row bottomline="true">
1192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1243 \begin_inset Quotes srd
1247 \begin_inset Quotes srd
1261 \begin_inset Quotes srd
1265 \begin_inset Quotes srd
1293 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1302 \begin_inset Quotes srd
1305 i586-mingw32msvc-gcc
1306 \begin_inset Quotes srd
1310 \begin_inset Quotes srd
1313 i586-mingw32msvc-g++
1314 \begin_inset Quotes srd
1322 \begin_inset Quotes srd
1325 i586-mingw32msvc-ranlib
1326 \begin_inset Quotes srd
1334 \begin_inset Quotes srd
1337 i586-mingw32msvc-strip
1338 \begin_inset Quotes srd
1356 \begin_inset Quotes srd
1360 \begin_inset Quotes srd
1378 \begin_inset Quotes srd
1382 \begin_inset Quotes srd
1390 \begin_inset Quotes srd
1394 \begin_inset Quotes srd
1402 \begin_inset Quotes srd
1406 \begin_inset Quotes srd
1414 \begin_inset Quotes srd
1418 \begin_inset Quotes srd
1425 sdccconf_h_dir_separator=
1426 \begin_inset Quotes srd
1438 \begin_inset Quotes srd
1455 -disable-device-lib-build
1483 -host=i586-mingw32msvc -
1493 -build=unknown-unknown-linux-gnu
1497 \begin_inset Quotes sld
1501 \begin_inset Quotes srd
1504 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1513 \begin_inset Quotes srd
1517 \begin_inset Quotes srd
1525 \begin_inset Quotes srd
1529 \begin_inset Quotes srd
1547 \begin_inset Quotes srd
1551 \begin_inset Quotes srd
1569 \begin_inset Quotes srd
1573 \begin_inset Quotes srd
1581 \begin_inset Quotes srd
1585 \begin_inset Quotes srd
1593 \begin_inset Quotes srd
1597 \begin_inset Quotes srd
1605 \begin_inset Quotes srd
1609 \begin_inset Quotes srd
1616 sdccconf_h_dir_separator=
1617 \begin_inset Quotes srd
1629 \begin_inset Quotes srd
1649 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1660 -C' turns on caching, which gives a little bit extra speed.
1661 However if options are changed, it can be necessary to delete the config.cache
1666 \begin_inset LatexCommand \index{Install paths}
1672 \added_space_top medskip \align center
1674 \begin_inset Tabular
1675 <lyxtabular version="3" rows="5" columns="4">
1677 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1678 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1679 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1680 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
1681 <row topline="true" bottomline="true">
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1723 <row topline="true">
1724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 <row topline="true">
1764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1779 $DATADIR/ $INCLUDE_DIR_SUFFIX
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 /usr/local/share/sdcc/include
1790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1803 <row topline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1819 $DATADIR/$LIB_DIR_SUFFIX
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1827 /usr/local/share/sdcc/lib
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1843 <row topline="true" bottomline="true">
1844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1867 /usr/local/share/sdcc/doc
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1892 *compiler, preprocessor, assembler, and linker
1898 is auto-appended by the compiler, e.g.
1899 small, large, z80, ds390 etc
1902 The install paths can still be changed during `make install` with e.g.:
1905 make install prefix=$(HOME)/local/sdcc
1908 Of course this doesn't change the search paths compiled into the binaries.
1912 \begin_inset LatexCommand \index{Search path}
1919 Some search paths or parts of them are determined by configure variables
1924 , see section above).
1925 Further search paths are determined by environment variables during runtime.
1928 The paths searched when running the compiler are as follows (the first catch
1934 Binary files (preprocessor, assembler and linker)
1940 \begin_inset Tabular
1941 <lyxtabular version="3" rows="4" columns="3">
1943 <column alignment="block" valignment="top" leftline="true" width="0in">
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1946 <row topline="true" bottomline="true">
1947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1972 <row topline="true">
1973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2002 <row topline="true">
2003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 Path of argv[0] (if available)
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2028 <row topline="true" bottomline="true">
2029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2070 \begin_inset Tabular
2071 <lyxtabular version="3" rows="6" columns="3">
2073 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2074 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2075 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2076 <row topline="true" bottomline="true">
2077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2102 <row topline="true">
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 <row topline="true">
2159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2184 <row topline="true">
2185 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2222 <row topline="true">
2223 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2304 <row topline="true" bottomline="true">
2305 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2321 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2326 /usr/local/share/sdcc/
2331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2359 -nostdinc disables the last two search paths.
2369 With the exception of
2370 \begin_inset Quotes sld
2384 \begin_inset Quotes srd
2391 is auto-appended by the compiler (e.g.
2392 small, large, z80, ds390 etc.).
2399 \begin_inset Tabular
2400 <lyxtabular version="3" rows="6" columns="3">
2402 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2403 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2404 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2405 <row topline="true" bottomline="true">
2406 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2414 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2431 <row topline="true">
2432 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2487 <row topline="true">
2488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2500 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2527 <row topline="true">
2528 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2539 $LIB_DIR_SUFFIX/<model>
2542 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2556 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2573 <row topline="true">
2574 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2589 $LIB_DIR_SUFFIX/<model>
2592 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2701 <row topline="true" bottomline="true">
2702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2711 $LIB_DIR_SUFFIX/<model>
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2719 /usr/local/share/sdcc/
2726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2744 Don't delete any of the stray spaces in the table above without checking
2745 the HTML output (last line)!
2761 -nostdlib disables the last two search paths.
2765 \begin_inset LatexCommand \index{Building SDCC}
2770 \layout Subsubsection
2772 Building SDCC on Linux
2773 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2782 Download the source package
2784 either from the SDCC CVS repository or from the
2785 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2791 , it will be named something like sdcc
2804 Bring up a command line terminal, such as xterm.
2809 Unpack the file using a command like:
2812 "tar -xzf sdcc.src.tar.gz
2817 , this will create a sub-directory called sdcc with all of the sources.
2820 Change directory into the main SDCC directory, for example type:
2837 This configures the package for compilation on your system.
2853 All of the source packages will compile, this can take a while.
2869 This copies the binary executables, the include files, the libraries and
2870 the documentation to the install directories.
2871 \layout Subsubsection
2873 Building SDCC on OSX 2.x
2876 Follow the instruction for Linux.
2880 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2881 )) fails to compile SDCC.
2882 Fortunately there's also gcc 2.9.x installed, which works fine.
2883 This compiler can be selected by running 'configure' with:
2886 ./configure CC=gcc2 CXX=g++2
2887 \layout Subsubsection
2889 Cross compiling SDCC on Linux for Windows
2892 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2893 See section 'Configure Options'.
2894 \layout Subsubsection
2896 Building SDCC on Windows
2899 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2901 They use Unix-sockets, which are not available on Win32.
2902 \layout Subsubsection
2904 Building SDCC using Cygwin and Mingw32
2907 For building and installing a Cygwin executable follow the instructions
2913 \begin_inset Quotes sld
2917 \begin_inset Quotes srd
2920 Win32-binary can be built, which will not need the Cygwin-DLL.
2921 For the necessary 'configure' options see section 'configure options' or
2922 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2926 In order to install Cygwin on Windows download setup.exe from
2927 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2933 \begin_inset Quotes sld
2936 default text file type
2937 \begin_inset Quotes srd
2941 \begin_inset Quotes sld
2945 \begin_inset Quotes srd
2948 and download/install at least the following packages.
2949 Some packages are selected by default, others will be automatically selected
2950 because of dependencies with the manually selected packages.
2951 Never deselect these packages!
2960 gcc ; version 3.x is fine, no need to use the old 2.9x
2963 binutils ; selected with gcc
2969 rxvt ; a nice console, which makes life much easier under windoze (see below)
2972 man ; not really needed for building SDCC, but you'll miss it sooner or
2976 less ; not really needed for building SDCC, but you'll miss it sooner or
2980 cvs ; only if you use CVS access
2983 If you want to develop something you'll need:
2986 python ; for the regression tests
2989 gdb ; the gnu debugger, together with the nice GUI
2990 \begin_inset Quotes sld
2994 \begin_inset Quotes srd
3000 openssh ; to access the CF or commit changes
3003 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3004 use autoconf-stable!
3007 rxvt is a nice console with history.
3008 Replace in your cygwin.bat the line
3027 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3030 -bg black -fg white -geometry 100x65 -e bash -
3043 Text selected with the mouse is automatically copied to the clipboard, pasting
3044 works with shift-insert.
3048 The other good tip is to make sure you have no //c/-style paths anywhere,
3049 use /cygdrive/c/ instead.
3050 Using // invokes a network lookup which is very slow.
3052 \begin_inset Quotes sld
3056 \begin_inset Quotes srd
3059 is too long, you can change it with e.g.
3065 SDCC sources use the unix line ending LF.
3066 Life is much easier, if you store the source tree on a drive which is mounted
3068 And use an editor which can handle LF-only line endings.
3069 Make sure not to commit files with windows line endings.
3070 The tabulator spacing used in the project is 8.
3071 \layout Subsubsection
3073 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3078 Download the source package
3080 either from the SDCC CVS repository or from the
3081 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3087 , it will be named something like sdcc
3094 SDCC is distributed with all the projects, workspaces, and files you need
3095 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3096 doesn't build under MSVC).
3097 The workspace name is 'sdcc.dsw'.
3098 Please note that as it is now, all the executables are created in a folder
3102 Once built you need to copy the executables from sdcc
3106 bin before running SDCC.
3111 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3112 flex.exe, and gawk.exe.
3113 One good place to get them is
3114 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3122 Download the file UnxUtils
3123 \begin_inset LatexCommand \index{UnxUtils}
3128 Now you have to install the utilities and setup MSVC so it can locate the
3130 Here there are two alternatives (choose one!):
3137 a) Extract UnxUtils.zip to your C:
3139 hard disk PRESERVING the original paths, otherwise bison won't work.
3140 (If you are using WinZip make certain that 'Use folder names' is selected)
3144 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3145 in 'Show directories for:' select 'Executable files', and in the directories
3146 window add a new path: 'C:
3156 (As a side effect, you get a bunch of Unix utilities that could be useful,
3157 such as diff and patch.)
3164 This one avoids extracting a bunch of files you may not use, but requires
3169 a) Create a directory were to put the tools needed, or use a directory already
3177 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3178 to such directory WITHOUT preserving the original paths.
3179 (If you are using WinZip make certain that 'Use folder names' is not selected)
3183 c) Rename bison.exe to '_bison.exe'.
3187 d) Create a batch file 'bison.bat' in 'C:
3191 ' and add these lines:
3211 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3215 Steps 'c' and 'd' are needed because bison requires by default that the
3216 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3217 '/usr/local/share/' I think.
3218 So it is necessary to tell bison where those files are located if they
3219 are not in such directory.
3220 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3224 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3225 in 'Show directories for:' select 'Executable files', and in the directories
3226 window add a new path: 'c:
3229 Note that you can use any other path instead of 'c:
3231 util', even the path where the Visual C++ tools are, probably: 'C:
3235 Microsoft Visual Studio
3240 So you don't have to execute step 'e' :)
3244 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3245 the executables from sdcc
3249 bin, and you can compile using sdcc.
3250 \layout Subsubsection
3252 Building SDCC Using Borland
3255 From the sdcc directory, run the command "make -f Makefile.bcc".
3256 This should regenerate all the .exe files in the bin directory except for
3257 sdcdb.exe (which currently doesn't build under Borland C++).
3260 If you modify any source files and need to rebuild, be aware that the dependenci
3261 es may not be correctly calculated.
3262 The safest option is to delete all .obj files and run the build again.
3263 From a Cygwin BASH prompt, this can easily be done with the command (be
3264 sure you are in the sdcc directory):
3274 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3276 ) -print -exec rm {}
3285 or on Windows NT/2000/XP from the command prompt with the command:
3292 del /s *.obj *.lib *.rul
3295 from the sdcc directory.
3296 \layout Subsubsection
3298 Windows Install Using a Binary Package
3299 \begin_inset LatexCommand \label{sub:Windows-Install}
3306 Download the binary package from
3307 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3311 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3312 This should unpack to a group of sub-directories.
3313 An example directory structure after unpacking the mingw32 package is:
3318 bin for the executables, c:
3326 lib for the include and libraries.
3329 Adjust your environment variable PATH to include the location of the bin
3330 directory or start sdcc using the full path.
3333 Building the Documentation
3336 If the necessary tools are installed it is as easy as changing into the
3337 doc directory and typing
3341 \begin_inset Quotes srd
3345 \begin_inset Quotes srd
3352 If you want to avoid installing the tools you will have some success with
3353 a bootable Knoppix CD
3354 \begin_inset LatexCommand \url{http://www.knopper.net}
3361 Testing the SDCC Compiler
3364 The first thing you should do after installing your SDCC compiler is to
3380 \begin_inset LatexCommand \index{version}
3387 at the prompt, and the program should run and tell you the version.
3388 If it doesn't run, or gives a message about not finding sdcc program, then
3389 you need to check over your installation.
3390 Make sure that the sdcc bin directory is in your executable search path
3391 defined by the PATH environment setting (see the Trouble-shooting section
3393 Make sure that the sdcc program is in the bin folder, if not perhaps something
3394 did not install correctly.
3402 is commonly installed as described in section
3403 \begin_inset Quotes sld
3406 Install and search paths
3407 \begin_inset Quotes srd
3416 Make sure the compiler works on a very simple example.
3417 Type in the following test.c program using your favorite
3443 Compile this using the following command:
3452 If all goes well, the compiler will generate a test.asm and test.rel file.
3453 Congratulations, you've just compiled your first program with SDCC.
3454 We used the -c option to tell SDCC not to link the generated code, just
3455 to keep things simple for this step.
3463 The next step is to try it with the linker.
3473 If all goes well the compiler will link with the libraries and produce
3474 a test.ihx output file.
3479 (no test.ihx, and the linker generates warnings), then the problem is most
3480 likely that sdcc cannot find the
3484 usr/local/share/sdcc/lib directory
3488 (see the Install trouble-shooting section for suggestions).
3496 The final test is to ensure sdcc can use the
3500 header files and libraries.
3501 Edit test.c and change it to the following:
3518 strcpy(str1, "testing");
3525 Compile this by typing
3532 This should generate a test.ihx output file, and it should give no warnings
3533 such as not finding the string.h file.
3534 If it cannot find the string.h file, then the problem is that sdcc cannot
3535 find the /usr/local/share/sdcc/include directory
3539 (see the Install trouble-shooting section for suggestions).
3557 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3561 to find exactly where SDCC is looking for the include and lib files.
3564 Install Trouble-shooting
3565 \begin_inset LatexCommand \index{Install trouble-shooting}
3570 \layout Subsubsection
3572 SDCC does not build correctly.
3575 A thing to try is starting from scratch by unpacking the .tgz source package
3576 again in an empty directory.
3584 ./configure 2>&1 | tee configure.log
3598 make 2>&1 | tee make.log
3605 If anything goes wrong, you can review the log files to locate the problem.
3606 Or a relevant part of this can be attached to an email that could be helpful
3607 when requesting help from the mailing list.
3608 \layout Subsubsection
3611 \begin_inset Quotes sld
3615 \begin_inset Quotes srd
3622 \begin_inset Quotes sld
3626 \begin_inset Quotes srd
3629 command is a script that analyzes your system and performs some configuration
3630 to ensure the source package compiles on your system.
3631 It will take a few minutes to run, and will compile a few tests to determine
3632 what compiler features are installed.
3633 \layout Subsubsection
3636 \begin_inset Quotes sld
3640 \begin_inset Quotes srd
3646 This runs the GNU make tool, which automatically compiles all the source
3647 packages into the final installed binary executables.
3648 \layout Subsubsection
3651 \begin_inset Quotes sld
3655 \begin_inset Quotes erd
3661 This will install the compiler, other executables libraries and include
3662 files into the appropriate directories.
3664 \begin_inset Quotes sld
3667 Install and Search PATHS
3668 \begin_inset Quotes srd
3673 On most systems you will need super-user privileges to do this.
3679 SDCC is not just a compiler, but a collection of tools by various developers.
3680 These include linkers, assemblers, simulators and other components.
3681 Here is a summary of some of the components.
3682 Note that the included simulator and assembler have separate documentation
3683 which you can find in the source package in their respective directories.
3684 As SDCC grows to include support for other processors, other packages from
3685 various developers are included and may have their own sets of documentation.
3689 You might want to look at the files which are installed in <installdir>.
3690 At the time of this writing, we find the following programs for gcc-builds:
3694 In <installdir>/bin:
3697 sdcc - The compiler.
3700 sdcpp - The C preprocessor.
3703 asx8051 - The assembler for 8051 type processors.
3710 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3713 aslink -The linker for 8051 type processors.
3720 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3723 s51 - The ucSim 8051 simulator.
3726 sdcdb - The source debugger.
3729 packihx - A tool to pack (compress) Intel hex files.
3732 In <installdir>/share/sdcc/include
3738 In <installdir>/share/sdcc/lib
3741 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3745 In <installdir>/share/sdcc/doc
3751 As development for other processors proceeds, this list will expand to include
3752 executables to support processors like AVR, PIC, etc.
3753 \layout Subsubsection
3758 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3759 the assembler and linkage editor.
3760 \layout Subsubsection
3763 \begin_inset LatexCommand \index{sdcpp}
3767 - The C-Preprocessor
3770 The preprocessor is a modified version of the GNU preprocessor.
3771 The C preprocessor is used to pull in #include sources, process #ifdef
3772 statements, #defines and so on.
3773 \layout Subsubsection
3775 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3779 This is retargettable assembler & linkage editor, it was developed by Alan
3781 John Hartman created the version for 8051, and I (Sandeep) have made some
3782 enhancements and bug fixes for it to work properly with SDCC.
3783 \layout Subsubsection
3786 \begin_inset LatexCommand \index{s51}
3793 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3794 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3799 The simulator is built as part of the build process.
3800 For more information visit Daniel's web site at:
3801 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3806 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3808 \layout Subsubsection
3811 \begin_inset LatexCommand \index{sdcdb}
3815 - Source Level Debugger
3818 Sdcdb is the companion source level debugger.
3819 The current version of the debugger uses Daniel's Simulator S51
3820 \begin_inset LatexCommand \index{s51}
3824 , but can be easily changed to use other simulators.
3831 \layout Subsubsection
3833 Single Source File Projects
3836 For single source file 8051 projects the process is very simple.
3837 Compile your programs with the following command
3840 "sdcc sourcefile.c".
3844 This will compile, assemble and link your source file.
3845 Output files are as follows
3849 \begin_inset LatexCommand \index{.asm}
3854 \begin_inset LatexCommand \index{Assembler source}
3858 file created by the compiler
3862 \begin_inset LatexCommand \index{.lst}
3867 \begin_inset LatexCommand \index{Assembler listing}
3871 file created by the Assembler
3875 \begin_inset LatexCommand \index{.rst}
3880 \begin_inset LatexCommand \index{Assembler listing}
3884 file updated with linkedit information, created by linkage editor
3888 \begin_inset LatexCommand \index{.sym}
3893 \begin_inset LatexCommand \index{Symbol listing}
3897 for the sourcefile, created by the assembler
3901 \begin_inset LatexCommand \index{.rel}
3906 \begin_inset LatexCommand \index{Object file}
3910 created by the assembler, input to Linkage editor
3914 \begin_inset LatexCommand \index{.map}
3919 \begin_inset LatexCommand \index{Memory map}
3923 for the load module, created by the Linker
3927 \begin_inset LatexCommand \index{.mem}
3931 - A file with a summary of the memory usage
3935 \begin_inset LatexCommand \index{.ihx}
3939 - The load module in Intel hex format
3940 \begin_inset LatexCommand \index{Intel hex format}
3944 (you can select the Motorola S19 format
3945 \begin_inset LatexCommand \index{Motorola S19 format}
3960 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3965 If you need another format you might want to use
3972 \begin_inset LatexCommand \index{objdump}
3983 \begin_inset LatexCommand \index{srecord}
3991 \begin_inset LatexCommand \index{.adb}
3995 - An intermediate file containing debug information needed to create the
4007 \begin_inset LatexCommand \index{-\/-debug}
4015 \begin_inset LatexCommand \index{.cdb}
4019 - An optional file (with -
4029 -debug) containing debug information
4034 \begin_inset LatexCommand \index{. (no extension)}
4039 \begin_inset LatexCommand \index{AOMF51}
4043 file containing debug information (with -
4054 This format is commonly used by third party tools (debuggers
4055 \begin_inset LatexCommand \index{Debugger}
4059 , simulators, emulators)
4063 \begin_inset LatexCommand \index{.dump*}
4067 - Dump file to debug the compiler it self (with -
4077 -dumpall) (see section
4078 \begin_inset Quotes sld
4081 Anatomy of the compiler
4082 \begin_inset Quotes srd
4086 \layout Subsubsection
4088 Projects with Multiple Source Files
4091 SDCC can compile only ONE file at a time.
4092 Let us for example assume that you have a project containing the following
4097 foo1.c (contains some functions)
4099 foo2.c (contains some more functions)
4101 foomain.c (contains more functions and the function main)
4109 The first two files will need to be compiled separately with the commands:
4141 Then compile the source file containing the
4146 \begin_inset LatexCommand \index{Linker}
4150 the files together with the following command:
4158 foomain.c\SpecialChar ~
4159 foo1.rel\SpecialChar ~
4164 \begin_inset LatexCommand \index{.rel}
4176 can be separately compiled as well:
4187 sdcc foomain.rel foo1.rel foo2.rel
4194 The file containing the
4209 file specified in the command line, since the linkage editor processes
4210 file in the order they are presented to it.
4211 The linker is invoked from sdcc using a script file with extension .lnk
4212 \begin_inset LatexCommand \index{.lnk}
4217 You can view this file to troubleshoot linking problems such as those arising
4218 from missing libraries.
4219 \layout Subsubsection
4221 Projects with Additional Libraries
4222 \begin_inset LatexCommand \index{Libraries}
4229 Some reusable routines may be compiled into a library, see the documentation
4230 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4234 \begin_inset LatexCommand \index{.lib}
4241 Libraries created in this manner can be included in the command line.
4242 Make sure you include the -L <library-path> option to tell the linker where
4243 to look for these files if they are not in the current directory.
4244 Here is an example, assuming you have the source file
4256 (if that is not the same as your current project):
4263 sdcc foomain.c foolib.lib -L mylib
4274 must be an absolute path name.
4278 The most efficient way to use libraries is to keep separate modules in separate
4280 The lib file now should name all the modules.rel
4281 \begin_inset LatexCommand \index{rel}
4286 For an example see the standard library file
4290 in the directory <installdir>/share/lib/small.
4293 Command Line Options
4294 \begin_inset LatexCommand \index{Command Line Options}
4299 \layout Subsubsection
4301 Processor Selection Options
4302 \begin_inset LatexCommand \index{Options processor selection}
4307 \begin_inset LatexCommand \index{Processor selection options}
4313 \labelwidthstring 00.00.0000
4318 \begin_inset LatexCommand \index{-mmcs51}
4324 Generate code for the Intel MCS51
4325 \begin_inset LatexCommand \index{MCS51}
4329 family of processors.
4330 This is the default processor target.
4332 \labelwidthstring 00.00.0000
4337 \begin_inset LatexCommand \index{-mds390}
4343 Generate code for the Dallas DS80C390
4344 \begin_inset LatexCommand \index{DS80C390}
4350 \labelwidthstring 00.00.0000
4355 \begin_inset LatexCommand \index{-mds400}
4361 Generate code for the Dallas DS80C400
4362 \begin_inset LatexCommand \index{DS80C400}
4368 \labelwidthstring 00.00.0000
4373 \begin_inset LatexCommand \index{-mz80}
4379 Generate code for the Zilog Z80
4380 \begin_inset LatexCommand \index{Z80}
4384 family of processors.
4386 \labelwidthstring 00.00.0000
4391 \begin_inset LatexCommand \index{-mgbz80}
4397 Generate code for the GameBoy Z80
4398 \begin_inset LatexCommand \index{GameBoy Z80}
4404 \labelwidthstring 00.00.0000
4409 \begin_inset LatexCommand \index{-mavr}
4415 Generate code for the Atmel AVR
4416 \begin_inset LatexCommand \index{AVR}
4420 processor (In development, not complete).
4421 AVR users should probably have a look at avr-gcc
4422 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4429 I think it is fair to direct users there for now.
4430 Open source is also about avoiding unnecessary work .
4431 But I didn't find the 'official' link.
4433 \labelwidthstring 00.00.0000
4438 \begin_inset LatexCommand \index{-mpic14}
4444 Generate code for the Microchip PIC 14
4445 \begin_inset LatexCommand \index{PIC14}
4449 -bit processors (p16f84 and variants).
4452 p16f627 p16f628 p16f84 p16f873 p16f877?
4454 \labelwidthstring 00.00.0000
4459 \begin_inset LatexCommand \index{-mpic16}
4465 Generate code for the Microchip PIC 16
4466 \begin_inset LatexCommand \index{PIC16}
4470 -bit processors (p18f452 and variants).
4472 \labelwidthstring 00.00.0000
4478 Generate code for the Toshiba TLCS-900H
4479 \begin_inset LatexCommand \index{TLCS-900H}
4483 processor (In development, not complete).
4485 \labelwidthstring 00.00.0000
4490 \begin_inset LatexCommand \index{-mxa51}
4496 Generate code for the Phillips XA51
4497 \begin_inset LatexCommand \index{XA51}
4501 processor (In development, not complete).
4502 \layout Subsubsection
4504 Preprocessor Options
4505 \begin_inset LatexCommand \index{Options preprocessor}
4510 \begin_inset LatexCommand \index{Preprocessor options}
4516 \labelwidthstring 00.00.0000
4521 \begin_inset LatexCommand \index{-I<path>}
4527 The additional location where the pre processor will look for <..h> or
4528 \begin_inset Quotes eld
4532 \begin_inset Quotes erd
4537 \labelwidthstring 00.00.0000
4542 \begin_inset LatexCommand \index{-D<macro[=value]>}
4548 Command line definition of macros.
4549 Passed to the preprocessor.
4551 \labelwidthstring 00.00.0000
4556 \begin_inset LatexCommand \index{-M}
4562 Tell the preprocessor to output a rule suitable for make describing the
4563 dependencies of each object file.
4564 For each source file, the preprocessor outputs one make-rule whose target
4565 is the object file name for that source file and whose dependencies are
4566 all the files `#include'd in it.
4567 This rule may be a single line or may be continued with `
4569 '-newline if it is long.
4570 The list of rules is printed on standard output instead of the preprocessed
4573 \begin_inset LatexCommand \index{-E}
4579 \labelwidthstring 00.00.0000
4584 \begin_inset LatexCommand \index{-C}
4590 Tell the preprocessor not to discard comments.
4591 Used with the `-E' option.
4593 \labelwidthstring 00.00.0000
4598 \begin_inset LatexCommand \index{-MM}
4609 Like `-M' but the output mentions only the user header files included with
4611 \begin_inset Quotes eld
4615 System header files included with `#include <file>' are omitted.
4617 \labelwidthstring 00.00.0000
4622 \begin_inset LatexCommand \index{-Aquestion(answer)}
4628 Assert the answer answer for question, in case it is tested with a preprocessor
4629 conditional such as `#if #question(answer)'.
4630 `-A-' disables the standard assertions that normally describe the target
4633 \labelwidthstring 00.00.0000
4638 \begin_inset LatexCommand \index{-Umacro}
4644 Undefine macro macro.
4645 `-U' options are evaluated after all `-D' options, but before any `-include'
4646 and `-imacros' options.
4648 \labelwidthstring 00.00.0000
4653 \begin_inset LatexCommand \index{-dM}
4659 Tell the preprocessor to output only a list of the macro definitions that
4660 are in effect at the end of preprocessing.
4661 Used with the `-E' option.
4663 \labelwidthstring 00.00.0000
4668 \begin_inset LatexCommand \index{-dD}
4674 Tell the preprocessor to pass all macro definitions into the output, in
4675 their proper sequence in the rest of the output.
4677 \labelwidthstring 00.00.0000
4682 \begin_inset LatexCommand \index{-dN}
4693 Like `-dD' except that the macro arguments and contents are omitted.
4694 Only `#define name' is included in the output.
4695 \layout Subsubsection
4698 \begin_inset LatexCommand \index{Options linker}
4703 \begin_inset LatexCommand \index{Linker options}
4709 \labelwidthstring 00.00.0000
4729 \begin_inset LatexCommand \index{-\/-lib-path}
4734 \begin_inset LatexCommand \index{-L -\/-lib-path}
4743 <absolute path to additional libraries> This option is passed to the linkage
4744 editor's additional libraries
4745 \begin_inset LatexCommand \index{Libraries}
4750 The path name must be absolute.
4751 Additional library files may be specified in the command line.
4752 See section Compiling programs for more details.
4754 \labelwidthstring 00.00.0000
4771 \begin_inset LatexCommand \index{-\/-xram-loc}
4775 <Value> The start location of the external ram
4776 \begin_inset LatexCommand \index{xdata}
4780 , default value is 0.
4781 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4791 -xram-loc 0x8000 or -
4803 \labelwidthstring 00.00.0000
4820 \begin_inset LatexCommand \index{-\/-code-loc}
4824 <Value> The start location of the code
4825 \begin_inset LatexCommand \index{code}
4829 segment, default value 0.
4830 Note when this option is used the interrupt vector table is also relocated
4831 to the given address.
4832 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4842 -code-loc 0x8000 or -
4854 \labelwidthstring 00.00.0000
4871 \begin_inset LatexCommand \index{-\/-stack-loc}
4875 <Value> By default the stack
4876 \begin_inset LatexCommand \index{stack}
4880 is placed after the data segment.
4881 Using this option the stack can be placed anywhere in the internal memory
4883 The value entered can be in Hexadecimal or Decimal format, e.g.
4894 -stack-loc 0x20 or -
4905 Since the sp register is incremented before a push or call, the initial
4906 sp will be set to one byte prior the provided value.
4907 The provided value should not overlap any other memory areas such as used
4908 register banks or the data segment and with enough space for the current
4911 \labelwidthstring 00.00.0000
4928 \begin_inset LatexCommand \index{-\/-data-loc}
4932 <Value> The start location of the internal ram data
4933 \begin_inset LatexCommand \index{data}
4938 The value entered can be in Hexadecimal or Decimal format, eg.
4960 (By default, the start location of the internal ram data segment is set
4961 as low as possible in memory, taking into account the used register banks
4962 and the bit segment at address 0x20.
4963 For example if register banks 0 and 1 are used without bit variables, the
4964 data segment will be set, if -
4974 -data-loc is not used, to location 0x10.)
4976 \labelwidthstring 00.00.0000
4993 \begin_inset LatexCommand \index{-\/-idata-loc}
4997 <Value> The start location of the indirectly addressable internal ram
4998 \begin_inset LatexCommand \index{idata}
5002 , default value is 0x80.
5003 The value entered can be in Hexadecimal or Decimal format, eg.
5014 -idata-loc 0x88 or -
5026 \labelwidthstring 00.00.0000
5041 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5050 The linker output (final object code) is in Intel Hex format.
5051 \begin_inset LatexCommand \index{Intel hex format}
5055 (This is the default option).
5057 \labelwidthstring 00.00.0000
5072 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5081 The linker output (final object code) is in Motorola S19 format
5082 \begin_inset LatexCommand \index{Motorola S19 format}
5087 \layout Subsubsection
5090 \begin_inset LatexCommand \index{Options MCS51}
5095 \begin_inset LatexCommand \index{MCS51 options}
5101 \labelwidthstring 00.00.0000
5116 \begin_inset LatexCommand \index{-\/-model-small}
5127 Generate code for Small Model programs see section Memory Models for more
5129 This is the default model.
5131 \labelwidthstring 00.00.0000
5146 \begin_inset LatexCommand \index{-\/-model-large}
5152 Generate code for Large model programs see section Memory Models for more
5154 If this option is used all source files in the project should be compiled
5157 \labelwidthstring 00.00.0000
5172 \begin_inset LatexCommand \index{-\/-xstack}
5178 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5179 variables and passing parameters.
5180 See section on external stack for more details.
5182 \labelwidthstring 00.00.0000
5199 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5203 Causes the linker to check if the internal ram usage is within limits of
5206 \labelwidthstring 00.00.0000
5223 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5227 Causes the linker to check if the external ram usage is within limits of
5230 \labelwidthstring 00.00.0000
5247 \begin_inset LatexCommand \index{-\/-data-loc}
5251 Causes the linker to check if the code memory usage is within limits of
5253 \layout Subsubsection
5256 \begin_inset LatexCommand \index{Options DS390}
5261 \begin_inset LatexCommand \index{DS390 options}
5267 \labelwidthstring 00.00.0000
5284 \begin_inset LatexCommand \index{-\/-model-flat24}
5294 Generate 24-bit flat mode code.
5295 This is the one and only that the ds390 code generator supports right now
5296 and is default when using
5301 See section Memory Models for more details.
5303 \labelwidthstring 00.00.0000
5320 \begin_inset LatexCommand \index{-\/-stack-10bit}
5324 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5325 This is the one and only that the ds390 code generator supports right now
5326 and is default when using
5331 In this mode, the stack is located in the lower 1K of the internal RAM,
5332 which is mapped to 0x400000.
5333 Note that the support is incomplete, since it still uses a single byte
5334 as the stack pointer.
5335 This means that only the lower 256 bytes of the potential 1K stack space
5336 will actually be used.
5337 However, this does allow you to reclaim the precious 256 bytes of low RAM
5338 for use for the DATA and IDATA segments.
5339 The compiler will not generate any code to put the processor into 10 bit
5341 It is important to ensure that the processor is in this mode before calling
5342 any re-entrant functions compiled with this option.
5343 In principle, this should work with the
5356 \begin_inset LatexCommand \index{-\/-stack-auto}
5362 option, but that has not been tested.
5363 It is incompatible with the
5376 \begin_inset LatexCommand \index{-\/-xstack}
5383 It also only makes sense if the processor is in 24 bit contiguous addressing
5396 -model-flat24 option
5399 \layout Subsubsection
5402 \begin_inset LatexCommand \index{Options Z80}
5407 \begin_inset LatexCommand \index{Z80 options}
5413 \labelwidthstring 00.00.0000
5430 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5440 Force a called function to always save BC.
5442 \labelwidthstring 00.00.0000
5459 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5463 When linking, skip the standard crt0.o object file.
5464 You must provide your own crt0.o for your system when linking.
5466 \layout Subsubsection
5468 Optimization Options
5469 \begin_inset LatexCommand \index{Options optimization}
5474 \begin_inset LatexCommand \index{Optimization options}
5480 \labelwidthstring 00.00.0000
5495 \begin_inset LatexCommand \index{-\/-nogcse}
5501 Will not do global subexpression elimination, this option may be used when
5502 the compiler creates undesirably large stack/data spaces to store compiler
5504 A warning message will be generated when this happens and the compiler
5505 will indicate the number of extra bytes it allocated.
5506 It recommended that this option NOT be used, #pragma\SpecialChar ~
5508 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5512 can be used to turn off global subexpression elimination
5513 \begin_inset LatexCommand \index{Subexpression elimination}
5517 for a given function only.
5519 \labelwidthstring 00.00.0000
5534 \begin_inset LatexCommand \index{-\/-noinvariant}
5540 Will not do loop invariant optimizations, this may be turned off for reasons
5541 explained for the previous option.
5542 For more details of loop optimizations performed see section Loop Invariants.It
5543 recommended that this option NOT be used, #pragma\SpecialChar ~
5545 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5549 can be used to turn off invariant optimizations for a given function only.
5551 \labelwidthstring 00.00.0000
5566 \begin_inset LatexCommand \index{-\/-noinduction}
5572 Will not do loop induction optimizations, see section strength reduction
5573 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5576 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5580 can be used to turn off induction optimizations for a given function only.
5582 \labelwidthstring 00.00.0000
5597 \begin_inset LatexCommand \index{-\/-nojtbound}
5608 Will not generate boundary condition check when switch statements
5609 \begin_inset LatexCommand \index{switch statement}
5613 are implemented using jump-tables.
5614 See section Switch Statements for more details.
5615 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5617 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5621 can be used to turn off boundary checking for jump tables for a given function
5624 \labelwidthstring 00.00.0000
5639 \begin_inset LatexCommand \index{-\/-noloopreverse}
5648 Will not do loop reversal
5649 \begin_inset LatexCommand \index{Loop reversing}
5655 \labelwidthstring 00.00.0000
5672 \begin_inset LatexCommand \index{-\/-nolabelopt }
5676 Will not optimize labels (makes the dumpfiles more readable).
5678 \labelwidthstring 00.00.0000
5693 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5699 Will not memcpy initialized data from code space into xdata space.
5700 This saves a few bytes in code space if you don't have initialized data.
5701 \layout Subsubsection
5704 \begin_inset LatexCommand \index{Options other}
5710 \labelwidthstring 00.00.0000
5726 \begin_inset LatexCommand \index{-\/-compile-only}
5731 \begin_inset LatexCommand \index{-c -\/-compile-only}
5737 will compile and assemble the source, but will not call the linkage editor.
5739 \labelwidthstring 00.00.0000
5758 \begin_inset LatexCommand \index{-\/-c1mode}
5764 reads the preprocessed source from standard input and compiles it.
5765 The file name for the assembler output must be specified using the -o option.
5767 \labelwidthstring 00.00.0000
5772 \begin_inset LatexCommand \index{-E}
5778 Run only the C preprocessor.
5779 Preprocess all the C source files specified and output the results to standard
5782 \labelwidthstring 00.00.0000
5788 \begin_inset LatexCommand \index{-o <path/file>}
5794 The output path resp.
5795 file where everything will be placed.
5796 If the parameter is a path, it must have a trailing slash (or backslash
5797 for the Windows binaries) to be recognized as a path.
5800 \labelwidthstring 00.00.0000
5815 \begin_inset LatexCommand \index{-\/-stack-auto}
5826 All functions in the source file will be compiled as
5831 \begin_inset LatexCommand \index{reentrant}
5836 the parameters and local variables will be allocated on the stack
5837 \begin_inset LatexCommand \index{stack}
5842 see section Parameters and Local Variables for more details.
5843 If this option is used all source files in the project should be compiled
5847 \labelwidthstring 00.00.0000
5862 \begin_inset LatexCommand \index{-\/-callee-saves}
5866 function1[,function2][,function3]....
5869 The compiler by default uses a caller saves convention for register saving
5870 across function calls, however this can cause unnecessary register pushing
5871 & popping when calling small functions from larger functions.
5872 This option can be used to switch the register saving convention for the
5873 function names specified.
5874 The compiler will not save registers when calling these functions, no extra
5875 code will be generated at the entry & exit (function prologue
5878 \begin_inset LatexCommand \index{function prologue}
5887 \begin_inset LatexCommand \index{function epilogue}
5893 ) for these functions to save & restore the registers used by these functions,
5894 this can SUBSTANTIALLY reduce code & improve run time performance of the
5896 In the future the compiler (with inter procedural analysis) will be able
5897 to determine the appropriate scheme to use for each function call.
5898 DO NOT use this option for built-in functions such as _mulint..., if this
5899 option is used for a library function the appropriate library function
5900 needs to be recompiled with the same option.
5901 If the project consists of multiple source files then all the source file
5902 should be compiled with the same -
5912 -callee-saves option string.
5913 Also see #pragma\SpecialChar ~
5915 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5921 \labelwidthstring 00.00.0000
5936 \begin_inset LatexCommand \index{-\/-debug}
5945 When this option is used the compiler will generate debug information, that
5946 can be used with the SDCDB.
5947 The debug information is collected in a file with .cdb extension.
5948 For more information see documentation for SDCDB.
5950 \labelwidthstring 00.00.0000
5955 \begin_inset LatexCommand \index{-S}
5966 Stop after the stage of compilation proper; do not assemble.
5967 The output is an assembler code file for the input file specified.
5969 \labelwidthstring 00.00.0000
5973 -Wa_asmOption[,asmOption]
5976 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5981 Pass the asmOption to the assembler.
5983 \labelwidthstring 00.00.0000
5987 -Wl_linkOption[,linkOption]
5990 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5995 Pass the linkOption to the linker.
5997 \labelwidthstring 00.00.0000
6012 \begin_inset LatexCommand \index{-\/-int-long-reent}
6018 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6019 Note by default these libraries are compiled as non-reentrant.
6020 See section Installation for more details.
6022 \labelwidthstring 00.00.0000
6037 \begin_inset LatexCommand \index{-\/-cyclomatic}
6046 This option will cause the compiler to generate an information message for
6047 each function in the source file.
6048 The message contains some
6052 information about the function.
6053 The number of edges and nodes the compiler detected in the control flow
6054 graph of the function, and most importantly the
6056 cyclomatic complexity
6057 \begin_inset LatexCommand \index{Cyclomatic complexity}
6063 see section on Cyclomatic Complexity for more details.
6065 \labelwidthstring 00.00.0000
6080 \begin_inset LatexCommand \index{-\/-float-reent}
6089 Floating point library is compiled as reentrant
6090 \begin_inset LatexCommand \index{reentrant}
6095 See section Installation for more details.
6097 \labelwidthstring 00.00.0000
6112 \begin_inset LatexCommand \index{-\/-nooverlay}
6118 The compiler will not overlay parameters and local variables of any function,
6119 see section Parameters and local variables for more details.
6121 \labelwidthstring 00.00.0000
6136 \begin_inset LatexCommand \index{-\/-main-return}
6142 This option can be used when the code generated is called by a monitor
6144 The compiler will generate a 'ret' upon return from the 'main'
6145 \begin_inset LatexCommand \index{main return}
6150 The default option is to lock up i.e.
6157 \labelwidthstring 00.00.0000
6174 \begin_inset LatexCommand \index{-\/-peep-file}
6178 <filename> This option can be used to use additional rules to be used by
6179 the peep hole optimizer.
6180 See section Peep Hole optimizations for details on how to write these rules.
6182 \labelwidthstring 00.00.0000
6197 \begin_inset LatexCommand \index{-\/-no-peep}
6203 Disable peep-hole optimization.
6205 \labelwidthstring 00.00.0000
6220 \begin_inset LatexCommand \index{-\/-peep-asm}
6226 Pass the inline assembler code through the peep hole optimizer.
6227 This can cause unexpected changes to inline assembler code, please go through
6228 the peephole optimizer
6229 \begin_inset LatexCommand \index{Peephole optimizer}
6233 rules defined in the source file tree '<target>/peeph.def' before using
6236 \labelwidthstring 00.00.0000
6251 \begin_inset LatexCommand \index{-\/-nostdincl}
6257 This will prevent the compiler from passing on the default include path
6258 to the preprocessor.
6260 \labelwidthstring 00.00.0000
6275 \begin_inset LatexCommand \index{-\/-nostdlib}
6281 This will prevent the compiler from passing on the default library
6282 \begin_inset LatexCommand \index{Libraries}
6288 \labelwidthstring 00.00.0000
6303 \begin_inset LatexCommand \index{-\/-verbose}
6309 Shows the various actions the compiler is performing.
6311 \labelwidthstring 00.00.0000
6316 \begin_inset LatexCommand \index{-V}
6322 Shows the actual commands the compiler is executing.
6324 \labelwidthstring 00.00.0000
6339 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6345 Hides your ugly and inefficient c-code from the asm file, so you can always
6346 blame the compiler :).
6348 \labelwidthstring 00.00.0000
6363 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6369 Include i-codes in the asm file.
6370 Sounds like noise but is most helpful for debugging the compiler itself.
6372 \labelwidthstring 00.00.0000
6387 \begin_inset LatexCommand \index{-\/-less-pedantic}
6393 Disable some of the more pedantic warnings (jwk burps: please be more specific
6396 \labelwidthstring 00.00.0000
6411 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6417 Display the directories in the compiler's search path
6419 \labelwidthstring 00.00.0000
6434 \begin_inset LatexCommand \index{-\/-vc}
6440 Display errors and warnings using MSVC style, so you can use SDCC with
6443 \labelwidthstring 00.00.0000
6458 \begin_inset LatexCommand \index{-\/-use-stdout}
6464 Send errors and warnings to stdout instead of stderr.
6465 \layout Subsubsection
6467 Intermediate Dump Options
6468 \begin_inset LatexCommand \index{Options intermediate dump}
6473 \begin_inset LatexCommand \index{Intermediate dump options}
6480 The following options are provided for the purpose of retargetting and debugging
6482 These provided a means to dump the intermediate code (iCode
6483 \begin_inset LatexCommand \index{iCode}
6487 ) generated by the compiler in human readable form at various stages of
6488 the compilation process.
6491 \labelwidthstring 00.00.0000
6506 \begin_inset LatexCommand \index{-\/-dumpraw}
6512 This option will cause the compiler to dump the intermediate code into
6515 <source filename>.dumpraw
6517 just after the intermediate code has been generated for a function, i.e.
6518 before any optimizations are done.
6520 \begin_inset LatexCommand \index{Basic blocks}
6524 at this stage ordered in the depth first number, so they may not be in
6525 sequence of execution.
6527 \labelwidthstring 00.00.0000
6542 \begin_inset LatexCommand \index{-\/-dumpgcse}
6548 Will create a dump of iCode's, after global subexpression elimination
6549 \begin_inset LatexCommand \index{Global subexpression elimination}
6555 <source filename>.dumpgcse.
6557 \labelwidthstring 00.00.0000
6572 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6578 Will create a dump of iCode's, after deadcode elimination
6579 \begin_inset LatexCommand \index{Dead-code elimination}
6585 <source filename>.dumpdeadcode.
6587 \labelwidthstring 00.00.0000
6602 \begin_inset LatexCommand \index{-\/-dumploop}
6611 Will create a dump of iCode's, after loop optimizations
6612 \begin_inset LatexCommand \index{Loop optimization}
6618 <source filename>.dumploop.
6620 \labelwidthstring 00.00.0000
6635 \begin_inset LatexCommand \index{-\/-dumprange}
6644 Will create a dump of iCode's, after live range analysis
6645 \begin_inset LatexCommand \index{Live range analysis}
6651 <source filename>.dumprange.
6653 \labelwidthstring 00.00.0000
6668 \begin_inset LatexCommand \index{-\/-dumlrange}
6674 Will dump the life ranges
6675 \begin_inset LatexCommand \index{Live range analysis}
6681 \labelwidthstring 00.00.0000
6696 \begin_inset LatexCommand \index{-\/-dumpregassign}
6705 Will create a dump of iCode's, after register assignment
6706 \begin_inset LatexCommand \index{Register assignment}
6712 <source filename>.dumprassgn.
6714 \labelwidthstring 00.00.0000
6729 \begin_inset LatexCommand \index{-\/-dumplrange}
6735 Will create a dump of the live ranges of iTemp's
6737 \labelwidthstring 00.00.0000
6752 \begin_inset LatexCommand \index{-\/-dumpall}
6763 Will cause all the above mentioned dumps to be created.
6764 \layout Subsubsection
6766 Redirecting output on Windows Shells
6769 By default SDCC writes it's error messages to
6770 \begin_inset Quotes sld
6774 \begin_inset Quotes srd
6778 To force all messages to
6779 \begin_inset Quotes sld
6783 \begin_inset Quotes srd
6807 \begin_inset LatexCommand \index{-\/-use-stdout}
6812 Aditionaly, if you happen to have visual studio installed in your windows
6813 machine, you can use it to compile your sources using a custom build and
6829 \begin_inset LatexCommand \index{-\/-vc}
6834 Something like this should work:
6878 -model-large -c $(InputPath)
6881 Environment variables
6882 \begin_inset LatexCommand \index{Environment variables}
6889 SDCC recognizes the following environment variables:
6891 \labelwidthstring 00.00.0000
6896 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6902 SDCC installs a signal handler
6903 \begin_inset LatexCommand \index{signal handler}
6907 to be able to delete temporary files after an user break (^C) or an exception.
6908 If this environment variable is set, SDCC won't install the signal handler
6909 in order to be able to debug SDCC.
6911 \labelwidthstring 00.00.0000
6918 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
6924 Path, where temporary files will be created.
6925 The order of the variables is the search order.
6926 In a standard *nix environment these variables are not set, and there's
6927 no need to set them.
6928 On Windows it's recommended to set one of them.
6930 \labelwidthstring 00.00.0000
6935 \begin_inset LatexCommand \index{SDCC\_HOME}
6942 \begin_inset Quotes sld
6945 2.3 Install and search paths
6946 \begin_inset Quotes srd
6951 \labelwidthstring 00.00.0000
6956 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6963 \begin_inset Quotes sld
6966 2.3 Install and search paths
6967 \begin_inset Quotes srd
6972 \labelwidthstring 00.00.0000
6977 \begin_inset LatexCommand \index{SDCC\_LIB}
6984 \begin_inset Quotes sld
6987 2.3 Install and search paths
6988 \begin_inset Quotes srd
6994 There are some more environment variables recognized by SDCC, but these
6995 are solely used for debugging purposes.
6996 They can change or disappear very quickly, and will never be documented.
6999 MCS51/DS390 Storage Class
7000 \begin_inset LatexCommand \index{Storage class}
7007 In addition to the ANSI storage classes SDCC allows the following MCS51
7008 specific storage classes.
7009 \layout Subsubsection
7012 \begin_inset LatexCommand \index{data}
7023 storage class for Small Memory model.
7024 Variables declared with this storage class will be allocated in the directly
7025 addressable portion of the internal RAM of a 8051, e.g.:
7030 data unsigned char test_data;
7033 Writing 0x01 to this variable generates the assembly code:
7038 75*00 01\SpecialChar ~
7044 \layout Subsubsection
7047 \begin_inset LatexCommand \index{xdata}
7054 Variables declared with this storage class will be placed in the external
7060 storage class for Large Memory model, e.g.:
7065 xdata unsigned char test_xdata;
7068 Writing 0x01 to this variable generates the assembly code:
7073 90s00r00\SpecialChar ~
7102 \layout Subsubsection
7105 \begin_inset LatexCommand \index{idata}
7112 Variables declared with this storage class will be allocated into the indirectly
7113 addressable portion of the internal ram of a 8051, e.g.:
7118 idata unsigned char test_idata;
7121 Writing 0x01 to this variable generates the assembly code:
7148 \layout Subsubsection
7151 \begin_inset LatexCommand \index{pdata}
7158 Paged xdata access is currently not as straightforward as using the other
7159 addressing modes of a 8051.
7160 The following example writes 0x01 to the address pointed to.
7161 Please note, pdata access physically accesses xdata memory.
7162 The high byte of the address is determined by port P2 (or in case of some
7163 8051 variants by a separate Special Function Register).
7168 pdata unsigned char *test_pdata_ptr;
7180 test_pdata_ptr = (pdata *)0xfe;
7186 *test_pdata_ptr = 1;
7191 Generates the assembly code:
7196 75*01 FE\SpecialChar ~
7200 _test_pdata_ptr,#0xFE
7232 Be extremely carefull if you use pdata together with the -
7243 \begin_inset LatexCommand \index{-\/-xstack}
7248 \layout Subsubsection
7251 \begin_inset LatexCommand \index{code}
7258 'Variables' declared with this storage class will be placed in the code
7264 code unsigned char test_code;
7267 Read access to this variable generates the assembly code:
7272 90s00r6F\SpecialChar ~
7275 mov dptr,#_test_code
7298 \layout Subsubsection
7301 \begin_inset LatexCommand \index{bit}
7308 This is a data-type and a storage class specifier.
7309 When a variable is declared as a bit, it is allocated into the bit addressable
7310 memory of 8051, e.g.:
7318 Writing 1 to this variable generates the assembly code:
7332 \layout Subsubsection
7335 \begin_inset LatexCommand \index{sfr}
7340 \begin_inset LatexCommand \index{sbit}
7347 Like the bit keyword,
7351 signifies both a data-type and storage class, they are used to describe
7352 the special function registers and special bit variables of a 8051, eg:
7358 \begin_inset LatexCommand \index{at}
7362 0x80 P0;\SpecialChar ~
7363 /* special function register P0 at location 0x80 */
7365 sbit at 0xd7 CY; /* CY (Carry Flag
7366 \begin_inset LatexCommand \index{Flags}
7371 \begin_inset LatexCommand \index{Carry flag}
7376 \layout Subsubsection
7379 \begin_inset LatexCommand \index{Pointers}
7383 to MCS51/DS390 specific memory spaces
7386 SDCC allows (via language extensions) pointers to explicitly point to any
7387 of the memory spaces
7388 \begin_inset LatexCommand \index{Memory model}
7393 In addition to the explicit pointers, the compiler uses (by default) generic
7394 pointers which can be used to point to any of the memory spaces.
7398 Pointer declaration examples:
7403 /* pointer physically in internal ram pointing to object in external ram
7406 xdata unsigned char * data p;
7410 /* pointer physically in external ram pointing to object in internal ram
7413 data unsigned char * xdata p;
7417 /* pointer physically in code rom pointing to data in xdata space */
7419 xdata unsigned char * code p;
7423 /* pointer physically in code space pointing to data in code space */
7425 code unsigned char * code p;
7429 /* the following is a generic pointer physically located in xdata space
7435 Well you get the idea.
7440 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7453 The highest order byte of the
7457 pointers contains the data space information.
7458 Assembler support routines are called whenever data is stored or retrieved
7464 These are useful for developing reusable library
7465 \begin_inset LatexCommand \index{Libraries}
7470 Explicitly specifying the pointer type will generate the most efficient
7475 \begin_inset LatexCommand \index{Absolute addressing}
7482 Data items can be assigned an absolute address with the
7485 \begin_inset LatexCommand \index{at}
7491 keyword, in addition to a storage class, e.g.:
7497 \begin_inset LatexCommand \index{xdata}
7502 \begin_inset LatexCommand \index{at}
7506 0x7ffe unsigned int chksum;
7509 In the above example the variable chksum will located at 0x7ffe and 0x7fff
7510 of the external ram.
7511 The compiler does not actually reserve any space for variables declared
7512 in this way (they are implemented with an equate in the assembler).
7513 Thus it is left to the programmer to make sure there are no overlaps with
7514 other variables that are declared without the absolute address.
7515 The assembler listing file (.lst
7516 \begin_inset LatexCommand \index{.lst}
7520 ) and the linker output files (.rst
7521 \begin_inset LatexCommand \index{.rst}
7526 \begin_inset LatexCommand \index{.map}
7530 ) are good places to look for such overlaps.
7533 In case of memory mapped I/O devices the keyword
7537 should be used to tell the compiler that accesses might not be optimized
7544 \begin_inset LatexCommand \index{volatile}
7549 \begin_inset LatexCommand \index{xdata}
7554 \begin_inset LatexCommand \index{at}
7558 0x8000 unsigned char PORTA_8255;
7561 Absolute address can be specified for variables in all storage classes,
7568 \begin_inset LatexCommand \index{bit}
7573 \begin_inset LatexCommand \index{at}
7580 The above example will allocate the variable at offset 0x02 in the bit-addressab
7582 There is no real advantage to assigning absolute addresses to variables
7583 in this manner, unless you want strict control over all the variables allocated.
7584 One possible use would be to write hardware portable code.
7585 For example, if you have a routine that uses one or more of the microcontroller
7586 I/O pins, and such pins are different for two different hardwares, you
7587 can declare the I/O pins in your routine using:
7592 extern volatile bit SDI;
7594 extern volatile bit SCLK;
7596 extern volatile bit CPOL;
7600 void DS1306_put(unsigned char value)
7608 unsigned char mask=0x80;
7632 SDI=(value & mask)?1:0;
7673 Then, someplace in the code for the first hardware you would use
7678 bit at 0x80 SDI;\SpecialChar ~
7682 /* I/O port 0, bit 0 */
7684 bit at 0x81 SCLK;\SpecialChar ~
7687 /* I/O port 0, bit 1 */
7689 bit CPOL;\SpecialChar ~
7700 /* This is a variable, let the linker allocate this one */
7703 Similarly, for the second hardware you would use
7708 bit at 0x83 SDI;\SpecialChar ~
7712 /* I/O port 0, bit 3 */
7714 bit at 0x91 SCLK;\SpecialChar ~
7717 /* I/O port 1, bit 1 */
7719 bit CPOL;\SpecialChar ~
7730 /* This is a variable, let the linker allocate this one */
7733 and you can use the same hardware dependent routine without changes, as
7734 for example in a library.
7735 This is somehow similar to sbit, but only one absolute address has to be
7736 specified in the whole project.
7740 \begin_inset LatexCommand \index{Parameters}
7745 \begin_inset LatexCommand \index{Local variable}
7752 Automatic (local) variables and parameters to functions can either be placed
7753 on the stack or in data-space.
7754 The default action of the compiler is to place these variables in the internal
7755 RAM (for small model) or external RAM (for large model).
7756 This in fact makes them
7759 \begin_inset LatexCommand \index{static}
7765 so by default functions are non-reentrant
7766 \begin_inset LatexCommand \index{reentrant}
7774 They can be placed on the stack
7775 \begin_inset LatexCommand \index{stack}
7792 \begin_inset LatexCommand \index{-\/-stack-auto}
7798 option or by using the
7801 \begin_inset LatexCommand \index{reentrant}
7807 keyword in the function declaration, e.g.:
7812 unsigned char foo(char i) reentrant
7826 Since stack space on 8051 is limited, the
7844 option should be used sparingly.
7845 Note that the reentrant keyword just means that the parameters & local
7846 variables will be allocated to the stack, it
7850 mean that the function is register bank independent.
7854 Local variables can be assigned storage classes and absolute
7855 \begin_inset LatexCommand \index{Absolute addressing}
7872 xdata unsigned char i;
7884 data at 0x31 unsigned char j;
7896 In the above example the variable
7900 will be allocated in the external ram,
7904 in bit addressable space and
7923 or when a function is declared as
7927 this should only be done for static variables.
7930 Parameters however are not allowed any storage class, (storage classes for
7931 parameters will be ignored), their allocation is governed by the memory
7932 model in use, and the reentrancy options.
7936 \begin_inset LatexCommand \label{sub:Overlaying}
7941 \begin_inset LatexCommand \index{Overlaying}
7949 \begin_inset LatexCommand \index{reentrant}
7953 functions SDCC will try to reduce internal ram space usage by overlaying
7954 parameters and local variables of a function (if possible).
7955 Parameters and local variables of a function will be allocated to an overlayabl
7956 e segment if the function has
7958 no other function calls and the function is non-reentrant and the memory
7960 \begin_inset LatexCommand \index{Memory model}
7967 If an explicit storage class
7968 \begin_inset LatexCommand \index{Storage class}
7972 is specified for a local variable, it will NOT be overlayed.
7975 Note that the compiler (not the linkage editor) makes the decision for overlayin
7977 Functions that are called from an interrupt service routine should be preceded
7978 by a #pragma\SpecialChar ~
7980 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7984 if they are not reentrant.
7987 Also note that the compiler does not do any processing of inline
7988 \begin_inset LatexCommand \index{inline}
7992 assembler code, so the compiler might incorrectly assign local variables
7993 and parameters of a function into the overlay segment if the inline assembler
7994 code calls other c-functions that might use the overlay.
7995 In that case the #pragma\SpecialChar ~
7996 NOOVERLAY should be used.
7999 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
8001 \begin_inset LatexCommand \index{Multiplication}
8006 \begin_inset LatexCommand \index{Division}
8010 will NOT be overlayed since these are implemented using external functions,
8019 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8025 void set_error(unsigned char errcd)
8041 void some_isr () interrupt
8042 \begin_inset LatexCommand \index{interrupt}
8072 In the above example the parameter
8080 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8082 not present, this could cause unpredictable runtime behavior when called
8084 The #pragma\SpecialChar ~
8085 NOOVERLAY ensures that the parameters and local variables for
8086 the function are NOT overlayed.
8089 Interrupt Service Routines
8092 SDCC allows interrupt service routines to be coded in C, with some extended
8098 void timer_isr (void) interrupt 1 using 1
8112 The optional number following the
8115 \begin_inset LatexCommand \index{interrupt}
8121 keyword is the interrupt number this routine will service.
8122 When present, the compiler will insert a call to this routine in the interrupt
8123 vector table for the interrupt number specified.
8128 keyword can be used to tell the compiler to use the specified register
8129 bank (8051 specific) when generating code for this function.
8130 Note that when some function is called from an interrupt service routine
8131 it should be preceded by a #pragma\SpecialChar ~
8133 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8137 if it is not reentrant.
8138 Furthermore nonreentrant functions should not be called from the main program
8139 while the interrupt service routine might be active.
8140 If the interrupt service routines changes variables which are accessed
8141 by other functions these variables should be declared
8146 \begin_inset LatexCommand \index{volatile}
8154 A special note here, int (16 bit) and long (32 bit) integer division
8155 \begin_inset LatexCommand \index{Division}
8160 \begin_inset LatexCommand \index{Multiplication}
8165 \begin_inset LatexCommand \index{Modulus}
8169 operations are implemented using external support routines developed in
8170 ANSI-C, if an interrupt service routine needs to do any of these operations
8171 then the support routines (as mentioned in a following section) will have
8172 to be recompiled using the
8185 \begin_inset LatexCommand \index{-\/-stack-auto}
8191 option and the source file will need to be compiled using the
8206 \begin_inset LatexCommand \index{-\/-int-long-rent}
8213 If you have multiple source files in your project, interrupt service routines
8214 can be present in any of them, but a prototype of the isr MUST be present
8215 or included in the file that contains the function
8222 Interrupt numbers and the corresponding address & descriptions for the Standard
8223 8051/8052 are listed below.
8224 SDCC will automatically adjust the interrupt vector table to the maximum
8225 interrupt number specified.
8231 \begin_inset Tabular
8232 <lyxtabular version="3" rows="7" columns="3">
8234 <column alignment="center" valignment="top" leftline="true" width="0in">
8235 <column alignment="center" valignment="top" leftline="true" width="0in">
8236 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
8237 <row topline="true" bottomline="true">
8238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8263 <row topline="true">
8264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8289 <row topline="true">
8290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8315 <row topline="true">
8316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8341 <row topline="true">
8342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8367 <row topline="true">
8368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8393 <row topline="true" bottomline="true">
8394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8428 If the interrupt service routine is defined without
8431 \begin_inset LatexCommand \index{using}
8437 a register bank or with register bank 0 (using 0), the compiler will save
8438 the registers used by itself on the stack upon entry and restore them at
8439 exit, however if such an interrupt service routine calls another function
8440 then the entire register bank will be saved on the stack.
8441 This scheme may be advantageous for small interrupt service routines which
8442 have low register usage.
8445 If the interrupt service routine is defined to be using a specific register
8450 are save and restored, if such an interrupt service routine calls another
8451 function (using another register bank) then the entire register bank of
8452 the called function will be saved on the stack.
8453 This scheme is recommended for larger interrupt service routines.
8456 Calling other functions from an interrupt service routine is not recommended,
8457 avoid it if possible.
8459 For some pitfalls see section
8460 \begin_inset LatexCommand \ref{sub:Overlaying}
8464 about Overlaying and section
8465 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8469 about Functions using private banks.
8479 <TODO: this isn't implemented at all!>
8485 A special keyword may be associated with a function declaring it as
8490 SDCC will generate code to disable all interrupts upon entry to a critical
8491 function and enable them back before returning.
8492 Note that nesting critical functions may cause unpredictable results.
8518 The critical attribute maybe used with other attributes like
8524 \begin_inset LatexCommand \label{sub:Naked-Functions}
8529 \begin_inset LatexCommand \index{Naked functions}
8536 A special keyword may be associated with a function declaring it as
8539 \begin_inset LatexCommand \index{\_naked}
8550 function modifier attribute prevents the compiler from generating prologue
8551 \begin_inset LatexCommand \index{function prologue}
8556 \begin_inset LatexCommand \index{function epilogue}
8560 code for that function.
8561 This means that the user is entirely responsible for such things as saving
8562 any registers that may need to be preserved, selecting the proper register
8563 bank, generating the
8567 instruction at the end, etc.
8568 Practically, this means that the contents of the function must be written
8569 in inline assembler.
8570 This is particularly useful for interrupt functions, which can have a large
8571 (and often unnecessary) prologue/epilogue.
8572 For example, compare the code generated by these two functions:
8578 \begin_inset LatexCommand \index{volatile}
8582 data unsigned char counter;
8586 void simpleInterrupt(void) interrupt
8587 \begin_inset LatexCommand \index{interrupt}
8605 void nakedInterrupt(void) interrupt 2 _naked
8614 \begin_inset LatexCommand \index{\_asm}
8643 ; MUST explicitly include ret or reti in _naked function.
8650 \begin_inset LatexCommand \index{\_endasm}
8659 For an 8051 target, the generated simpleInterrupt looks like:
8800 whereas nakedInterrupt looks like:
8824 ; MUST explicitly include ret or reti in _naked function.
8827 The #pragma directive EXCLUDE
8828 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
8832 also allows to reduce pushing & popping the registers.
8835 While there is nothing preventing you from writing C code inside a _naked
8836 function, there are many ways to shoot yourself in the foot doing this,
8837 and it is recommended that you stick to inline assembler.
8840 Functions using private banks
8841 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
8846 \begin_inset LatexCommand \index{bank}
8856 \begin_inset LatexCommand \index{using}
8862 attribute (which tells the compiler to use a register bank other than the
8863 default bank zero) should only be applied to
8866 \begin_inset LatexCommand \index{interrupt}
8872 functions (see note 1 below).
8873 This will in most circumstances make the generated ISR code more efficient
8874 since it will not have to save registers on the stack.
8881 attribute will have no effect on the generated code for a
8885 function (but may occasionally be useful anyway
8891 possible exception: if a function is called ONLY from 'interrupt' functions
8892 using a particular bank, it can be declared with the same 'using' attribute
8893 as the calling 'interrupt' functions.
8894 For instance, if you have several ISRs using bank one, and all of them
8895 call memcpy(), it might make sense to create a specialized version of memcpy()
8896 'using 1', since this would prevent the ISR from having to save bank zero
8897 to the stack on entry and switch to bank zero before calling the function
8904 (pending: I don't think this has been done yet)
8911 function using a non-zero bank will assume that it can trash that register
8912 bank, and will not save it.
8913 Since high-priority interrupts
8914 \begin_inset LatexCommand \index{interrupt priority}
8918 can interrupt low-priority ones on the 8051 and friends, this means that
8919 if a high-priority ISR
8923 a particular bank occurs while processing a low-priority ISR
8927 the same bank, terrible and bad things can happen.
8928 To prevent this, no single register bank should be
8932 by both a high priority and a low priority ISR.
8933 This is probably most easily done by having all high priority ISRs use
8934 one bank and all low priority ISRs use another.
8935 If you have an ISR which can change priority at runtime, you're on your
8936 own: I suggest using the default bank zero and taking the small performance
8940 It is most efficient if your ISR calls no other functions.
8941 If your ISR must call other functions, it is most efficient if those functions
8942 use the same bank as the ISR (see note 1 below); the next best is if the
8943 called functions use bank zero.
8944 It is very inefficient to call a function using a different, non-zero bank
8950 \begin_inset LatexCommand \label{sub:Startup-Code}
8955 \begin_inset LatexCommand \index{Startup code}
8962 The compiler inserts a call to the C routine
8964 _sdcc_external_startup()
8965 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8974 at the start of the CODE area.
8975 This routine is in the runtime library
8976 \begin_inset LatexCommand \index{Runtime library}
8981 By default this routine returns 0, if this routine returns a non-zero value,
8982 the static & global variable initialization will be skipped and the function
8983 main will be invoked.
8984 Otherwise static & global variables will be initialized before the function
8988 _sdcc_external_startup()
8990 routine to your program to override the default if you need to setup hardware
8991 or perform some other critical operation prior to static & global variable
8993 See also the compiler option
9012 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9019 Inline Assembler Code
9020 \begin_inset LatexCommand \index{Assembler routines}
9027 SDCC allows the use of in-line assembler with a few restriction as regards
9029 All labels defined within inline assembler code
9037 where nnnn is a number less than 100 (which implies a limit of utmost 100
9038 inline assembler labels
9046 It is strongly recommended that each assembly instruction (including labels)
9047 be placed in a separate line (as the example shows).
9061 \begin_inset LatexCommand \index{-\/-peep-asm}
9067 command line option is used, the inline assembler code will be passed through
9068 the peephole optimizer
9069 \begin_inset LatexCommand \index{Peephole optimizer}
9074 This might cause some unexpected changes in the inline assembler code.
9075 Please go through the peephole optimizer rules defined in file
9079 carefully before using this option.
9085 \begin_inset LatexCommand \index{\_asm}
9115 \begin_inset LatexCommand \index{\_endasm}
9122 The inline assembler code can contain any valid code understood by the assembler
9123 , this includes any assembler directives and comment lines.
9124 The compiler does not do any validation of the code within the
9134 Inline assembler code cannot reference any C-Labels, however it can reference
9136 \begin_inset LatexCommand \index{Labels}
9140 defined by the inline assembler, e.g.:
9165 ; some assembler code
9185 /* some more c code */
9187 clabel:\SpecialChar ~
9189 /* inline assembler cannot reference this label */
9201 $0003: ;label (can be reference by inline assembler only)
9213 /* some more c code */
9218 In other words inline assembly code can access labels defined in inline
9219 assembly within the scope of the function.
9220 The same goes the other way, ie.
9221 labels defines in inline assembly CANNOT be accessed by C statements.
9224 An example acessing a C variable is in section
9225 \begin_inset LatexCommand \ref{sub:Naked-Functions}
9232 Interfacing with Assembler Code
9233 \begin_inset LatexCommand \index{Assembler routines}
9238 \layout Subsubsection
9240 Global Registers used for Parameter Passing
9241 \begin_inset LatexCommand \index{Parameter passing}
9248 The compiler always uses the global registers
9251 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9256 \begin_inset LatexCommand \index{B (register)}
9265 \begin_inset LatexCommand \index{ACC}
9271 to pass the first parameter to a routine.
9272 The second parameter onwards is either allocated on the stack (for reentrant
9283 -stack-auto is used) or in data / xdata memory (depending on the memory
9286 \layout Subsubsection
9288 Assembler Routine(non-reentrant
9289 \begin_inset LatexCommand \index{reentrant}
9294 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
9301 In the following example the function c_func calls an assembler routine
9302 asm_func, which takes two parameters.
9307 extern int asm_func(unsigned char, unsigned char);
9311 int c_func (unsigned char i, unsigned char j)
9319 return asm_func(i,j);
9333 return c_func(10,9);
9338 The corresponding assembler function is:
9343 .globl _asm_func_PARM_2
9407 add a,_asm_func_PARM_2
9432 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9449 Note here that the return values are placed in 'dpl' - One byte return value,
9450 'dpl' LSB & 'dph' MSB for two byte values.
9451 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9452 b' & 'acc' for four byte values.
9455 The parameter naming convention is _<function_name>_PARM_<n>, where n is
9456 the parameter number starting from 1, and counting from the left.
9457 The first parameter is passed in
9458 \begin_inset Quotes eld
9462 \begin_inset Quotes erd
9465 for One bye parameter,
9466 \begin_inset Quotes eld
9470 \begin_inset Quotes erd
9474 \begin_inset Quotes eld
9478 \begin_inset Quotes erd
9482 \begin_inset Quotes eld
9486 \begin_inset Quotes erd
9489 for four bytes, the variable name for the second parameter will be _<function_n
9494 Assemble the assembler routine with the following command:
9501 asx8051 -losg asmfunc.asm
9508 Then compile and link the assembler routine to the C source file with the
9516 sdcc cfunc.c asmfunc.rel
9517 \layout Subsubsection
9519 Assembler Routine(reentrant
9520 \begin_inset LatexCommand \index{reentrant}
9525 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
9532 In this case the second parameter onwards will be passed on the stack, the
9533 parameters are pushed from right to left i.e.
9534 after the call the left most parameter will be on the top of the stack.
9540 extern int asm_func(unsigned char, unsigned char);
9544 int c_func (unsigned char i, unsigned char j) reentrant
9552 return asm_func(i,j);
9566 return c_func(10,9);
9571 The corresponding assembler routine is:
9677 The compiling and linking procedure remains the same, however note the extra
9678 entry & exit linkage required for the assembler code, _bp is the stack
9679 frame pointer and is used to compute the offset into the stack for parameters
9680 and local variables.
9684 \begin_inset LatexCommand \index{int (16 bit)}
9689 \begin_inset LatexCommand \index{long (32 bit)}
9696 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
9697 multiplication and modulus operations are implemented by support routines.
9698 These support routines are all developed in ANSI-C to facilitate porting
9699 to other MCUs, although some model specific assembler optimizations are
9701 The following files contain the described routines, all of them can be
9702 found in <installdir>/share/sdcc/lib.
9708 \begin_inset Tabular
9709 <lyxtabular version="3" rows="11" columns="2">
9711 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9712 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9713 <row topline="true" bottomline="true">
9714 <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">
9735 <row topline="true">
9736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9749 16 bit multiplication
9753 <row topline="true">
9754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9767 signed 16 bit division (calls _divuint)
9771 <row topline="true">
9772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9785 unsigned 16 bit division
9789 <row topline="true">
9790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9803 signed 16 bit modulus (calls _moduint)
9807 <row topline="true">
9808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9821 unsigned 16 bit modulus
9825 <row topline="true">
9826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9839 32 bit multiplication
9843 <row topline="true">
9844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9857 signed 32 division (calls _divulong)
9861 <row topline="true">
9862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9875 unsigned 32 division
9879 <row topline="true">
9880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9893 signed 32 bit modulus (calls _modulong)
9897 <row topline="true" bottomline="true">
9898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9911 unsigned 32 bit modulus
9924 Since they are compiled as
9929 \begin_inset LatexCommand \index{reentrant}
9934 \begin_inset LatexCommand \index{interrupt}
9938 service routines should not do any of the above operations.
9939 If this is unavoidable then the above routines will need to be compiled
9953 \begin_inset LatexCommand \index{-\/-stack-auto}
9959 option, after which the source program will have to be compiled with
9972 \begin_inset LatexCommand \index{-\/-int-long-rent}
9979 Notice that you don't have to call this routines directly.
9980 The compiler will use them automatically every time a integer operation
9984 Floating Point Support
9985 \begin_inset LatexCommand \index{Floating point support}
9992 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9993 floating point support routines are derived from gcc's floatlib.c and consists
9994 of the following routines:
10002 \begin_inset Tabular
10003 <lyxtabular version="3" rows="17" columns="2">
10005 <column alignment="center" valignment="top" leftline="true" width="0(null)">
10006 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
10007 <row topline="true" bottomline="true">
10008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10034 <row topline="true">
10035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10066 add floating point numbers
10070 <row topline="true">
10071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10102 subtract floating point numbers
10106 <row topline="true">
10107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10138 divide floating point numbers
10142 <row topline="true">
10143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10174 multiply floating point numbers
10178 <row topline="true">
10179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10210 convert floating point to unsigned char
10214 <row topline="true">
10215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10246 convert floating point to signed char
10250 <row topline="true">
10251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10282 convert floating point to unsigned int
10286 <row topline="true">
10287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10318 convert floating point to signed int
10322 <row topline="true">
10323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10363 convert floating point to unsigned long
10367 <row topline="true">
10368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10399 convert floating point to signed long
10403 <row topline="true">
10404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10435 convert unsigned char to floating point
10439 <row topline="true">
10440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10471 convert char to floating point number
10475 <row topline="true">
10476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10507 convert unsigned int to floating point
10511 <row topline="true">
10512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10543 convert int to floating point numbers
10547 <row topline="true">
10548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10579 convert unsigned long to floating point number
10583 <row topline="true" bottomline="true">
10584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10615 convert long to floating point number
10628 Note if all these routines are used simultaneously the data space might
10630 For serious floating point usage it is strongly recommended that the large
10632 Also notice that you don't have to call this routines directly.
10633 The compiler will use them automatically every time a floating point operation
10637 MCS51 Memory Models
10638 \begin_inset LatexCommand \index{Memory model}
10643 \begin_inset LatexCommand \index{MCS51 memory}
10650 SDCC allows two memory models for MCS51 code,
10659 Modules compiled with different memory models should
10663 be combined together or the results would be unpredictable.
10664 The library routines supplied with the compiler are compiled as both small
10666 The compiled library modules are contained in separate directories as small
10667 and large so that you can link to either set.
10671 When the large model is used all variables declared without a storage class
10672 will be allocated into the external ram, this includes all parameters and
10673 local variables (for non-reentrant
10674 \begin_inset LatexCommand \index{reentrant}
10679 When the small model is used variables without storage class are allocated
10680 in the internal ram.
10683 Judicious usage of the processor specific storage classes
10684 \begin_inset LatexCommand \index{Storage class}
10688 and the 'reentrant' function type will yield much more efficient code,
10689 than using the large model.
10690 Several optimizations are disabled when the program is compiled using the
10691 large model, it is therefore strongly recommended that the small model
10692 be used unless absolutely required.
10695 DS390 Memory Models
10696 \begin_inset LatexCommand \index{Memory model}
10701 \begin_inset LatexCommand \index{DS390 memory model}
10708 The only model supported is Flat 24
10709 \begin_inset LatexCommand \index{Flat 24 (memory model)}
10714 This generates code for the 24 bit contiguous addressing mode of the Dallas
10716 In this mode, up to four meg of external RAM or code space can be directly
10718 See the data sheets at www.dalsemi.com for further information on this part.
10722 Note that the compiler does not generate any code to place the processor
10723 into 24 bitmode (although
10727 in the ds390 libraries will do that for you).
10733 \begin_inset LatexCommand \index{Tinibios (DS390)}
10737 , the boot loader or similar code must ensure that the processor is in 24
10738 bit contiguous addressing mode before calling the SDCC startup code.
10756 option, variables will by default be placed into the XDATA segment.
10761 Segments may be placed anywhere in the 4 meg address space using the usual
10773 Note that if any segments are located above 64K, the -r flag must be passed
10774 to the linker to generate the proper segment relocations, and the Intel
10775 HEX output format must be used.
10776 The -r flag can be passed to the linker by using the option
10780 on the sdcc command line.
10781 However, currently the linker can not handle code segments > 64k.
10785 \begin_inset LatexCommand \index{Pragmas}
10792 SDCC supports the following #pragma directives.
10796 \begin_inset LatexCommand \index{\#pragma SAVE}
10800 - this will save all current options to the SAVE/RESTORE stack.
10805 \begin_inset LatexCommand \index{\#pragma RESTORE}
10809 - will restore saved options from the last save.
10810 SAVEs & RESTOREs can be nested.
10811 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
10812 RESTORE pulls current options from the stack.
10817 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10821 - will stop global common subexpression elimination.
10825 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10829 - will stop loop induction optimizations.
10833 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
10837 - will not generate code for boundary value checking, when switch statements
10838 are turned into jump-tables (dangerous).
10843 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
10847 - the compiler will not overlay the parameters and local variables of a
10852 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
10856 - the compiler will not warn you anymore for obvious mistakes, you'r on
10861 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
10865 - Will not do loop reversal optimization
10869 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10873 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
10875 \begin_inset LatexCommand \index{push/pop}
10879 instruction in ISR function (using interrupt
10880 \begin_inset LatexCommand \index{interrupt}
10885 The directive should be placed immediately before the ISR function definition
10886 and it affects ALL ISR functions following it.
10887 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
10888 EXCLUDE\SpecialChar ~
10890 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10898 \begin_inset LatexCommand \index{\#pragma NOIV}
10902 - Do not generate interrupt vector table entries for all ISR functions
10903 defined after the pragma.
10904 This is useful in cases where the interrupt vector table must be defined
10905 manually, or when there is a secondary, manually defined interrupt vector
10907 for the autovector feature of the Cypress EZ-USB FX2).
10911 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10916 \begin_inset LatexCommand \index{function prologue}
10920 function1[,function2[,function3...]] - The compiler by default uses a caller
10921 saves convention for register saving across function calls, however this
10922 can cause unnecessary register pushing & popping when calling small functions
10923 from larger functions.
10924 This option can be used to switch off the register saving convention for
10925 the function names specified.
10926 The compiler will not save registers when calling these functions, extra
10927 code need to be manually inserted at the entry & exit for these functions
10928 to save & restore the registers used by these functions, this can SUBSTANTIALLY
10929 reduce code & improve run time performance of the generated code.
10930 In the future the compiler (with inter procedural analysis) may be able
10931 to determine the appropriate scheme to use for each function call.
10942 -callee-saves command line option is used, the function names specified
10943 in #pragma\SpecialChar ~
10945 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10949 is appended to the list of functions specified in the command line.
10952 The pragma's are intended to be used to turn-off certain optimizations which
10953 might cause the compiler to generate extra stack / data space to store
10954 compiler generated temporary variables.
10955 This usually happens in large functions.
10956 Pragma directives should be used as shown in the following example, they
10957 are used to control options & optimizations for a given function; pragmas
10958 should be placed before and/or after a function, placing pragma's inside
10959 a function body could have unpredictable results.
10965 \begin_inset LatexCommand \index{\#pragma SAVE}
10976 /* save the current settings */
10979 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10988 /* turnoff global subexpression elimination */
10990 #pragma NOINDUCTION
10991 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10995 /* turn off induction optimizations */
11018 \begin_inset LatexCommand \index{\#pragma RESTORE}
11022 /* turn the optimizations back on */
11025 The compiler will generate a warning message when extra space is allocated.
11026 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11027 changing options for a function.
11030 Defines Created by the Compiler
11031 \begin_inset LatexCommand \index{Defines created by the compiler}
11038 The compiler creates the following #defines
11039 \begin_inset LatexCommand \index{\#defines}
11049 \begin_inset Tabular
11050 <lyxtabular version="3" rows="10" columns="2">
11052 <column alignment="center" valignment="top" leftline="true" width="0(null)">
11053 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
11054 <row topline="true" bottomline="true">
11055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11076 <row topline="true">
11077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11083 \begin_inset LatexCommand \index{SDCC}
11090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11095 this Symbol is always defined
11099 <row topline="true">
11100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11106 \begin_inset LatexCommand \index{SDCC\_mcs51}
11111 \begin_inset LatexCommand \index{SDCC\_ds390}
11116 \begin_inset LatexCommand \index{SDCC\_z80}
11123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11128 depending on the model used (e.g.: -mds390
11132 <row topline="true">
11133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11139 \begin_inset LatexCommand \index{\_\_mcs51}
11144 \begin_inset LatexCommand \index{\_\_ds390}
11149 \begin_inset LatexCommand \index{\_\_z80}
11156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11161 depending on the model used (e.g.
11166 <row topline="true">
11167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11173 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
11180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11203 <row topline="true">
11204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11210 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
11217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11240 <row topline="true">
11241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11247 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
11254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11277 <row topline="true">
11278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11284 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
11291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11314 <row topline="true">
11315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11321 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
11328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11341 <row topline="true" bottomline="true">
11342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11348 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
11355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11377 Debugging with SDCDB
11378 \begin_inset LatexCommand \index{sdcdb}
11385 SDCC is distributed with a source level debugger
11386 \begin_inset LatexCommand \index{Debugger}
11391 The debugger uses a command line interface, the command repertoire of the
11392 debugger has been kept as close to gdb
11393 \begin_inset LatexCommand \index{gdb}
11397 (the GNU debugger) as possible.
11398 The configuration and build process is part of the standard compiler installati
11399 on, which also builds and installs the debugger in the target directory
11400 specified during configuration.
11401 The debugger allows you debug BOTH at the C source and at the ASM source
11403 Sdcdb is available on Unix platforms only.
11406 Compiling for Debugging
11409 The \SpecialChar \-
11411 debug option must be specified for all files for which debug information
11412 is to be generated.
11413 The complier generates a .adb file for each of these files.
11414 The linker creates the .cdb file from the .adb files and the address information.
11415 This .cdb is used by the debugger.
11418 How the Debugger Works
11431 -debug option is specified the compiler generates extra symbol information
11432 some of which are put into the the assembler source and some are put into
11434 Then the linker creates the .cdb file from the individual .adb files with
11435 the address information for the symbols.
11436 The debugger reads the symbolic information generated by the compiler &
11437 the address information generated by the linker.
11438 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
11439 execution is controlled by the debugger.
11440 When a command is issued for the debugger, it translates it into appropriate
11441 commands for the simulator.
11444 Starting the Debugger
11447 The debugger can be started using the following command line.
11448 (Assume the file you are debugging has the file name foo).
11462 The debugger will look for the following files.
11465 foo.c - the source file.
11468 foo.cdb - the debugger symbol information file.
11471 foo.ihx - the Intel hex format
11472 \begin_inset LatexCommand \index{Intel hex format}
11479 Command Line Options.
11492 -directory=<source file directory> this option can used to specify the directory
11494 The debugger will look into the directory list specified for source, cdb
11496 The items in the directory list must be separated by ':', e.g.
11497 if the source files can be in the directories /home/src1 and /home/src2,
11508 -directory option should be -
11518 -directory=/home/src1:/home/src2.
11519 Note there can be no spaces in the option.
11523 -cd <directory> - change to the <directory>.
11526 -fullname - used by GUI front ends.
11529 -cpu <cpu-type> - this argument is passed to the simulator please see the
11530 simulator docs for details.
11533 -X <Clock frequency > this options is passed to the simulator please see
11534 the simulator docs for details.
11537 -s <serial port file> passed to simulator see the simulator docs for details.
11540 -S <serial in,out> passed to simulator see the simulator docs for details.
11546 As mentioned earlier the command interface for the debugger has been deliberatel
11547 y kept as close the GNU debugger gdb, as possible.
11548 This will help the integration with existing graphical user interfaces
11549 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
11550 If you use a graphical user interface for the debugger you can skip the
11552 \layout Subsubsection*
11554 break [line | file:line | function | file:function]
11557 Set breakpoint at specified line or function:
11566 sdcdb>break foo.c:100
11568 sdcdb>break funcfoo
11570 sdcdb>break foo.c:funcfoo
11571 \layout Subsubsection*
11573 clear [line | file:line | function | file:function ]
11576 Clear breakpoint at specified line or function:
11585 sdcdb>clear foo.c:100
11587 sdcdb>clear funcfoo
11589 sdcdb>clear foo.c:funcfoo
11590 \layout Subsubsection*
11595 Continue program being debugged, after breakpoint.
11596 \layout Subsubsection*
11601 Execute till the end of the current function.
11602 \layout Subsubsection*
11607 Delete breakpoint number 'n'.
11608 If used without any option clear ALL user defined break points.
11609 \layout Subsubsection*
11611 info [break | stack | frame | registers ]
11614 info break - list all breakpoints
11617 info stack - show the function call stack.
11620 info frame - show information about the current execution frame.
11623 info registers - show content of all registers.
11624 \layout Subsubsection*
11629 Step program until it reaches a different source line.
11630 \layout Subsubsection*
11635 Step program, proceeding through subroutine calls.
11636 \layout Subsubsection*
11641 Start debugged program.
11642 \layout Subsubsection*
11647 Print type information of the variable.
11648 \layout Subsubsection*
11653 print value of variable.
11654 \layout Subsubsection*
11659 load the given file name.
11660 Note this is an alternate method of loading file for debugging.
11661 \layout Subsubsection*
11666 print information about current frame.
11667 \layout Subsubsection*
11672 Toggle between C source & assembly source.
11673 \layout Subsubsection*
11675 ! simulator command
11678 Send the string following '!' to the simulator, the simulator response is
11680 Note the debugger does not interpret the command being sent to the simulator,
11681 so if a command like 'go' is sent the debugger can loose its execution
11682 context and may display incorrect values.
11683 \layout Subsubsection*
11690 My name is Bobby Brown"
11693 Interfacing with XEmacs
11694 \begin_inset LatexCommand \index{XEmacs}
11699 \begin_inset LatexCommand \index{Emacs}
11706 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
11707 sdcdb.el and sdcdbsrc.el.
11708 These two files can be found in the $(prefix)/bin directory after the installat
11710 These files need to be loaded into XEmacs for the interface to work.
11711 This can be done at XEmacs startup time by inserting the following into
11712 your '.xemacs' file (which can be found in your HOME directory):
11718 (load-file sdcdbsrc.el)
11724 .xemacs is a lisp file so the () around the command is REQUIRED.
11725 The files can also be loaded dynamically while XEmacs is running, set the
11726 environment variable 'EMACSLOADPATH' to the installation bin directory
11727 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
11728 To start the interface enter the following command:
11742 You will prompted to enter the file name to be debugged.
11747 The command line options that are passed to the simulator directly are bound
11748 to default values in the file sdcdbsrc.el.
11749 The variables are listed below, these values maybe changed as required.
11752 sdcdbsrc-cpu-type '51
11755 sdcdbsrc-frequency '11059200
11758 sdcdbsrc-serial nil
11761 The following is a list of key mapping for the debugger interface.
11769 ;; Current Listing ::
11771 ;;key\SpecialChar ~
11786 binding\SpecialChar ~
11810 ;;---\SpecialChar ~
11825 ------\SpecialChar ~
11865 sdcdb-next-from-src\SpecialChar ~
11891 sdcdb-back-from-src\SpecialChar ~
11917 sdcdb-cont-from-src\SpecialChar ~
11927 SDCDB continue command
11943 sdcdb-step-from-src\SpecialChar ~
11969 sdcdb-whatis-c-sexp\SpecialChar ~
11979 SDCDB ptypecommand for data at
12043 sdcdbsrc-delete\SpecialChar ~
12057 SDCDB Delete all breakpoints if no arg
12105 given or delete arg (C-u arg x)
12121 sdcdbsrc-frame\SpecialChar ~
12136 SDCDB Display current frame if no arg,
12185 given or display frame arg
12250 sdcdbsrc-goto-sdcdb\SpecialChar ~
12260 Goto the SDCDB output buffer
12276 sdcdb-print-c-sexp\SpecialChar ~
12287 SDCDB print command for data at
12351 sdcdbsrc-goto-sdcdb\SpecialChar ~
12361 Goto the SDCDB output buffer
12377 sdcdbsrc-mode\SpecialChar ~
12393 Toggles Sdcdbsrc mode (turns it off)
12397 ;; C-c C-f\SpecialChar ~
12405 sdcdb-finish-from-src\SpecialChar ~
12413 SDCDB finish command
12417 ;; C-x SPC\SpecialChar ~
12425 sdcdb-break\SpecialChar ~
12443 Set break for line with point
12445 ;; ESC t\SpecialChar ~
12455 sdcdbsrc-mode\SpecialChar ~
12471 Toggle Sdcdbsrc mode
12473 ;; ESC m\SpecialChar ~
12483 sdcdbsrc-srcmode\SpecialChar ~
12505 Here are a few guidelines that will help the compiler generate more efficient
12506 code, some of the tips are specific to this compiler others are generally
12507 good programming practice.
12510 Use the smallest data type to represent your data-value.
12511 If it is known in advance that the value is going to be less than 256 then
12512 use an 'unsigned char' instead of a 'short' or 'int'.
12515 Use unsigned when it is known in advance that the value is not going to
12517 This helps especially if you are doing division or multiplication.
12520 NEVER jump into a LOOP.
12523 Declare the variables to be local whenever possible, especially loop control
12524 variables (induction).
12527 Since the compiler does not always do implicit integral promotion, the programme
12528 r should do an explicit cast when integral promotion is required.
12531 Reducing the size of division, multiplication & modulus operations can reduce
12532 code size substantially.
12533 Take the following code for example.
12539 foobar(unsigned int p1, unsigned char ch)
12547 unsigned char ch1 = p1 % ch ;
12558 For the modulus operation the variable ch will be promoted to unsigned int
12559 first then the modulus operation will be performed (this will lead to a
12560 call to support routine _moduint()), and the result will be casted to a
12562 If the code is changed to
12567 foobar(unsigned int p1, unsigned char ch)
12575 unsigned char ch1 = (unsigned char)p1 % ch ;
12586 It would substantially reduce the code generated (future versions of the
12587 compiler will be smart enough to detect such optimization opportunities).
12591 Have a look at the assembly listing to get a
12592 \begin_inset Quotes sld
12596 \begin_inset Quotes srd
12599 for the code generation.
12602 Notes on MCS51 memory
12603 \begin_inset LatexCommand \index{MCS51 memory}
12610 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12611 RAM memory which is structured as follows
12615 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12618 - Bytes 20-2F - 16 bytes to hold 128 bit
12619 \begin_inset LatexCommand \index{bit}
12625 - Bytes 30-7F - 80 bytes for general purpose use.
12630 Additionally some members of the MCS51 family may have up to 128 bytes of
12631 additional, indirectly addressable, internal RAM memory (
12636 \begin_inset LatexCommand \index{idata}
12641 Furthermore, some chips may have some built in external memory (
12646 \begin_inset LatexCommand \index{xdata}
12650 ) which should not be confused with the internal, directly addressable RAM
12656 \begin_inset LatexCommand \index{data}
12661 Sometimes this built in
12665 memory has to be activated before using it (you can probably find this
12666 information on the datasheet of the microcontroller your are using).
12669 Normally SDCC will only use the first bank
12670 \begin_inset LatexCommand \index{bank}
12674 of registers (register bank 0), but it is possible to specify that other
12675 banks of registers should be used in interrupt
12676 \begin_inset LatexCommand \index{interrupt}
12681 By default, the compiler will place the stack after the last byte of allocated
12682 memory for variables.
12683 For example, if the first 2 banks of registers are used, and only four
12688 variables, it will position the base of the internal stack at address 20
12690 This implies that as the stack
12691 \begin_inset LatexCommand \index{stack}
12695 grows, it will use up the remaining register banks, and the 16 bytes used
12696 by the 128 bit variables, and 80 bytes for general purpose use.
12697 If any bit variables are used, the data variables will be placed after
12698 the byte holding the last bit variable.
12699 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12704 variables will be placed starting at address 0x22.
12716 \begin_inset LatexCommand \index{-\/-data-loc}
12720 to specify the start address of the
12734 -iram-size to specify the size of the total internal RAM (
12746 By default the 8051 linker will place the stack after the last byte of data
12759 \begin_inset LatexCommand \index{-\/-stack-loc}
12763 allows you to specify the start of the stack, i.e.
12764 you could start it after any data in the general purpose area.
12765 If your microcontroller has additional indirectly addressable internal
12770 ) you can place the stack on it.
12771 You may also need to use -
12782 \begin_inset LatexCommand \index{-\/-data-loc}
12786 to set the start address of the external RAM (
12801 \begin_inset LatexCommand \index{-\/-data-loc}
12805 to specify its size.
12806 Same goes for the code memory, using -
12817 \begin_inset LatexCommand \index{-\/-data-loc}
12832 \begin_inset LatexCommand \index{-\/-data-loc}
12837 If in doubt, don't specify any options and see if the resulting memory
12838 layout is appropriate, then you can adjust it.
12841 The 8051 linker generates two files with memory allocation information.
12842 The first, with extension .map shows all the variables and segments.
12843 The second with extension .mem shows the final memory layout.
12844 The linker will complaint either if memory segments overlap, there is not
12845 enough memory, or there is not enough space for stack.
12846 If you get any linking warnings and/or errors related to stack or segments
12847 allocation, take a look at either the .map or .mem files to find out what
12849 The .mem file may even suggest a solution to the problem.
12853 \begin_inset LatexCommand \index{Tools}
12857 included in the distribution
12861 \begin_inset Tabular
12862 <lyxtabular version="3" rows="12" columns="3">
12864 <column alignment="center" valignment="top" leftline="true" width="0pt">
12865 <column alignment="center" valignment="top" leftline="true" width="0pt">
12866 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12867 <row topline="true" bottomline="true">
12868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12893 <row topline="true">
12894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12907 Simulator for various architectures
12910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12919 <row topline="true">
12920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12933 header file conversion
12936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12941 sdcc/support/scripts
12945 <row topline="true">
12946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12959 header file conversion
12962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12967 sdcc/support/scripts
12971 <row topline="true">
12972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13006 <row topline="true">
13007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13041 <row topline="true">
13042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13076 <row topline="true">
13077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13111 <row topline="true">
13112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13146 <row topline="true">
13147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13181 <row topline="true">
13182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13216 <row topline="true" bottomline="true">
13217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13260 Related open source tools
13261 \begin_inset LatexCommand \index{Related tools}
13269 \begin_inset Tabular
13270 <lyxtabular version="3" rows="8" columns="3">
13272 <column alignment="center" valignment="top" leftline="true" width="0pt">
13273 <column alignment="block" valignment="top" leftline="true" width="30line%">
13274 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13275 <row topline="true" bottomline="true">
13276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13301 <row topline="true">
13302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13308 \begin_inset LatexCommand \index{gpsim}
13315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13329 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13337 <row topline="true">
13338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13360 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
13368 <row topline="true">
13369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13375 \begin_inset LatexCommand \index{srecord}
13382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13387 Object file conversion, checksumming, ...
13390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13396 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13404 <row topline="true">
13405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13411 \begin_inset LatexCommand \index{objdump}
13418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13423 Object file conversion, ...
13426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13431 Part of binutils (should be there anyway)
13435 <row topline="true">
13436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13442 \begin_inset LatexCommand \index{doxygen}
13449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13454 Source code documentation system
13457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13463 \begin_inset LatexCommand \url{http://www.doxygen.org}
13471 <row topline="true">
13472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13478 \begin_inset LatexCommand \index{splint}
13485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13490 Statically checks c sources
13493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13499 \begin_inset LatexCommand \url{http://www.splint.org}
13507 <row topline="true" bottomline="true">
13508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13514 \begin_inset LatexCommand \index{ddd}
13521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13526 Debugger, serves nicely as GUI to sdcdb
13527 \begin_inset LatexCommand \index{sdcdb}
13534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13540 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13557 Related documentation / recommended reading
13561 \begin_inset Tabular
13562 <lyxtabular version="3" rows="5" columns="3">
13564 <column alignment="center" valignment="top" leftline="true" width="0pt">
13565 <column alignment="block" valignment="top" leftline="true" width="30line%">
13566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13567 <row topline="true" bottomline="true">
13568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13593 <row topline="true">
13594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13609 Advanced Compiler Design and Implementation
13612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13621 <row topline="true">
13622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13645 \begin_inset LatexCommand \index{C Reference card}
13652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13658 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13666 <row topline="true">
13667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13672 test_suite_spec.pdf
13675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13680 sdcc regression test
13681 \begin_inset LatexCommand \index{Regression test}
13688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13697 <row topline="true" bottomline="true">
13698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13729 sdcc internal documentation
13732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13751 \begin_inset LatexCommand \index{Support}
13758 SDCC has grown to be a large project.
13759 The compiler alone (without the preprocessor, assembler and linker) is
13760 well over 100,000 lines of code (blank stripped).
13761 The open source nature of this project is a key to its continued growth
13763 You gain the benefit and support of many active software developers and
13765 Is SDCC perfect? No, that's why we need your help.
13766 The developers take pride in fixing reported bugs.
13767 You can help by reporting the bugs and helping other SDCC users.
13768 There are lots of ways to contribute, and we encourage you to take part
13769 in making SDCC a great software package.
13773 The SDCC project is hosted on the sdcc sourceforge site at
13774 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
13779 You'll find the complete set of mailing lists
13780 \begin_inset LatexCommand \index{Mailing list}
13784 , forums, bug reporting system, patch submission
13785 \begin_inset LatexCommand \index{Patch submission}
13790 \begin_inset LatexCommand \index{download}
13794 area and cvs code repository
13795 \begin_inset LatexCommand \index{cvs code repository}
13803 \begin_inset LatexCommand \index{Bugs}
13808 \begin_inset LatexCommand \index{Reporting bugs}
13815 The recommended way of reporting bugs is using the infrastructure of the
13817 You can follow the status of bug reports there and have an overview about
13821 Bug reports are automatically forwarded to the developer mailing list and
13822 will be fixed ASAP.
13823 When reporting a bug, it is very useful to include a small test program
13824 (the smaller the better) which reproduces the problem.
13825 If you can isolate the problem by looking at the generated assembly code,
13826 this can be very helpful.
13827 Compiling your program with the -
13838 \begin_inset LatexCommand \index{-\/-dumpall}
13842 option can sometimes be useful in locating optimization problems.
13843 When reporting a bug please maker sure you:
13846 Attach the code you are compiling with SDCC.
13850 Specify the exact command you use to run SDCC, or attach your Makefile.
13854 Specify the SDCC version (type "sdcc -v"), your platform, and operating
13859 Provide an exact copy of any error message or incorrect output.
13863 Put something meaningful in the subject of your message.
13866 Please attempt to include these 5 important parts, as applicable, in all
13867 requests for support or when reporting any problems or bugs with SDCC.
13868 Though this will make your message lengthy, it will greatly improve your
13869 chance that SDCC users and developers will be able to help you.
13870 Some SDCC developers are frustrated by bug reports without code provided
13871 that they can use to reproduce and ultimately fix the problem, so please
13872 be sure to provide sample code if you are reporting a bug!
13875 Please have a short check that you are using a recent version of SDCC and
13876 the bug is not yet known.
13877 This is the link for reporting bugs:
13878 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
13885 Requesting Features
13886 \begin_inset LatexCommand \label{sub:Requesting-Features}
13891 \begin_inset LatexCommand \index{Feature request}
13896 \begin_inset LatexCommand \index{Requesting features}
13903 Like bug reports feature requests are forwarded to the developer mailing
13905 This is the link for requesting features:
13906 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
13916 These links should take you directly to the
13917 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
13927 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
13928 automated messages (mid 2003)
13932 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
13936 , lists and forums are archived so if you are lucky someone already had
13941 \begin_inset LatexCommand \index{Changelog}
13948 You can follow the status of the cvs version
13949 \begin_inset LatexCommand \index{version}
13953 of SDCC by watching the file
13954 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
13958 in the cvs-repository.
13962 \begin_inset LatexCommand \index{Release policy}
13969 Historically there often were long delays between official releases and
13970 the sourceforge download area tends to get not updated at all.
13971 Current excuses might refer to problems with live range analysis, but if
13972 this is fixed, the next problem rising is that another excuse will have
13974 Kidding aside, we have to get better there! On the other hand there are
13975 daily snapshots available at
13976 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
13980 , and you can always built the very last version (hopefully with many bugs
13981 fixed, and features added) from the source code available at
13982 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
13990 \begin_inset LatexCommand \index{Examples}
13997 You'll find some small examples in the directory sdcc/device/examples/
14000 Maybe we should include some links to real world applications.
14001 Preferably pointer to pointers (one for each architecture) so this stays
14006 \begin_inset LatexCommand \index{Quality control}
14013 The compiler is passed through nightly compile and build checks.
14019 \begin_inset LatexCommand \index{Regression test}
14023 check that SDCC itself compiles flawlessly on several platforms and checks
14024 the quality of the code generated by SDCC by running the code through simulator
14026 There is a separate document
14029 \begin_inset LatexCommand \index{Test suite}
14038 You'll find the test code in the directory
14040 sdcc/support/regression
14043 You can run these tests manually by running
14047 in this directory (or f.e.
14052 if you don't want to run the complete tests).
14053 The test code might also be interesting if you want to look for examples
14054 \begin_inset LatexCommand \index{Examples}
14058 checking corner cases of SDCC or if you plan to submit patches
14059 \begin_inset LatexCommand \index{Patch submission}
14066 The pic port uses a different set of regression tests, you'll find them
14069 sdcc/src/regression
14074 SDCC Technical Data
14078 \begin_inset LatexCommand \index{Optimizations}
14085 SDCC performs a host of standard optimizations in addition to some MCU specific
14088 \layout Subsubsection
14090 Sub-expression Elimination
14091 \begin_inset LatexCommand \index{Subexpression elimination}
14098 The compiler does local and global common subexpression elimination, e.g.:
14109 will be translated to
14121 Some subexpressions are not as obvious as the above example, e.g.:
14131 In this case the address arithmetic a->b[i] will be computed only once;
14132 the equivalent code in C would be.
14144 The compiler will try to keep these temporary variables in registers.
14145 \layout Subsubsection
14147 Dead-Code Elimination
14148 \begin_inset LatexCommand \index{Dead-code elimination}
14169 i = 1; \SpecialChar ~
14178 global = 1;\SpecialChar ~
14191 global = 3;\SpecialChar ~
14217 \layout Subsubsection
14220 \begin_inset LatexCommand \index{Copy propagation}
14276 Note: the dead stores created by this copy propagation will be eliminated
14277 by dead-code elimination.
14278 \layout Subsubsection
14281 \begin_inset LatexCommand \index{Loop optimization}
14288 Two types of loop optimizations are done by SDCC loop invariant lifting
14289 and strength reduction of loop induction variables.
14290 In addition to the strength reduction the optimizer marks the induction
14291 variables and the register allocator tries to keep the induction variables
14292 in registers for the duration of the loop.
14293 Because of this preference of the register allocator
14294 \begin_inset LatexCommand \index{Register allocation}
14298 , loop induction optimization causes an increase in register pressure, which
14299 may cause unwanted spilling of other temporary variables into the stack
14300 \begin_inset LatexCommand \index{stack}
14305 The compiler will generate a warning message when it is forced to allocate
14306 extra space either on the stack or data space.
14307 If this extra space allocation is undesirable then induction optimization
14308 can be eliminated either for the entire source file (with -
14318 -noinduction option) or for a given function only using #pragma\SpecialChar ~
14320 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
14333 for (i = 0 ; i < 100 ; i ++)
14349 for (i = 0; i < 100; i++)
14358 As mentioned previously some loop invariants are not as apparent, all static
14359 address computations are also moved out of the loop.
14364 \begin_inset LatexCommand \index{Strength reduction}
14368 , this optimization substitutes an expression by a cheaper expression:
14373 for (i=0;i < 100; i++)
14391 for (i=0;i< 100;i++) {
14397 ar[itemp1] = itemp2;
14414 The more expensive multiplication
14415 \begin_inset LatexCommand \index{Multiplication}
14419 is changed to a less expensive addition.
14420 \layout Subsubsection
14423 \begin_inset LatexCommand \index{Loop reversing}
14430 This optimization is done to reduce the overhead of checking loop boundaries
14431 for every iteration.
14432 Some simple loops can be reversed and implemented using a
14433 \begin_inset Quotes eld
14436 decrement and jump if not zero
14437 \begin_inset Quotes erd
14441 SDCC checks for the following criterion to determine if a loop is reversible
14442 (note: more sophisticated compilers use data-dependency analysis to make
14443 this determination, SDCC uses a more simple minded analysis).
14446 The 'for' loop is of the form
14452 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
14462 The <for body> does not contain
14463 \begin_inset Quotes eld
14467 \begin_inset Quotes erd
14471 \begin_inset Quotes erd
14477 All goto's are contained within the loop.
14480 No function calls within the loop.
14483 The loop control variable <sym> is not assigned any value within the loop
14486 The loop control variable does NOT participate in any arithmetic operation
14490 There are NO switch statements in the loop.
14491 \layout Subsubsection
14493 Algebraic Simplifications
14496 SDCC does numerous algebraic simplifications, the following is a small sub-set
14497 of these optimizations.
14502 i = j + 0 ; /* changed to */ i = j;
14504 i /= 2;\SpecialChar ~
14508 /* changed to */ i >>= 1;
14510 i = j - j ; /* changed to */ i = 0;
14512 i = j / 1 ; /* changed to */ i = j;
14515 Note the subexpressions
14516 \begin_inset LatexCommand \index{Subexpression}
14520 given above are generally introduced by macro expansions or as a result
14521 of copy/constant propagation.
14522 \layout Subsubsection
14524 'switch' Statements
14525 \begin_inset LatexCommand \index{switch statement}
14532 SDCC changes switch statements to jump tables
14533 \begin_inset LatexCommand \index{jump tables}
14537 when the following conditions are true.
14541 The case labels are in numerical sequence, the labels need not be in order,
14542 and the starting number need not be one or zero.
14548 switch(i) {\SpecialChar ~
14579 case 4: ...\SpecialChar ~
14611 case 5: ...\SpecialChar ~
14643 case 3: ...\SpecialChar ~
14675 case 6: ...\SpecialChar ~
14743 Both the above switch statements will be implemented using a jump-table.
14744 The example to the right side is slightly more efficient as the check for
14745 the lower boundary of the jump-table is not needed.
14749 The number of case labels is at least three, since it takes two conditional
14750 statements to handle the boundary conditions.
14753 The number of case labels is less than 84, since each label takes 3 bytes
14754 and a jump-table can be utmost 256 bytes long.
14757 Switch statements which have gaps in the numeric sequence or those that
14758 have more that 84 case labels can be split into more than one switch statement
14759 for efficient code generation, e.g.:
14809 If the above switch statement is broken down into two switch statements
14848 case 9:\SpecialChar ~
14855 case 10:\SpecialChar ~
14861 case 11:\SpecialChar ~
14867 case 12:\SpecialChar ~
14874 then both the switch statements will be implemented using jump-tables whereas
14875 the unmodified switch statement will not be.
14876 You might also consider dummy cases 0 and 5 to 8 in this example.
14877 The pragma NOJTBOUND
14878 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
14882 can be used to turn off checking the
14895 \layout Subsubsection
14897 Bit-shifting Operations
14898 \begin_inset LatexCommand \index{Bit shifting}
14905 Bit shifting is one of the most frequently used operation in embedded programmin
14907 SDCC tries to implement bit-shift operations in the most efficient way
14923 generates the following code:
14940 In general SDCC will never setup a loop if the shift count is known.
14982 Note that SDCC stores numbers in little-endian
14983 \begin_inset LatexCommand \index{little-endian}
14988 \begin_inset LatexCommand \index{Endianness}
14993 lowest order first).
14994 \layout Subsubsection
14997 \begin_inset LatexCommand \index{Bit rotation}
15004 A special case of the bit-shift operation is bit rotation, SDCC recognizes
15005 the following expression to be a left bit-rotation:
15015 i = ((i << 1) | (i >> 7));
15024 will generate the following code:
15043 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
15044 ns of this case will also be recognized as bit-rotation, i.e.:
15049 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
15050 \layout Subsubsection
15053 \begin_inset LatexCommand \index{Highest Order Bit}
15060 It is frequently required to obtain the highest order bit of an integral
15061 type (long, int, short or char types).
15062 SDCC recognizes the following expression to yield the highest order bit
15063 and generates optimized code for it, e.g.:
15085 hob = (gint >> 15) & 1;
15095 will generate the following code:
15128 000A E5*01\SpecialChar ~
15155 000C 23\SpecialChar ~
15186 000D 54 01\SpecialChar ~
15213 000F F5*02\SpecialChar ~
15241 Variations of this case however will
15246 It is a standard C expression, so I heartily recommend this be the only
15247 way to get the highest order bit, (it is portable).
15248 Of course it will be recognized even if it is embedded in other expressions,
15254 xyz = gint + ((gint >> 15) & 1);
15257 will still be recognized.
15258 \layout Subsubsection
15261 \begin_inset LatexCommand \index{Peephole optimizer}
15268 The compiler uses a rule based, pattern matching and re-writing mechanism
15269 for peep-hole optimization.
15274 a peep-hole optimizer by Christopher W.
15275 Fraser (cwfraser@microsoft.com).
15276 A default set of rules are compiled into the compiler, additional rules
15277 may be added with the
15290 \begin_inset LatexCommand \index{-\/-peep-file}
15297 The rule language is best illustrated with examples.
15321 The above rule will change the following assembly
15322 \begin_inset LatexCommand \index{Assembler routines}
15344 Note: All occurrences of a
15348 (pattern variable) must denote the same string.
15349 With the above rule, the assembly sequence:
15359 will remain unmodified.
15363 Other special case optimizations may be added by the user (via
15379 some variants of the 8051 MCU allow only
15388 The following two rules will change all
15407 replace { lcall %1 } by { acall %1 }
15409 replace { ljmp %1 } by { ajmp %1 }
15414 inline-assembler code
15416 is also passed through the peep hole optimizer, thus the peephole optimizer
15417 can also be used as an assembly level macro expander.
15418 The rules themselves are MCU dependent whereas the rule language infra-structur
15419 e is MCU independent.
15420 Peephole optimization rules for other MCU can be easily programmed using
15425 The syntax for a rule is as follows:
15430 rule := replace [ restart ] '{' <assembly sequence> '
15468 <assembly sequence> '
15486 '}' [if <functionName> ] '
15491 <assembly sequence> := assembly instruction (each instruction including
15492 labels must be on a separate line).
15496 The optimizer will apply to the rules one by one from the top in the sequence
15497 of their appearance, it will terminate when all rules are exhausted.
15498 If the 'restart' option is specified, then the optimizer will start matching
15499 the rules again from the top, this option for a rule is expensive (performance)
15500 , it is intended to be used in situations where a transformation will trigger
15501 the same rule again.
15502 An example of this (not a good one, it has side effects) is the following
15525 Note that the replace pattern cannot be a blank, but can be a comment line.
15526 Without the 'restart' option only the inner most 'pop' 'push' pair would
15527 be eliminated, i.e.:
15557 the restart option the rule will be applied again to the resulting code
15558 and then all the pop-push pairs will be eliminated to yield:
15568 A conditional function can be attached to a rule.
15569 Attaching rules are somewhat more involved, let me illustrate this with
15596 The optimizer does a look-up of a function name table defined in function
15601 in the source file SDCCpeeph.c, with the name
15606 If it finds a corresponding entry the function is called.
15607 Note there can be no parameters specified for these functions, in this
15612 is crucial, since the function
15616 expects to find the label in that particular variable (the hash table containin
15617 g the variable bindings is passed as a parameter).
15618 If you want to code more such functions, take a close look at the function
15619 labelInRange and the calling mechanism in source file SDCCpeeph.c.
15620 Currently implemented are
15622 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
15623 24bitMode, portIsDS390, 24bitModeAndPortDS390
15632 I know this whole thing is a little kludgey, but maybe some day we will
15633 have some better means.
15634 If you are looking at this file, you will see the default rules that are
15635 compiled into the compiler, you can add your own rules in the default set
15636 there if you get tired of specifying the -
15656 <pending: this is messy and incomplete>
15661 Compiler support routines (_gptrget, _mulint etc)
15664 Stdclib functions (puts, printf, strcat etc)
15667 Math functions (sin, pow, sqrt etc)
15671 \begin_inset LatexCommand \index{Libraries}
15675 included in SDCC should have a license at least as liberal as the GNU Lesser
15676 General Public License
15677 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15688 license statements for the libraries are missing.
15689 sdcc/device/lib/ser_ir.c
15693 come with a GPL (as opposed to LGPL) License - this will not be liberal
15694 enough for many embedded programmers.
15698 \begin_inset LatexCommand \label{sub:External-Stack}
15703 \begin_inset LatexCommand \index{stack}
15708 \begin_inset LatexCommand \index{External stack}
15715 The external stack (-
15726 \begin_inset LatexCommand \index{-\/-xstack}
15730 ) is located at the start of the external ram segment, and is 256 bytes
15742 -xstack option is used to compile the program, the parameters and local
15743 variables of all reentrant functions are allocated in this area.
15744 This option is provided for programs with large stack space requirements.
15745 When used with the -
15756 \begin_inset LatexCommand \index{-\/-stack-auto}
15760 option, all parameters and local variables are allocated on the external
15761 stack (note support libraries will need to be recompiled with the same
15765 The compiler outputs the higher order address byte of the external ram segment
15766 into PORT P2, therefore when using the External Stack option, this port
15767 MAY NOT be used by the application program.
15771 \begin_inset LatexCommand \index{ANSI-compliance}
15778 Deviations from the compliance:
15781 functions are not always reentrant.
15784 structures cannot be assigned values directly, cannot be passed as function
15785 parameters or assigned to each other and cannot be a return value from
15812 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
15823 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
15845 return rets;/* is invalid in SDCC although allowed in ANSI */
15852 \begin_inset LatexCommand \index{long long (not supported)}
15857 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
15865 \begin_inset LatexCommand \index{double (not supported)}
15869 ' precision floating point
15870 \begin_inset LatexCommand \index{Floating point support}
15877 No support for setjmp and longjmp (for now).
15881 \begin_inset LatexCommand \index{K\&R style}
15885 function declarations are NOT allowed.
15891 foo(i,j) /* this old style of function declarations */
15893 int i,j; /* are valid in ANSI but not valid in SDCC */
15908 functions declared as pointers must be dereferenced during the call.
15919 /* has to be called like this */
15921 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
15925 Cyclomatic Complexity
15926 \begin_inset LatexCommand \index{Cyclomatic complexity}
15933 Cyclomatic complexity of a function is defined as the number of independent
15934 paths the program can take during execution of the function.
15935 This is an important number since it defines the number test cases you
15936 have to generate to validate the function.
15937 The accepted industry standard for complexity number is 10, if the cyclomatic
15938 complexity reported by SDCC exceeds 10 you should think about simplification
15939 of the function logic.
15940 Note that the complexity level is not related to the number of lines of
15941 code in a function.
15942 Large functions can have low complexity, and small functions can have large
15948 SDCC uses the following formula to compute the complexity:
15953 complexity = (number of edges in control flow graph) - (number of nodes
15954 in control flow graph) + 2;
15958 Having said that the industry standard is 10, you should be aware that in
15959 some cases it be may unavoidable to have a complexity level of less than
15961 For example if you have switch statement with more than 10 case labels,
15962 each case label adds one to the complexity level.
15963 The complexity level is by no means an absolute measure of the algorithmic
15964 complexity of the function, it does however provide a good starting point
15965 for which functions you might look at for further optimization.
15969 \layout Subsubsection
15972 \begin_inset LatexCommand \index{MCS51 variants}
15979 MCS51 processors are available from many vendors and come in many different
15981 While they might differ considerably in respect to Special Function Registers
15982 the core MCS51 is usually not modified or is kept compatible.
15984 \layout Subsubsection*
15986 pdata access by SFR
15989 With the upcome of devices with internal xdata and flash memory devices
15990 using port P2 as dedicated I/O port is becoming more popular.
15991 Switching the high byte for pdata
15992 \begin_inset LatexCommand \index{pdata}
15996 access which was formerly done by port P2 is then achieved by a Special
15998 In well-established MCS51 tradition the address of this
16002 is where the chip designers decided to put it.
16003 As pdata addressing is used in the startup code for the initialization
16004 of xdata variables a separate startup code should be used as described
16006 \begin_inset LatexCommand \ref{sub:Startup-Code}
16011 \layout Subsubsection*
16013 Other Features available by SFR
16016 Some MCS51 variants offer features like Double DPTR
16017 \begin_inset LatexCommand \index{DPTR}
16021 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16022 These are currently not used for the MCS51 port.
16023 If you absolutely need them you can fall back to inline assembly or submit
16025 \layout Subsubsection
16027 The Z80 and gbz80 port
16030 SDCC can target both the Zilog
16031 \begin_inset LatexCommand \index{Z80}
16035 and the Nintendo Gameboy's Z80-like gbz80
16036 \begin_inset LatexCommand \index{GameBoy Z80}
16041 The Z80 port is passed through the same
16044 \begin_inset LatexCommand \index{Regression test}
16050 as MCS51 and DS390 ports, so floating point support, support for long variables
16051 and bitfield support is fine.
16054 As always, the code is the authoritative reference - see z80/ralloc.c and
16056 The stack frame is similar to that generated by the IAR Z80 compiler.
16057 IX is used as the base pointer, HL is used as a temporary register, and
16058 BC and DE are available for holding variables.
16059 IY is currently unused.
16060 Return values are stored in HL.
16061 One bad side effect of using IX as the base pointer is that a functions
16062 stack frame is limited to 127 bytes - this will be fixed in a later version.
16065 Retargetting for other MCUs.
16068 The issues for retargetting the compiler are far too numerous to be covered
16070 What follows is a brief description of each of the seven phases of the
16071 compiler and its MCU dependency.
16074 Parsing the source and building the annotated parse tree.
16075 This phase is largely MCU independent (except for the language extensions).
16076 Syntax & semantic checks are also done in this phase, along with some initial
16077 optimizations like back patching labels and the pattern matching optimizations
16078 like bit-rotation etc.
16081 The second phase involves generating an intermediate code which can be easy
16082 manipulated during the later phases.
16083 This phase is entirely MCU independent.
16084 The intermediate code generation assumes the target machine has unlimited
16085 number of registers, and designates them with the name iTemp.
16086 The compiler can be made to dump a human readable form of the code generated
16100 This phase does the bulk of the standard optimizations and is also MCU independe
16102 This phase can be broken down into several sub-phases:
16106 Break down intermediate code (iCode) into basic blocks.
16108 Do control flow & data flow analysis on the basic blocks.
16110 Do local common subexpression elimination, then global subexpression elimination
16112 Dead code elimination
16116 If loop optimizations caused any changes then do 'global subexpression eliminati
16117 on' and 'dead code elimination' again.
16120 This phase determines the live-ranges; by live range I mean those iTemp
16121 variables defined by the compiler that still survive after all the optimization
16123 Live range analysis
16124 \begin_inset LatexCommand \index{Live range analysis}
16128 is essential for register allocation, since these computation determines
16129 which of these iTemps will be assigned to registers, and for how long.
16132 Phase five is register allocation.
16133 There are two parts to this process.
16137 The first part I call 'register packing' (for lack of a better term).
16138 In this case several MCU specific expression folding is done to reduce
16143 The second part is more MCU independent and deals with allocating registers
16144 to the remaining live ranges.
16145 A lot of MCU specific code does creep into this phase because of the limited
16146 number of index registers available in the 8051.
16149 The Code generation phase is (unhappily), entirely MCU dependent and very
16150 little (if any at all) of this code can be reused for other MCU.
16151 However the scheme for allocating a homogenized assembler operand for each
16152 iCode operand may be reused.
16155 As mentioned in the optimization section the peep-hole optimizer is rule
16156 based system, which can reprogrammed for other MCUs.
16160 \begin_inset LatexCommand \index{Compiler internals}
16167 The anatomy of the compiler
16172 This is an excerpt from an article published in Circuit Cellar Magazine
16174 It's a little outdated (the compiler is much more efficient now and user/develo
16175 per friendly), but pretty well exposes the guts of it all.
16181 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
16182 It is fairly easy to retarget for other 8-bit MCU.
16183 Here we take a look at some of the internals of the compiler.
16188 \begin_inset LatexCommand \index{Parsing}
16195 Parsing the input source file and creating an AST (Annotated Syntax Tree
16196 \begin_inset LatexCommand \index{Annotated syntax tree}
16201 This phase also involves propagating types (annotating each node of the
16202 parse tree with type information) and semantic analysis.
16203 There are some MCU specific parsing rules.
16204 For example the storage classes, the extended storage classes are MCU specific
16205 while there may be a xdata storage class for 8051 there is no such storage
16206 class for z80 or Atmel AVR.
16207 SDCC allows MCU specific storage class extensions, i.e.
16208 xdata will be treated as a storage class specifier when parsing 8051 C
16209 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
16214 \begin_inset LatexCommand \index{iCode}
16221 Intermediate code generation.
16222 In this phase the AST is broken down into three-operand form (iCode).
16223 These three operand forms are represented as doubly linked lists.
16224 ICode is the term given to the intermediate form generated by the compiler.
16225 ICode example section shows some examples of iCode generated for some simple
16226 C source functions.
16230 \begin_inset LatexCommand \index{Optimizations}
16237 Bulk of the target independent optimizations is performed in this phase.
16238 The optimizations include constant propagation, common sub-expression eliminati
16239 on, loop invariant code movement, strength reduction of loop induction variables
16240 and dead-code elimination.
16243 Live range analysis
16244 \begin_inset LatexCommand \index{Live range analysis}
16251 During intermediate code generation phase, the compiler assumes the target
16252 machine has infinite number of registers and generates a lot of temporary
16254 The live range computation determines the lifetime of each of these compiler-ge
16255 nerated temporaries.
16256 A picture speaks a thousand words.
16257 ICode example sections show the live range annotations for each of the
16259 It is important to note here, each iCode is assigned a number in the order
16260 of its execution in the function.
16261 The live ranges are computed in terms of these numbers.
16262 The from number is the number of the iCode which first defines the operand
16263 and the to number signifies the iCode which uses this operand last.
16266 Register Allocation
16267 \begin_inset LatexCommand \index{Register allocation}
16274 The register allocation determines the type and number of registers needed
16276 In most MCUs only a few registers can be used for indirect addressing.
16277 In case of 8051 for example the registers R0 & R1 can be used to indirectly
16278 address the internal ram and DPTR to indirectly address the external ram.
16279 The compiler will try to allocate the appropriate register to pointer variables
16281 ICode example section shows the operands annotated with the registers assigned
16283 The compiler will try to keep operands in registers as much as possible;
16284 there are several schemes the compiler uses to do achieve this.
16285 When the compiler runs out of registers the compiler will check to see
16286 if there are any live operands which is not used or defined in the current
16287 basic block being processed, if there are any found then it will push that
16288 operand and use the registers in this block, the operand will then be popped
16289 at the end of the basic block.
16293 There are other MCU specific considerations in this phase.
16294 Some MCUs have an accumulator; very short-lived operands could be assigned
16295 to the accumulator instead of general-purpose register.
16301 Figure II gives a table of iCode operations supported by the compiler.
16302 The code generation involves translating these operations into corresponding
16303 assembly code for the processor.
16304 This sounds overly simple but that is the essence of code generation.
16305 Some of the iCode operations are generated on a MCU specific manner for
16306 example, the z80 port does not use registers to pass parameters so the
16307 SEND and RECV iCode operations will not be generated, and it also does
16308 not support JUMPTABLES.
16315 <Where is Figure II ?>
16319 \begin_inset LatexCommand \index{iCode}
16326 This section shows some details of iCode.
16327 The example C code does not do anything useful; it is used as an example
16328 to illustrate the intermediate code generated by the compiler.
16340 /* This function does nothing useful.
16347 for the purpose of explaining iCode */
16350 short function (data int *x)
16358 short i=10; /* dead initialization eliminated */
16363 short sum=10; /* dead initialization eliminated */
16376 while (*x) *x++ = *p++;
16390 /* compiler detects i,j to be induction variables */
16394 for (i = 0, j = 10 ; i < 10 ; i++, j
16420 mul += i * 3; /* this multiplication remains */
16426 gint += j * 3;/* this multiplication changed to addition */
16440 In addition to the operands each iCode contains information about the filename
16441 and line it corresponds to in the source file.
16442 The first field in the listing should be interpreted as follows:
16447 Filename(linenumber: iCode Execution sequence number : ICode hash table
16448 key : loop depth of the iCode).
16453 Then follows the human readable form of the ICode operation.
16454 Each operand of this triplet form can be of three basic types a) compiler
16455 generated temporary b) user defined variable c) a constant value.
16456 Note that local variables and parameters are replaced by compiler generated
16459 \begin_inset LatexCommand \index{Live range analysis}
16463 are computed only for temporaries (i.e.
16464 live ranges are not computed for global variables).
16466 \begin_inset LatexCommand \index{Register allocation}
16470 are allocated for temporaries only.
16471 Operands are formatted in the following manner:
16476 Operand Name [lr live-from : live-to ] { type information } [ registers
16482 As mentioned earlier the live ranges are computed in terms of the execution
16483 sequence number of the iCodes, for example
16485 the iTemp0 is live from (i.e.
16486 first defined in iCode with execution sequence number 3, and is last used
16487 in the iCode with sequence number 5).
16488 For induction variables such as iTemp21 the live range computation extends
16489 the lifetime from the start to the end of the loop.
16491 The register allocator used the live range information to allocate registers,
16492 the same registers may be used for different temporaries if their live
16493 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
16494 iTemp17 since their live ranges do not overlap.
16495 In addition the allocator also takes into consideration the type and usage
16496 of a temporary, for example itemp6 is a pointer to near space and is used
16497 as to fetch data from (i.e.
16498 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
16499 Some short lived temporaries are allocated to special registers which have
16500 meaning to the code generator e.g.
16501 iTemp13 is allocated to a pseudo register CC which tells the back end that
16502 the temporary is used only for a conditional jump the code generation makes
16503 use of this information to optimize a compare and jump ICode.
16505 There are several loop optimizations
16506 \begin_inset LatexCommand \index{Loop optimization}
16510 performed by the compiler.
16511 It can detect induction variables iTemp21(i) and iTemp23(j).
16512 Also note the compiler does selective strength reduction
16513 \begin_inset LatexCommand \index{Strength reduction}
16518 the multiplication of an induction variable in line 18 (gint = j * 3) is
16519 changed to addition, a new temporary iTemp17 is allocated and assigned
16520 a initial value, a constant 3 is then added for each iteration of the loop.
16521 The compiler does not change the multiplication
16522 \begin_inset LatexCommand \index{Multiplication}
16526 in line 17 however since the processor does support an 8 * 8 bit multiplication.
16528 Note the dead code elimination
16529 \begin_inset LatexCommand \index{Dead-code elimination}
16533 optimization eliminated the dead assignments in line 7 & 8 to I and sum
16541 Sample.c (5:1:0:0) _entry($9) :
16546 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
16551 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
16556 Sample.c(11:4:53:0) preHeaderLbl0($11) :
16561 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
16567 Sample.c(11:6:5:1) _whilecontinue_0($1) :
16572 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
16578 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16583 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
16589 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
16595 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
16601 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
16607 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
16608 * int}[r0] + 0x2 {short}
16613 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
16618 Sample.c(11:17:21:0)_whilebreak_0($3) :
16623 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16628 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16633 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16638 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16643 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16648 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16653 Sample.c(15:24:26:1)_forcond_0($4) :
16658 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16664 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16669 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16670 + ITemp21 [lr21:38]{short}[r4]
16675 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16681 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16682 + iTemp15 [lr29:30]{short}[r1]
16687 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16693 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16699 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16705 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16711 Sample.c(19:38:47:1) goto _forcond_0($4)
16716 Sample.c(19:39:48:0)_forbreak_0($7) :
16721 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16722 + ITemp11 [lr19:40]{short}[r3]
16727 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16732 Sample.c(20:42:51:0)_return($8) :
16737 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16743 Finally the code generated for this function:
16784 ; ----------------------------------------------
16789 ; function function
16794 ; ----------------------------------------------
16804 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16816 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16828 ;_whilecontinue_0($1) :
16838 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16843 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16902 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16921 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16968 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
17008 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
17034 ; iTemp6 [lr5:16]{_near * int}[r0] =
17039 ; iTemp6 [lr5:16]{_near * int}[r0] +
17056 ; goto _whilecontinue_0($1)
17068 ; _whilebreak_0($3) :
17078 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
17090 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
17102 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
17114 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
17133 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
17162 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
17167 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
17212 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
17217 ; iTemp21 [lr21:38]{short}[r4]
17243 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
17276 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
17281 ; iTemp15 [lr29:30]{short}[r1]
17300 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
17347 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
17394 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
17406 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
17420 cjne r5,#0xff,00104$
17432 ; goto _forcond_0($4)
17444 ; _forbreak_0($7) :
17454 ; ret iTemp24 [lr40:41]{short}
17497 A few words about basic block successors, predecessors and dominators
17500 Successors are basic blocks
17501 \begin_inset LatexCommand \index{Basic blocks}
17505 that might execute after this basic block.
17507 Predecessors are basic blocks that might execute before reaching this basic
17510 Dominators are basic blocks that WILL execute before reaching this basic
17544 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
17547 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
17550 c) domVect of [BB4] = BB1 ...
17551 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
17559 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
17569 Thanks to all the other volunteer developers who have helped with coding,
17570 testing, web-page creation, distribution sets, etc.
17571 You know who you are :-)
17578 This document was initially written by Sandeep Dutta
17581 All product names mentioned herein may be trademarks
17582 \begin_inset LatexCommand \index{Trademarks}
17586 of their respective companies.
17593 To avoid confusion, the installation and building options for sdcc itself
17594 (chapter 2) are not part of the index.
17598 \begin_inset LatexCommand \printindex{}