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 and unpack it using your favorite unpacking
3307 tool (gunzip, WinZip, etc).
3308 This should unpack to a group of sub-directories.
3309 An example directory structure after unpacking the mingw32 package is:
3314 bin for the executables, c:
3322 lib for the include and libraries.
3325 Adjust your environment variable PATH to include the location of the bin
3326 directory or start sdcc using the full path.
3329 Building the Documentation
3332 If the necessary tools are installed it is as easy as changing into the
3333 doc directory and typing
3337 \begin_inset Quotes srd
3341 \begin_inset Quotes srd
3348 If you want to avoid installing the tools you will have some success with
3349 a bootable Knoppix CD
3350 \begin_inset LatexCommand \url{http://www.knopper.net}
3357 Testing the SDCC Compiler
3360 The first thing you should do after installing your SDCC compiler is to
3376 \begin_inset LatexCommand \index{version}
3383 at the prompt, and the program should run and tell you the version.
3384 If it doesn't run, or gives a message about not finding sdcc program, then
3385 you need to check over your installation.
3386 Make sure that the sdcc bin directory is in your executable search path
3387 defined by the PATH environment setting (see the Trouble-shooting section
3389 Make sure that the sdcc program is in the bin folder, if not perhaps something
3390 did not install correctly.
3398 is commonly installed as described in section
3399 \begin_inset Quotes sld
3402 Install and search paths
3403 \begin_inset Quotes srd
3412 Make sure the compiler works on a very simple example.
3413 Type in the following test.c program using your favorite
3439 Compile this using the following command:
3448 If all goes well, the compiler will generate a test.asm and test.rel file.
3449 Congratulations, you've just compiled your first program with SDCC.
3450 We used the -c option to tell SDCC not to link the generated code, just
3451 to keep things simple for this step.
3459 The next step is to try it with the linker.
3469 If all goes well the compiler will link with the libraries and produce
3470 a test.ihx output file.
3475 (no test.ihx, and the linker generates warnings), then the problem is most
3476 likely that sdcc cannot find the
3480 usr/local/share/sdcc/lib directory
3484 (see the Install trouble-shooting section for suggestions).
3492 The final test is to ensure sdcc can use the
3496 header files and libraries.
3497 Edit test.c and change it to the following:
3514 strcpy(str1, "testing");
3521 Compile this by typing
3528 This should generate a test.ihx output file, and it should give no warnings
3529 such as not finding the string.h file.
3530 If it cannot find the string.h file, then the problem is that sdcc cannot
3531 find the /usr/local/share/sdcc/include directory
3535 (see the Install trouble-shooting section for suggestions).
3553 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3557 to find exactly where SDCC is looking for the include and lib files.
3560 Install Trouble-shooting
3561 \begin_inset LatexCommand \index{Install trouble-shooting}
3566 \layout Subsubsection
3568 SDCC does not build correctly.
3571 A thing to try is starting from scratch by unpacking the .tgz source package
3572 again in an empty directory.
3580 ./configure 2>&1 | tee configure.log
3594 make 2>&1 | tee make.log
3601 If anything goes wrong, you can review the log files to locate the problem.
3602 Or a relevant part of this can be attached to an email that could be helpful
3603 when requesting help from the mailing list.
3604 \layout Subsubsection
3607 \begin_inset Quotes sld
3611 \begin_inset Quotes srd
3618 \begin_inset Quotes sld
3622 \begin_inset Quotes srd
3625 command is a script that analyzes your system and performs some configuration
3626 to ensure the source package compiles on your system.
3627 It will take a few minutes to run, and will compile a few tests to determine
3628 what compiler features are installed.
3629 \layout Subsubsection
3632 \begin_inset Quotes sld
3636 \begin_inset Quotes srd
3642 This runs the GNU make tool, which automatically compiles all the source
3643 packages into the final installed binary executables.
3644 \layout Subsubsection
3647 \begin_inset Quotes sld
3651 \begin_inset Quotes erd
3657 This will install the compiler, other executables libraries and include
3658 files into the appropriate directories.
3660 \begin_inset Quotes sld
3663 Install and Search PATHS
3664 \begin_inset Quotes srd
3669 On most systems you will need super-user privileges to do this.
3675 SDCC is not just a compiler, but a collection of tools by various developers.
3676 These include linkers, assemblers, simulators and other components.
3677 Here is a summary of some of the components.
3678 Note that the included simulator and assembler have separate documentation
3679 which you can find in the source package in their respective directories.
3680 As SDCC grows to include support for other processors, other packages from
3681 various developers are included and may have their own sets of documentation.
3685 You might want to look at the files which are installed in <installdir>.
3686 At the time of this writing, we find the following programs for gcc-builds:
3690 In <installdir>/bin:
3693 sdcc - The compiler.
3696 sdcpp - The C preprocessor.
3699 asx8051 - The assembler for 8051 type processors.
3706 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3709 aslink -The linker for 8051 type processors.
3716 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3719 s51 - The ucSim 8051 simulator.
3722 sdcdb - The source debugger.
3725 packihx - A tool to pack (compress) Intel hex files.
3728 In <installdir>/share/sdcc/include
3734 In <installdir>/share/sdcc/lib
3737 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3741 In <installdir>/share/sdcc/doc
3747 As development for other processors proceeds, this list will expand to include
3748 executables to support processors like AVR, PIC, etc.
3749 \layout Subsubsection
3754 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3755 the assembler and linkage editor.
3756 \layout Subsubsection
3759 \begin_inset LatexCommand \index{sdcpp}
3763 - The C-Preprocessor
3766 The preprocessor is a modified version of the GNU preprocessor.
3767 The C preprocessor is used to pull in #include sources, process #ifdef
3768 statements, #defines and so on.
3769 \layout Subsubsection
3771 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3775 This is retargettable assembler & linkage editor, it was developed by Alan
3777 John Hartman created the version for 8051, and I (Sandeep) have made some
3778 enhancements and bug fixes for it to work properly with SDCC.
3779 \layout Subsubsection
3782 \begin_inset LatexCommand \index{s51}
3789 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3790 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3795 The simulator is built as part of the build process.
3796 For more information visit Daniel's web site at:
3797 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3802 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3804 \layout Subsubsection
3807 \begin_inset LatexCommand \index{sdcdb}
3811 - Source Level Debugger
3814 Sdcdb is the companion source level debugger.
3815 The current version of the debugger uses Daniel's Simulator S51
3816 \begin_inset LatexCommand \index{s51}
3820 , but can be easily changed to use other simulators.
3827 \layout Subsubsection
3829 Single Source File Projects
3832 For single source file 8051 projects the process is very simple.
3833 Compile your programs with the following command
3836 "sdcc sourcefile.c".
3840 This will compile, assemble and link your source file.
3841 Output files are as follows
3845 \begin_inset LatexCommand \index{.asm}
3850 \begin_inset LatexCommand \index{Assembler source}
3854 file created by the compiler
3858 \begin_inset LatexCommand \index{.lst}
3863 \begin_inset LatexCommand \index{Assembler listing}
3867 file created by the Assembler
3871 \begin_inset LatexCommand \index{.rst}
3876 \begin_inset LatexCommand \index{Assembler listing}
3880 file updated with linkedit information, created by linkage editor
3884 \begin_inset LatexCommand \index{.sym}
3889 \begin_inset LatexCommand \index{Symbol listing}
3893 for the sourcefile, created by the assembler
3897 \begin_inset LatexCommand \index{.rel}
3902 \begin_inset LatexCommand \index{Object file}
3906 created by the assembler, input to Linkage editor
3910 \begin_inset LatexCommand \index{.map}
3915 \begin_inset LatexCommand \index{Memory map}
3919 for the load module, created by the Linker
3923 \begin_inset LatexCommand \index{.mem}
3927 - A file with a summary of the memory usage
3931 \begin_inset LatexCommand \index{.ihx}
3935 - The load module in Intel hex format
3936 \begin_inset LatexCommand \index{Intel hex format}
3940 (you can select the Motorola S19 format
3941 \begin_inset LatexCommand \index{Motorola S19 format}
3956 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3961 If you need another format you might want to use
3968 \begin_inset LatexCommand \index{objdump}
3979 \begin_inset LatexCommand \index{srecord}
3987 \begin_inset LatexCommand \index{.adb}
3991 - An intermediate file containing debug information needed to create the
4003 \begin_inset LatexCommand \index{-\/-debug}
4011 \begin_inset LatexCommand \index{.cdb}
4015 - An optional file (with -
4025 -debug) containing debug information
4030 \begin_inset LatexCommand \index{. (no extension)}
4035 \begin_inset LatexCommand \index{AOMF51}
4039 file containing debug information (with -
4050 This format is commonly used by third party tools (debuggers
4051 \begin_inset LatexCommand \index{Debugger}
4055 , simulators, emulators)
4059 \begin_inset LatexCommand \index{.dump*}
4063 - Dump file to debug the compiler it self (with -
4073 -dumpall) (see section
4074 \begin_inset Quotes sld
4077 Anatomy of the compiler
4078 \begin_inset Quotes srd
4082 \layout Subsubsection
4084 Projects with Multiple Source Files
4087 SDCC can compile only ONE file at a time.
4088 Let us for example assume that you have a project containing the following
4093 foo1.c (contains some functions)
4095 foo2.c (contains some more functions)
4097 foomain.c (contains more functions and the function main)
4105 The first two files will need to be compiled separately with the commands:
4137 Then compile the source file containing the
4142 \begin_inset LatexCommand \index{Linker}
4146 the files together with the following command:
4154 foomain.c\SpecialChar ~
4155 foo1.rel\SpecialChar ~
4160 \begin_inset LatexCommand \index{.rel}
4172 can be separately compiled as well:
4183 sdcc foomain.rel foo1.rel foo2.rel
4190 The file containing the
4205 file specified in the command line, since the linkage editor processes
4206 file in the order they are presented to it.
4207 The linker is invoked from sdcc using a script file with extension .lnk
4208 \begin_inset LatexCommand \index{.lnk}
4213 You can view this file to troubleshoot linking problems such as those arising
4214 from missing libraries.
4215 \layout Subsubsection
4217 Projects with Additional Libraries
4218 \begin_inset LatexCommand \index{Libraries}
4225 Some reusable routines may be compiled into a library, see the documentation
4226 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4230 \begin_inset LatexCommand \index{.lib}
4237 Libraries created in this manner can be included in the command line.
4238 Make sure you include the -L <library-path> option to tell the linker where
4239 to look for these files if they are not in the current directory.
4240 Here is an example, assuming you have the source file
4252 (if that is not the same as your current project):
4259 sdcc foomain.c foolib.lib -L mylib
4270 must be an absolute path name.
4274 The most efficient way to use libraries is to keep separate modules in separate
4276 The lib file now should name all the modules.rel
4277 \begin_inset LatexCommand \index{rel}
4282 For an example see the standard library file
4286 in the directory <installdir>/share/lib/small.
4289 Command Line Options
4290 \begin_inset LatexCommand \index{Command Line Options}
4295 \layout Subsubsection
4297 Processor Selection Options
4298 \begin_inset LatexCommand \index{Options processor selection}
4303 \begin_inset LatexCommand \index{Processor selection options}
4309 \labelwidthstring 00.00.0000
4314 \begin_inset LatexCommand \index{-mmcs51}
4320 Generate code for the Intel MCS51
4321 \begin_inset LatexCommand \index{MCS51}
4325 family of processors.
4326 This is the default processor target.
4328 \labelwidthstring 00.00.0000
4333 \begin_inset LatexCommand \index{-mds390}
4339 Generate code for the Dallas DS80C390
4340 \begin_inset LatexCommand \index{DS80C390}
4346 \labelwidthstring 00.00.0000
4351 \begin_inset LatexCommand \index{-mds400}
4357 Generate code for the Dallas DS80C400
4358 \begin_inset LatexCommand \index{DS80C400}
4364 \labelwidthstring 00.00.0000
4369 \begin_inset LatexCommand \index{-mz80}
4375 Generate code for the Zilog Z80
4376 \begin_inset LatexCommand \index{Z80}
4380 family of processors.
4382 \labelwidthstring 00.00.0000
4387 \begin_inset LatexCommand \index{-mgbz80}
4393 Generate code for the GameBoy Z80
4394 \begin_inset LatexCommand \index{GameBoy Z80}
4400 \labelwidthstring 00.00.0000
4405 \begin_inset LatexCommand \index{-mavr}
4411 Generate code for the Atmel AVR
4412 \begin_inset LatexCommand \index{AVR}
4416 processor (In development, not complete).
4417 AVR users should probably have a look at avr-gcc
4418 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4425 I think it is fair to direct users there for now.
4426 Open source is also about avoiding unnecessary work .
4427 But I didn't find the 'official' link.
4429 \labelwidthstring 00.00.0000
4434 \begin_inset LatexCommand \index{-mpic14}
4440 Generate code for the Microchip PIC 14
4441 \begin_inset LatexCommand \index{PIC14}
4445 -bit processors (p16f84 and variants).
4448 p16f627 p16f628 p16f84 p16f873 p16f877?
4450 \labelwidthstring 00.00.0000
4455 \begin_inset LatexCommand \index{-mpic16}
4461 Generate code for the Microchip PIC 16
4462 \begin_inset LatexCommand \index{PIC16}
4466 -bit processors (p18f452 and variants).
4468 \labelwidthstring 00.00.0000
4474 Generate code for the Toshiba TLCS-900H
4475 \begin_inset LatexCommand \index{TLCS-900H}
4479 processor (In development, not complete).
4481 \labelwidthstring 00.00.0000
4486 \begin_inset LatexCommand \index{-mxa51}
4492 Generate code for the Phillips XA51
4493 \begin_inset LatexCommand \index{XA51}
4497 processor (In development, not complete).
4498 \layout Subsubsection
4500 Preprocessor Options
4501 \begin_inset LatexCommand \index{Options preprocessor}
4506 \begin_inset LatexCommand \index{Preprocessor options}
4512 \labelwidthstring 00.00.0000
4517 \begin_inset LatexCommand \index{-I<path>}
4523 The additional location where the pre processor will look for <..h> or
4524 \begin_inset Quotes eld
4528 \begin_inset Quotes erd
4533 \labelwidthstring 00.00.0000
4538 \begin_inset LatexCommand \index{-D<macro[=value]>}
4544 Command line definition of macros.
4545 Passed to the preprocessor.
4547 \labelwidthstring 00.00.0000
4552 \begin_inset LatexCommand \index{-M}
4558 Tell the preprocessor to output a rule suitable for make describing the
4559 dependencies of each object file.
4560 For each source file, the preprocessor outputs one make-rule whose target
4561 is the object file name for that source file and whose dependencies are
4562 all the files `#include'd in it.
4563 This rule may be a single line or may be continued with `
4565 '-newline if it is long.
4566 The list of rules is printed on standard output instead of the preprocessed
4569 \begin_inset LatexCommand \index{-E}
4575 \labelwidthstring 00.00.0000
4580 \begin_inset LatexCommand \index{-C}
4586 Tell the preprocessor not to discard comments.
4587 Used with the `-E' option.
4589 \labelwidthstring 00.00.0000
4594 \begin_inset LatexCommand \index{-MM}
4605 Like `-M' but the output mentions only the user header files included with
4607 \begin_inset Quotes eld
4611 System header files included with `#include <file>' are omitted.
4613 \labelwidthstring 00.00.0000
4618 \begin_inset LatexCommand \index{-Aquestion(answer)}
4624 Assert the answer answer for question, in case it is tested with a preprocessor
4625 conditional such as `#if #question(answer)'.
4626 `-A-' disables the standard assertions that normally describe the target
4629 \labelwidthstring 00.00.0000
4634 \begin_inset LatexCommand \index{-Umacro}
4640 Undefine macro macro.
4641 `-U' options are evaluated after all `-D' options, but before any `-include'
4642 and `-imacros' options.
4644 \labelwidthstring 00.00.0000
4649 \begin_inset LatexCommand \index{-dM}
4655 Tell the preprocessor to output only a list of the macro definitions that
4656 are in effect at the end of preprocessing.
4657 Used with the `-E' option.
4659 \labelwidthstring 00.00.0000
4664 \begin_inset LatexCommand \index{-dD}
4670 Tell the preprocessor to pass all macro definitions into the output, in
4671 their proper sequence in the rest of the output.
4673 \labelwidthstring 00.00.0000
4678 \begin_inset LatexCommand \index{-dN}
4689 Like `-dD' except that the macro arguments and contents are omitted.
4690 Only `#define name' is included in the output.
4691 \layout Subsubsection
4694 \begin_inset LatexCommand \index{Options linker}
4699 \begin_inset LatexCommand \index{Linker options}
4705 \labelwidthstring 00.00.0000
4725 \begin_inset LatexCommand \index{-\/-lib-path}
4730 \begin_inset LatexCommand \index{-L -\/-lib-path}
4739 <absolute path to additional libraries> This option is passed to the linkage
4740 editor's additional libraries
4741 \begin_inset LatexCommand \index{Libraries}
4746 The path name must be absolute.
4747 Additional library files may be specified in the command line.
4748 See section Compiling programs for more details.
4750 \labelwidthstring 00.00.0000
4767 \begin_inset LatexCommand \index{-\/-xram-loc}
4771 <Value> The start location of the external ram
4772 \begin_inset LatexCommand \index{xdata}
4776 , default value is 0.
4777 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4787 -xram-loc 0x8000 or -
4799 \labelwidthstring 00.00.0000
4816 \begin_inset LatexCommand \index{-\/-code-loc}
4820 <Value> The start location of the code
4821 \begin_inset LatexCommand \index{code}
4825 segment, default value 0.
4826 Note when this option is used the interrupt vector table is also relocated
4827 to the given address.
4828 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4838 -code-loc 0x8000 or -
4850 \labelwidthstring 00.00.0000
4867 \begin_inset LatexCommand \index{-\/-stack-loc}
4871 <Value> By default the stack
4872 \begin_inset LatexCommand \index{stack}
4876 is placed after the data segment.
4877 Using this option the stack can be placed anywhere in the internal memory
4879 The value entered can be in Hexadecimal or Decimal format, e.g.
4890 -stack-loc 0x20 or -
4901 Since the sp register is incremented before a push or call, the initial
4902 sp will be set to one byte prior the provided value.
4903 The provided value should not overlap any other memory areas such as used
4904 register banks or the data segment and with enough space for the current
4907 \labelwidthstring 00.00.0000
4924 \begin_inset LatexCommand \index{-\/-data-loc}
4928 <Value> The start location of the internal ram data
4929 \begin_inset LatexCommand \index{data}
4934 The value entered can be in Hexadecimal or Decimal format, eg.
4956 (By default, the start location of the internal ram data segment is set
4957 as low as possible in memory, taking into account the used register banks
4958 and the bit segment at address 0x20.
4959 For example if register banks 0 and 1 are used without bit variables, the
4960 data segment will be set, if -
4970 -data-loc is not used, to location 0x10.)
4972 \labelwidthstring 00.00.0000
4989 \begin_inset LatexCommand \index{-\/-idata-loc}
4993 <Value> The start location of the indirectly addressable internal ram
4994 \begin_inset LatexCommand \index{idata}
4998 , default value is 0x80.
4999 The value entered can be in Hexadecimal or Decimal format, eg.
5010 -idata-loc 0x88 or -
5022 \labelwidthstring 00.00.0000
5037 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5046 The linker output (final object code) is in Intel Hex format.
5047 \begin_inset LatexCommand \index{Intel hex format}
5051 (This is the default option).
5053 \labelwidthstring 00.00.0000
5068 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5077 The linker output (final object code) is in Motorola S19 format
5078 \begin_inset LatexCommand \index{Motorola S19 format}
5083 \layout Subsubsection
5086 \begin_inset LatexCommand \index{Options MCS51}
5091 \begin_inset LatexCommand \index{MCS51 options}
5097 \labelwidthstring 00.00.0000
5112 \begin_inset LatexCommand \index{-\/-model-small}
5123 Generate code for Small Model programs see section Memory Models for more
5125 This is the default model.
5127 \labelwidthstring 00.00.0000
5142 \begin_inset LatexCommand \index{-\/-model-large}
5148 Generate code for Large model programs see section Memory Models for more
5150 If this option is used all source files in the project should be compiled
5153 \labelwidthstring 00.00.0000
5168 \begin_inset LatexCommand \index{-\/-xstack}
5174 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5175 variables and passing parameters.
5176 See section on external stack for more details.
5178 \labelwidthstring 00.00.0000
5195 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5199 Causes the linker to check if the internal ram usage is within limits of
5202 \labelwidthstring 00.00.0000
5219 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5223 Causes the linker to check if the external ram usage is within limits of
5226 \labelwidthstring 00.00.0000
5243 \begin_inset LatexCommand \index{-\/-data-loc}
5247 Causes the linker to check if the code memory usage is within limits of
5249 \layout Subsubsection
5252 \begin_inset LatexCommand \index{Options DS390}
5257 \begin_inset LatexCommand \index{DS390 options}
5263 \labelwidthstring 00.00.0000
5280 \begin_inset LatexCommand \index{-\/-model-flat24}
5290 Generate 24-bit flat mode code.
5291 This is the one and only that the ds390 code generator supports right now
5292 and is default when using
5297 See section Memory Models for more details.
5299 \labelwidthstring 00.00.0000
5316 \begin_inset LatexCommand \index{-\/-stack-10bit}
5320 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5321 This is the one and only that the ds390 code generator supports right now
5322 and is default when using
5327 In this mode, the stack is located in the lower 1K of the internal RAM,
5328 which is mapped to 0x400000.
5329 Note that the support is incomplete, since it still uses a single byte
5330 as the stack pointer.
5331 This means that only the lower 256 bytes of the potential 1K stack space
5332 will actually be used.
5333 However, this does allow you to reclaim the precious 256 bytes of low RAM
5334 for use for the DATA and IDATA segments.
5335 The compiler will not generate any code to put the processor into 10 bit
5337 It is important to ensure that the processor is in this mode before calling
5338 any re-entrant functions compiled with this option.
5339 In principle, this should work with the
5352 \begin_inset LatexCommand \index{-\/-stack-auto}
5358 option, but that has not been tested.
5359 It is incompatible with the
5372 \begin_inset LatexCommand \index{-\/-xstack}
5379 It also only makes sense if the processor is in 24 bit contiguous addressing
5392 -model-flat24 option
5395 \layout Subsubsection
5398 \begin_inset LatexCommand \index{Options Z80}
5403 \begin_inset LatexCommand \index{Z80 options}
5409 \labelwidthstring 00.00.0000
5426 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5436 Force a called function to always save BC.
5438 \labelwidthstring 00.00.0000
5455 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5459 When linking, skip the standard crt0.o object file.
5460 You must provide your own crt0.o for your system when linking.
5462 \layout Subsubsection
5464 Optimization Options
5465 \begin_inset LatexCommand \index{Options optimization}
5470 \begin_inset LatexCommand \index{Optimization options}
5476 \labelwidthstring 00.00.0000
5491 \begin_inset LatexCommand \index{-\/-nogcse}
5497 Will not do global subexpression elimination, this option may be used when
5498 the compiler creates undesirably large stack/data spaces to store compiler
5500 A warning message will be generated when this happens and the compiler
5501 will indicate the number of extra bytes it allocated.
5502 It recommended that this option NOT be used, #pragma\SpecialChar ~
5504 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5508 can be used to turn off global subexpression elimination
5509 \begin_inset LatexCommand \index{Subexpression elimination}
5513 for a given function only.
5515 \labelwidthstring 00.00.0000
5530 \begin_inset LatexCommand \index{-\/-noinvariant}
5536 Will not do loop invariant optimizations, this may be turned off for reasons
5537 explained for the previous option.
5538 For more details of loop optimizations performed see section Loop Invariants.It
5539 recommended that this option NOT be used, #pragma\SpecialChar ~
5541 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5545 can be used to turn off invariant optimizations for a given function only.
5547 \labelwidthstring 00.00.0000
5562 \begin_inset LatexCommand \index{-\/-noinduction}
5568 Will not do loop induction optimizations, see section strength reduction
5569 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5572 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5576 can be used to turn off induction optimizations for a given function only.
5578 \labelwidthstring 00.00.0000
5593 \begin_inset LatexCommand \index{-\/-nojtbound}
5604 Will not generate boundary condition check when switch statements
5605 \begin_inset LatexCommand \index{switch statement}
5609 are implemented using jump-tables.
5610 See section Switch Statements for more details.
5611 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5613 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5617 can be used to turn off boundary checking for jump tables for a given function
5620 \labelwidthstring 00.00.0000
5635 \begin_inset LatexCommand \index{-\/-noloopreverse}
5644 Will not do loop reversal
5645 \begin_inset LatexCommand \index{Loop reversing}
5651 \labelwidthstring 00.00.0000
5668 \begin_inset LatexCommand \index{-\/-nolabelopt }
5672 Will not optimize labels (makes the dumpfiles more readable).
5674 \labelwidthstring 00.00.0000
5689 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5695 Will not memcpy initialized data from code space into xdata space.
5696 This saves a few bytes in code space if you don't have initialized data.
5697 \layout Subsubsection
5700 \begin_inset LatexCommand \index{Options other}
5706 \labelwidthstring 00.00.0000
5722 \begin_inset LatexCommand \index{-\/-compile-only}
5727 \begin_inset LatexCommand \index{-c -\/-compile-only}
5733 will compile and assemble the source, but will not call the linkage editor.
5735 \labelwidthstring 00.00.0000
5754 \begin_inset LatexCommand \index{-\/-c1mode}
5760 reads the preprocessed source from standard input and compiles it.
5761 The file name for the assembler output must be specified using the -o option.
5763 \labelwidthstring 00.00.0000
5768 \begin_inset LatexCommand \index{-E}
5774 Run only the C preprocessor.
5775 Preprocess all the C source files specified and output the results to standard
5778 \labelwidthstring 00.00.0000
5784 \begin_inset LatexCommand \index{-o <path/file>}
5790 The output path resp.
5791 file where everything will be placed.
5792 If the parameter is a path, it must have a trailing slash (or backslash
5793 for the Windows binaries) to be recognized as a path.
5796 \labelwidthstring 00.00.0000
5811 \begin_inset LatexCommand \index{-\/-stack-auto}
5822 All functions in the source file will be compiled as
5827 \begin_inset LatexCommand \index{reentrant}
5832 the parameters and local variables will be allocated on the stack
5833 \begin_inset LatexCommand \index{stack}
5838 see section Parameters and Local Variables for more details.
5839 If this option is used all source files in the project should be compiled
5843 \labelwidthstring 00.00.0000
5858 \begin_inset LatexCommand \index{-\/-callee-saves}
5862 function1[,function2][,function3]....
5865 The compiler by default uses a caller saves convention for register saving
5866 across function calls, however this can cause unnecessary register pushing
5867 & popping when calling small functions from larger functions.
5868 This option can be used to switch the register saving convention for the
5869 function names specified.
5870 The compiler will not save registers when calling these functions, no extra
5871 code will be generated at the entry & exit (function prologue
5874 \begin_inset LatexCommand \index{function prologue}
5883 \begin_inset LatexCommand \index{function epilogue}
5889 ) for these functions to save & restore the registers used by these functions,
5890 this can SUBSTANTIALLY reduce code & improve run time performance of the
5892 In the future the compiler (with inter procedural analysis) will be able
5893 to determine the appropriate scheme to use for each function call.
5894 DO NOT use this option for built-in functions such as _mulint..., if this
5895 option is used for a library function the appropriate library function
5896 needs to be recompiled with the same option.
5897 If the project consists of multiple source files then all the source file
5898 should be compiled with the same -
5908 -callee-saves option string.
5909 Also see #pragma\SpecialChar ~
5911 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5917 \labelwidthstring 00.00.0000
5932 \begin_inset LatexCommand \index{-\/-debug}
5941 When this option is used the compiler will generate debug information, that
5942 can be used with the SDCDB.
5943 The debug information is collected in a file with .cdb extension.
5944 For more information see documentation for SDCDB.
5946 \labelwidthstring 00.00.0000
5951 \begin_inset LatexCommand \index{-S}
5962 Stop after the stage of compilation proper; do not assemble.
5963 The output is an assembler code file for the input file specified.
5965 \labelwidthstring 00.00.0000
5969 -Wa_asmOption[,asmOption]
5972 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5977 Pass the asmOption to the assembler.
5979 \labelwidthstring 00.00.0000
5983 -Wl_linkOption[,linkOption]
5986 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5991 Pass the linkOption to the linker.
5993 \labelwidthstring 00.00.0000
6008 \begin_inset LatexCommand \index{-\/-int-long-reent}
6014 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6015 Note by default these libraries are compiled as non-reentrant.
6016 See section Installation for more details.
6018 \labelwidthstring 00.00.0000
6033 \begin_inset LatexCommand \index{-\/-cyclomatic}
6042 This option will cause the compiler to generate an information message for
6043 each function in the source file.
6044 The message contains some
6048 information about the function.
6049 The number of edges and nodes the compiler detected in the control flow
6050 graph of the function, and most importantly the
6052 cyclomatic complexity
6053 \begin_inset LatexCommand \index{Cyclomatic complexity}
6059 see section on Cyclomatic Complexity for more details.
6061 \labelwidthstring 00.00.0000
6076 \begin_inset LatexCommand \index{-\/-float-reent}
6085 Floating point library is compiled as reentrant
6086 \begin_inset LatexCommand \index{reentrant}
6090 .See section Installation for more details.
6092 \labelwidthstring 00.00.0000
6107 \begin_inset LatexCommand \index{-\/-nooverlay}
6113 The compiler will not overlay parameters and local variables of any function,
6114 see section Parameters and local variables for more details.
6116 \labelwidthstring 00.00.0000
6131 \begin_inset LatexCommand \index{-\/-main-return}
6137 This option can be used when the code generated is called by a monitor
6139 The compiler will generate a 'ret' upon return from the 'main'
6140 \begin_inset LatexCommand \index{main return}
6145 The default option is to lock up i.e.
6148 \labelwidthstring 00.00.0000
6165 \begin_inset LatexCommand \index{-\/-peep-file}
6169 <filename> This option can be used to use additional rules to be used by
6170 the peep hole optimizer.
6171 See section Peep Hole optimizations for details on how to write these rules.
6173 \labelwidthstring 00.00.0000
6188 \begin_inset LatexCommand \index{-\/-no-peep}
6194 Disable peep-hole optimization.
6196 \labelwidthstring 00.00.0000
6211 \begin_inset LatexCommand \index{-\/-peep-asm}
6217 Pass the inline assembler code through the peep hole optimizer.
6218 This can cause unexpected changes to inline assembler code, please go through
6219 the peephole optimizer
6220 \begin_inset LatexCommand \index{Peephole optimizer}
6224 rules defined in the source file tree '<target>/peeph.def' before using
6227 \labelwidthstring 00.00.0000
6242 \begin_inset LatexCommand \index{-\/-nostdincl}
6248 This will prevent the compiler from passing on the default include path
6249 to the preprocessor.
6251 \labelwidthstring 00.00.0000
6266 \begin_inset LatexCommand \index{-\/-nostdlib}
6272 This will prevent the compiler from passing on the default library
6273 \begin_inset LatexCommand \index{Libraries}
6279 \labelwidthstring 00.00.0000
6294 \begin_inset LatexCommand \index{-\/-verbose}
6300 Shows the various actions the compiler is performing.
6302 \labelwidthstring 00.00.0000
6307 \begin_inset LatexCommand \index{-V}
6313 Shows the actual commands the compiler is executing.
6315 \labelwidthstring 00.00.0000
6330 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6336 Hides your ugly and inefficient c-code from the asm file, so you can always
6337 blame the compiler :).
6339 \labelwidthstring 00.00.0000
6354 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6360 Include i-codes in the asm file.
6361 Sounds like noise but is most helpful for debugging the compiler itself.
6363 \labelwidthstring 00.00.0000
6378 \begin_inset LatexCommand \index{-\/-less-pedantic}
6384 Disable some of the more pedantic warnings (jwk burps: please be more specific
6387 \labelwidthstring 00.00.0000
6402 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6408 Display the directories in the compiler's search path
6410 \labelwidthstring 00.00.0000
6425 \begin_inset LatexCommand \index{-\/-vc}
6431 Display errors and warnings using MSVC style, so you can use SDCC with
6434 \labelwidthstring 00.00.0000
6449 \begin_inset LatexCommand \index{-\/-use-stdout}
6455 Send errors and warnings to stdout instead of stderr.
6456 \layout Subsubsection
6458 Intermediate Dump Options
6459 \begin_inset LatexCommand \index{Options intermediate dump}
6464 \begin_inset LatexCommand \index{Intermediate dump options}
6471 The following options are provided for the purpose of retargetting and debugging
6473 These provided a means to dump the intermediate code (iCode
6474 \begin_inset LatexCommand \index{iCode}
6478 ) generated by the compiler in human readable form at various stages of
6479 the compilation process.
6482 \labelwidthstring 00.00.0000
6497 \begin_inset LatexCommand \index{-\/-dumpraw}
6503 This option will cause the compiler to dump the intermediate code into
6506 <source filename>.dumpraw
6508 just after the intermediate code has been generated for a function, i.e.
6509 before any optimizations are done.
6511 \begin_inset LatexCommand \index{Basic blocks}
6515 at this stage ordered in the depth first number, so they may not be in
6516 sequence of execution.
6518 \labelwidthstring 00.00.0000
6533 \begin_inset LatexCommand \index{-\/-dumpgcse}
6539 Will create a dump of iCode's, after global subexpression elimination
6540 \begin_inset LatexCommand \index{Global subexpression elimination}
6546 <source filename>.dumpgcse.
6548 \labelwidthstring 00.00.0000
6563 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6569 Will create a dump of iCode's, after deadcode elimination
6570 \begin_inset LatexCommand \index{Dead-code elimination}
6576 <source filename>.dumpdeadcode.
6578 \labelwidthstring 00.00.0000
6593 \begin_inset LatexCommand \index{-\/-dumploop}
6602 Will create a dump of iCode's, after loop optimizations
6603 \begin_inset LatexCommand \index{Loop optimization}
6609 <source filename>.dumploop.
6611 \labelwidthstring 00.00.0000
6626 \begin_inset LatexCommand \index{-\/-dumprange}
6635 Will create a dump of iCode's, after live range analysis
6636 \begin_inset LatexCommand \index{Live range analysis}
6642 <source filename>.dumprange.
6644 \labelwidthstring 00.00.0000
6659 \begin_inset LatexCommand \index{-\/-dumlrange}
6665 Will dump the life ranges
6666 \begin_inset LatexCommand \index{Live range analysis}
6672 \labelwidthstring 00.00.0000
6687 \begin_inset LatexCommand \index{-\/-dumpregassign}
6696 Will create a dump of iCode's, after register assignment
6697 \begin_inset LatexCommand \index{Register assignment}
6703 <source filename>.dumprassgn.
6705 \labelwidthstring 00.00.0000
6720 \begin_inset LatexCommand \index{-\/-dumplrange}
6726 Will create a dump of the live ranges of iTemp's
6728 \labelwidthstring 00.00.0000
6743 \begin_inset LatexCommand \index{-\/-dumpall}
6754 Will cause all the above mentioned dumps to be created.
6755 \layout Subsubsection
6757 Redirecting output on Windows Shells
6760 By default SDCC writes it's error messages to
6761 \begin_inset Quotes sld
6765 \begin_inset Quotes srd
6769 To force all messages to
6770 \begin_inset Quotes sld
6774 \begin_inset Quotes srd
6798 \begin_inset LatexCommand \index{-\/-use-stdout}
6803 Aditionaly, if you happen to have visual studio installed in your windows
6804 machine, you can use it to compile your sources using a custom build and
6820 \begin_inset LatexCommand \index{-\/-vc}
6825 Something like this should work:
6869 -model-large -c $(InputPath)
6872 Environment variables
6873 \begin_inset LatexCommand \index{Environment variables}
6880 SDCC recognizes the following environment variables:
6882 \labelwidthstring 00.00.0000
6887 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6893 SDCC installs a signal handler
6894 \begin_inset LatexCommand \index{signal handler}
6898 to be able to delete temporary files after an user break (^C) or an exception.
6899 If this environment variable is set, SDCC won't install the signal handler
6900 in order to be able to debug SDCC.
6902 \labelwidthstring 00.00.0000
6909 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
6915 Path, where temporary files will be created.
6916 The order of the variables is the search order.
6917 In a standard *nix environment these variables are not set, and there's
6918 no need to set them.
6919 On Windows it's recommended to set one of them.
6921 \labelwidthstring 00.00.0000
6926 \begin_inset LatexCommand \index{SDCC\_HOME}
6933 \begin_inset Quotes sld
6936 2.3 Install and search paths
6937 \begin_inset Quotes srd
6942 \labelwidthstring 00.00.0000
6947 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6954 \begin_inset Quotes sld
6957 2.3 Install and search paths
6958 \begin_inset Quotes srd
6963 \labelwidthstring 00.00.0000
6968 \begin_inset LatexCommand \index{SDCC\_LIB}
6975 \begin_inset Quotes sld
6978 2.3 Install and search paths
6979 \begin_inset Quotes srd
6985 There are some more environment variables recognized by SDCC, but these
6986 are solely used for debugging purposes.
6987 They can change or disappear very quickly, and will never be documented.
6990 MCS51/DS390 Storage Class
6991 \begin_inset LatexCommand \index{Storage class}
6998 In addition to the ANSI storage classes SDCC allows the following MCS51
6999 specific storage classes.
7000 \layout Subsubsection
7003 \begin_inset LatexCommand \index{data}
7014 storage class for Small Memory model.
7015 Variables declared with this storage class will be allocated in the directly
7016 addressable portion of the internal RAM of a 8051, e.g.:
7021 data unsigned char test_data;
7024 Writing 0x01 to this variable generates the assembly code:
7029 75*00 01\SpecialChar ~
7035 \layout Subsubsection
7038 \begin_inset LatexCommand \index{xdata}
7045 Variables declared with this storage class will be placed in the external
7051 storage class for Large Memory model, e.g.:
7056 xdata unsigned char test_xdata;
7059 Writing 0x01 to this variable generates the assembly code:
7064 90s00r00\SpecialChar ~
7093 \layout Subsubsection
7096 \begin_inset LatexCommand \index{idata}
7103 Variables declared with this storage class will be allocated into the indirectly
7104 addressable portion of the internal ram of a 8051, e.g.:
7109 idata unsigned char test_idata;
7112 Writing 0x01 to this variable generates the assembly code:
7139 \layout Subsubsection
7142 \begin_inset LatexCommand \index{pdata}
7149 Paged xdata access is currently not as straightforward as using the other
7150 addressing modes of a 8051.
7151 The following example writes 0x01 to the address pointed to.
7152 Please note, pdata access physically accesses xdata memory.
7153 The high byte of the address is determined by port P2 (or in case of some
7154 8051 variants by a separate Special Function Register).
7159 pdata unsigned char *test_pdata_ptr;
7171 test_pdata_ptr = (pdata *)0xfe;
7177 *test_pdata_ptr = 1;
7182 Generates the assembly code:
7187 75*01 FE\SpecialChar ~
7191 _test_pdata_ptr,#0xFE
7223 Be extremely carefull if you use pdata together with the -
7234 \begin_inset LatexCommand \index{-\/-xstack}
7239 \layout Subsubsection
7242 \begin_inset LatexCommand \index{code}
7249 'Variables' declared with this storage class will be placed in the code
7255 code unsigned char test_code;
7258 Read access to this variable generates the assembly code:
7263 90s00r6F\SpecialChar ~
7266 mov dptr,#_test_code
7289 \layout Subsubsection
7292 \begin_inset LatexCommand \index{bit}
7299 This is a data-type and a storage class specifier.
7300 When a variable is declared as a bit, it is allocated into the bit addressable
7301 memory of 8051, e.g.:
7309 Writing 1 to this variable generates the assembly code:
7323 \layout Subsubsection
7326 \begin_inset LatexCommand \index{sfr}
7331 \begin_inset LatexCommand \index{sbit}
7338 Like the bit keyword,
7342 signifies both a data-type and storage class, they are used to describe
7343 the special function registers and special bit variables of a 8051, eg:
7349 \begin_inset LatexCommand \index{at}
7353 0x80 P0;\SpecialChar ~
7354 /* special function register P0 at location 0x80 */
7356 sbit at 0xd7 CY; /* CY (Carry Flag
7357 \begin_inset LatexCommand \index{Flags}
7362 \begin_inset LatexCommand \index{Carry flag}
7367 \layout Subsubsection
7370 \begin_inset LatexCommand \index{Pointers}
7374 to MCS51/DS390 specific memory spaces
7377 SDCC allows (via language extensions) pointers to explicitly point to any
7378 of the memory spaces
7379 \begin_inset LatexCommand \index{Memory model}
7384 In addition to the explicit pointers, the compiler uses (by default) generic
7385 pointers which can be used to point to any of the memory spaces.
7389 Pointer declaration examples:
7394 /* pointer physically in xternal ram pointing to object in internal ram
7397 data unsigned char * xdata p;
7401 /* pointer physically in code rom pointing to data in xdata space */
7403 xdata unsigned char * code p;
7407 /* pointer physically in code space pointing to data in code space */
7409 code unsigned char * code p;
7413 /* the following is a generic pointer physically located in xdata space
7419 Well you get the idea.
7424 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7437 The highest order byte of the
7441 pointers contains the data space information.
7442 Assembler support routines are called whenever data is stored or retrieved
7448 These are useful for developing reusable library
7449 \begin_inset LatexCommand \index{Libraries}
7454 Explicitly specifying the pointer type will generate the most efficient
7459 \begin_inset LatexCommand \index{Absolute addressing}
7466 Data items can be assigned an absolute address with the
7469 \begin_inset LatexCommand \index{at}
7475 keyword, in addition to a storage class, e.g.:
7481 \begin_inset LatexCommand \index{xdata}
7486 \begin_inset LatexCommand \index{at}
7490 0x7ffe unsigned int chksum;
7493 In the above example the variable chksum will located at 0x7ffe and 0x7fff
7494 of the external ram.
7495 The compiler does not actually reserve any space for variables declared
7496 in this way (they are implemented with an equate in the assembler).
7497 Thus it is left to the programmer to make sure there are no overlaps with
7498 other variables that are declared without the absolute address.
7499 The assembler listing file (.lst
7500 \begin_inset LatexCommand \index{.lst}
7504 ) and the linker output files (.rst
7505 \begin_inset LatexCommand \index{.rst}
7510 \begin_inset LatexCommand \index{.map}
7514 ) are good places to look for such overlaps.
7517 In case of memory mapped I/O devices the keyword
7521 should be used to tell the compiler that accesses might not be optimized
7528 \begin_inset LatexCommand \index{volatile}
7533 \begin_inset LatexCommand \index{xdata}
7538 \begin_inset LatexCommand \index{at}
7542 0x8000 unsigned char PORTA_8255;
7545 Absolute address can be specified for variables in all storage classes,
7552 \begin_inset LatexCommand \index{bit}
7557 \begin_inset LatexCommand \index{at}
7564 The above example will allocate the variable at offset 0x02 in the bit-addressab
7566 There is no real advantage to assigning absolute addresses to variables
7567 in this manner, unless you want strict control over all the variables allocated.
7568 One possible use would be to write hardware portable code.
7569 For example, if you have a routine that uses one or more of the microcontroller
7570 I/O pins, and such pins are different for two different hardwares, you
7571 can declare the I/O pins in your routine using:
7576 extern volatile bit SDI;
7578 extern volatile bit SCLK;
7580 extern volatile bit CPOL;
7584 void DS1306_put(unsigned char value)
7592 unsigned char mask=0x80;
7616 SDI=(value & mask)?1:0;
7657 Then, someplace in the code for the first hardware you would use
7662 bit at 0x80 SDI;\SpecialChar ~
7666 /* I/O port 0, bit 0 */
7668 bit at 0x81 SCLK;\SpecialChar ~
7671 /* I/O port 0, bit 1 */
7673 bit CPOL;\SpecialChar ~
7684 /* This is a variable, let the linker allocate this one */
7687 Similarly, for the second hardware you would use
7692 bit at 0x83 SDI;\SpecialChar ~
7696 /* I/O port 0, bit 3 */
7698 bit at 0x91 SCLK;\SpecialChar ~
7701 /* I/O port 1, bit 1 */
7703 bit CPOL;\SpecialChar ~
7714 /* This is a variable, let the linker allocate this one */
7717 and you can use the same hardware dependent routine without changes, as
7718 for example in a library.
7719 This is somehow similar to sbit, but only one absolute address has to be
7720 specified in the whole project.
7724 \begin_inset LatexCommand \index{Parameters}
7729 \begin_inset LatexCommand \index{Local variable}
7736 Automatic (local) variables and parameters to functions can either be placed
7737 on the stack or in data-space.
7738 The default action of the compiler is to place these variables in the internal
7739 RAM (for small model) or external RAM (for large model).
7740 This in fact makes them
7743 \begin_inset LatexCommand \index{static}
7749 so by default functions are non-reentrant
7750 \begin_inset LatexCommand \index{reentrant}
7758 They can be placed on the stack
7759 \begin_inset LatexCommand \index{stack}
7776 \begin_inset LatexCommand \index{-\/-stack-auto}
7782 option or by using the
7785 \begin_inset LatexCommand \index{reentrant}
7791 keyword in the function declaration, e.g.:
7796 unsigned char foo(char i) reentrant
7810 Since stack space on 8051 is limited, the
7828 option should be used sparingly.
7829 Note that the reentrant keyword just means that the parameters & local
7830 variables will be allocated to the stack, it
7834 mean that the function is register bank independent.
7838 Local variables can be assigned storage classes and absolute
7839 \begin_inset LatexCommand \index{Absolute addressing}
7856 xdata unsigned char i;
7868 data at 0x31 unsigned char j;
7880 In the above example the variable
7884 will be allocated in the external ram,
7888 in bit addressable space and
7907 or when a function is declared as
7911 this should only be done for static variables.
7914 Parameters however are not allowed any storage class, (storage classes for
7915 parameters will be ignored), their allocation is governed by the memory
7916 model in use, and the reentrancy options.
7920 \begin_inset LatexCommand \label{sub:Overlaying}
7925 \begin_inset LatexCommand \index{Overlaying}
7933 \begin_inset LatexCommand \index{reentrant}
7937 functions SDCC will try to reduce internal ram space usage by overlaying
7938 parameters and local variables of a function (if possible).
7939 Parameters and local variables of a function will be allocated to an overlayabl
7940 e segment if the function has
7942 no other function calls and the function is non-reentrant and the memory
7944 \begin_inset LatexCommand \index{Memory model}
7951 If an explicit storage class
7952 \begin_inset LatexCommand \index{Storage class}
7956 is specified for a local variable, it will NOT be overlayed.
7959 Note that the compiler (not the linkage editor) makes the decision for overlayin
7961 Functions that are called from an interrupt service routine should be preceded
7962 by a #pragma\SpecialChar ~
7964 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7968 if they are not reentrant.
7971 Also note that the compiler does not do any processing of inline
7972 \begin_inset LatexCommand \index{inline}
7976 assembler code, so the compiler might incorrectly assign local variables
7977 and parameters of a function into the overlay segment if the inline assembler
7978 code calls other c-functions that might use the overlay.
7979 In that case the #pragma\SpecialChar ~
7980 NOOVERLAY should be used.
7983 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7985 \begin_inset LatexCommand \index{Multiplication}
7990 \begin_inset LatexCommand \index{Division}
7994 will NOT be overlayed since these are implemented using external functions,
8003 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8009 void set_error(unsigned char errcd)
8025 void some_isr () interrupt
8026 \begin_inset LatexCommand \index{interrupt}
8056 In the above example the parameter
8064 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8066 not present, this could cause unpredictable runtime behavior when called
8068 The #pragma\SpecialChar ~
8069 NOOVERLAY ensures that the parameters and local variables for
8070 the function are NOT overlayed.
8073 Interrupt Service Routines
8076 SDCC allows interrupt service routines to be coded in C, with some extended
8082 void timer_isr (void) interrupt 1 using 1
8096 The optional number following the
8099 \begin_inset LatexCommand \index{interrupt}
8105 keyword is the interrupt number this routine will service.
8106 When present, the compiler will insert a call to this routine in the interrupt
8107 vector table for the interrupt number specified.
8112 keyword can be used to tell the compiler to use the specified register
8113 bank (8051 specific) when generating code for this function.
8114 Note that when some function is called from an interrupt service routine
8115 it should be preceded by a #pragma\SpecialChar ~
8117 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8121 if it is not reentrant.
8122 Furthermore nonreentrant functions should not be called from the main program
8123 while the interrupt service routine might be active.
8124 If the interrupt service routines changes variables which are accessed
8125 by other functions these variables should be declared
8130 \begin_inset LatexCommand \index{volatile}
8138 A special note here, int (16 bit) and long (32 bit) integer division
8139 \begin_inset LatexCommand \index{Division}
8144 \begin_inset LatexCommand \index{Multiplication}
8149 \begin_inset LatexCommand \index{Modulus}
8153 operations are implemented using external support routines developed in
8154 ANSI-C, if an interrupt service routine needs to do any of these operations
8155 then the support routines (as mentioned in a following section) will have
8156 to be recompiled using the
8169 \begin_inset LatexCommand \index{-\/-stack-auto}
8175 option and the source file will need to be compiled using the
8190 \begin_inset LatexCommand \index{-\/-int-long-rent}
8197 If you have multiple source files in your project, interrupt service routines
8198 can be present in any of them, but a prototype of the isr MUST be present
8199 or included in the file that contains the function
8206 Interrupt numbers and the corresponding address & descriptions for the Standard
8207 8051/8052 are listed below.
8208 SDCC will automatically adjust the interrupt vector table to the maximum
8209 interrupt number specified.
8215 \begin_inset Tabular
8216 <lyxtabular version="3" rows="7" columns="3">
8218 <column alignment="center" valignment="top" leftline="true" width="0in">
8219 <column alignment="center" valignment="top" leftline="true" width="0in">
8220 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
8221 <row topline="true" bottomline="true">
8222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8247 <row topline="true">
8248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8273 <row topline="true">
8274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8299 <row topline="true">
8300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8325 <row topline="true">
8326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8351 <row topline="true">
8352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8377 <row topline="true" bottomline="true">
8378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8412 If the interrupt service routine is defined without
8415 \begin_inset LatexCommand \index{using}
8421 a register bank or with register bank 0 (using 0), the compiler will save
8422 the registers used by itself on the stack upon entry and restore them at
8423 exit, however if such an interrupt service routine calls another function
8424 then the entire register bank will be saved on the stack.
8425 This scheme may be advantageous for small interrupt service routines which
8426 have low register usage.
8429 If the interrupt service routine is defined to be using a specific register
8434 are save and restored, if such an interrupt service routine calls another
8435 function (using another register bank) then the entire register bank of
8436 the called function will be saved on the stack.
8437 This scheme is recommended for larger interrupt service routines.
8440 Calling other functions from an interrupt service routine is not recommended,
8441 avoid it if possible.
8443 For some pitfalls see section
8444 \begin_inset LatexCommand \ref{sub:Overlaying}
8448 about Overlaying and section
8449 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8453 about Functions using private banks.
8463 <TODO: this isn't implemented at all!>
8469 A special keyword may be associated with a function declaring it as
8474 SDCC will generate code to disable all interrupts upon entry to a critical
8475 function and enable them back before returning.
8476 Note that nesting critical functions may cause unpredictable results.
8502 The critical attribute maybe used with other attributes like
8508 \begin_inset LatexCommand \label{sub:Naked-Functions}
8513 \begin_inset LatexCommand \index{Naked functions}
8520 A special keyword may be associated with a function declaring it as
8523 \begin_inset LatexCommand \index{\_naked}
8534 function modifier attribute prevents the compiler from generating prologue
8535 \begin_inset LatexCommand \index{function prologue}
8540 \begin_inset LatexCommand \index{function epilogue}
8544 code for that function.
8545 This means that the user is entirely responsible for such things as saving
8546 any registers that may need to be preserved, selecting the proper register
8547 bank, generating the
8551 instruction at the end, etc.
8552 Practically, this means that the contents of the function must be written
8553 in inline assembler.
8554 This is particularly useful for interrupt functions, which can have a large
8555 (and often unnecessary) prologue/epilogue.
8556 For example, compare the code generated by these two functions:
8562 \begin_inset LatexCommand \index{volatile}
8566 data unsigned char counter;
8570 void simpleInterrupt(void) interrupt
8571 \begin_inset LatexCommand \index{interrupt}
8589 void nakedInterrupt(void) interrupt 2 _naked
8598 \begin_inset LatexCommand \index{\_asm}
8627 ; MUST explicitly include ret or reti in _naked function.
8634 \begin_inset LatexCommand \index{\_endasm}
8643 For an 8051 target, the generated simpleInterrupt looks like:
8784 whereas nakedInterrupt looks like:
8808 ; MUST explicitly include ret or reti in _naked function.
8811 The #pragma directive EXCLUDE
8812 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
8816 also allows to reduce pushing & popping the registers.
8819 While there is nothing preventing you from writing C code inside a _naked
8820 function, there are many ways to shoot yourself in the foot doing this,
8821 and it is recommended that you stick to inline assembler.
8824 Functions using private banks
8825 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
8830 \begin_inset LatexCommand \index{bank}
8840 \begin_inset LatexCommand \index{using}
8846 attribute (which tells the compiler to use a register bank other than the
8847 default bank zero) should only be applied to
8850 \begin_inset LatexCommand \index{interrupt}
8856 functions (see note 1 below).
8857 This will in most circumstances make the generated ISR code more efficient
8858 since it will not have to save registers on the stack.
8865 attribute will have no effect on the generated code for a
8869 function (but may occasionally be useful anyway
8875 possible exception: if a function is called ONLY from 'interrupt' functions
8876 using a particular bank, it can be declared with the same 'using' attribute
8877 as the calling 'interrupt' functions.
8878 For instance, if you have several ISRs using bank one, and all of them
8879 call memcpy(), it might make sense to create a specialized version of memcpy()
8880 'using 1', since this would prevent the ISR from having to save bank zero
8881 to the stack on entry and switch to bank zero before calling the function
8888 (pending: I don't think this has been done yet)
8895 function using a non-zero bank will assume that it can trash that register
8896 bank, and will not save it.
8897 Since high-priority interrupts
8898 \begin_inset LatexCommand \index{interrupt priority}
8902 can interrupt low-priority ones on the 8051 and friends, this means that
8903 if a high-priority ISR
8907 a particular bank occurs while processing a low-priority ISR
8911 the same bank, terrible and bad things can happen.
8912 To prevent this, no single register bank should be
8916 by both a high priority and a low priority ISR.
8917 This is probably most easily done by having all high priority ISRs use
8918 one bank and all low priority ISRs use another.
8919 If you have an ISR which can change priority at runtime, you're on your
8920 own: I suggest using the default bank zero and taking the small performance
8924 It is most efficient if your ISR calls no other functions.
8925 If your ISR must call other functions, it is most efficient if those functions
8926 use the same bank as the ISR (see note 1 below); the next best is if the
8927 called functions use bank zero.
8928 It is very inefficient to call a function using a different, non-zero bank
8934 \begin_inset LatexCommand \index{Startup code}
8941 The compiler inserts a call to the C routine
8943 _sdcc_external_startup()
8944 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8953 at the start of the CODE area.
8954 This routine is in the runtime library
8955 \begin_inset LatexCommand \index{Runtime library}
8960 By default this routine returns 0, if this routine returns a non-zero value,
8961 the static & global variable initialization will be skipped and the function
8962 main will be invoked.
8963 Otherwise static & global variables will be initialized before the function
8967 _sdcc_external_startup()
8969 routine to your program to override the default if you need to setup hardware
8970 or perform some other critical operation prior to static & global variable
8972 See also the compiler option
8991 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8998 Inline Assembler Code
8999 \begin_inset LatexCommand \index{Assembler routines}
9006 SDCC allows the use of in-line assembler with a few restriction as regards
9008 All labels defined within inline assembler code
9016 where nnnn is a number less than 100 (which implies a limit of utmost 100
9017 inline assembler labels
9025 It is strongly recommended that each assembly instruction (including labels)
9026 be placed in a separate line (as the example shows).
9040 \begin_inset LatexCommand \index{-\/-peep-asm}
9046 command line option is used, the inline assembler code will be passed through
9047 the peephole optimizer
9048 \begin_inset LatexCommand \index{Peephole optimizer}
9053 This might cause some unexpected changes in the inline assembler code.
9054 Please go through the peephole optimizer rules defined in file
9058 carefully before using this option.
9064 \begin_inset LatexCommand \index{\_asm}
9094 \begin_inset LatexCommand \index{\_endasm}
9101 The inline assembler code can contain any valid code understood by the assembler
9102 , this includes any assembler directives and comment lines.
9103 The compiler does not do any validation of the code within the
9113 Inline assembler code cannot reference any C-Labels, however it can reference
9115 \begin_inset LatexCommand \index{Labels}
9119 defined by the inline assembler, e.g.:
9144 ; some assembler code
9164 /* some more c code */
9166 clabel:\SpecialChar ~
9168 /* inline assembler cannot reference this label */
9180 $0003: ;label (can be reference by inline assembler only)
9192 /* some more c code */
9197 In other words inline assembly code can access labels defined in inline
9198 assembly within the scope of the function.
9199 The same goes the other way, ie.
9200 labels defines in inline assembly CANNOT be accessed by C statements.
9203 An example acessing a C variable is in section
9204 \begin_inset LatexCommand \ref{sub:Naked-Functions}
9211 Interfacing with Assembler Code
9212 \begin_inset LatexCommand \index{Assembler routines}
9217 \layout Subsubsection
9219 Global Registers used for Parameter Passing
9220 \begin_inset LatexCommand \index{Parameter passing}
9227 The compiler always uses the global registers
9230 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9235 \begin_inset LatexCommand \index{B (register)}
9244 \begin_inset LatexCommand \index{ACC}
9250 to pass the first parameter to a routine.
9251 The second parameter onwards is either allocated on the stack (for reentrant
9262 -stack-auto is used) or in data / xdata memory (depending on the memory
9265 \layout Subsubsection
9267 Assembler Routine(non-reentrant
9268 \begin_inset LatexCommand \index{reentrant}
9273 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
9280 In the following example the function c_func calls an assembler routine
9281 asm_func, which takes two parameters.
9286 extern int asm_func(unsigned char, unsigned char);
9290 int c_func (unsigned char i, unsigned char j)
9298 return asm_func(i,j);
9312 return c_func(10,9);
9317 The corresponding assembler function is:
9322 .globl _asm_func_PARM_2
9386 add a,_asm_func_PARM_2
9411 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9428 Note here that the return values are placed in 'dpl' - One byte return value,
9429 'dpl' LSB & 'dph' MSB for two byte values.
9430 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9431 b' & 'acc' for four byte values.
9434 The parameter naming convention is _<function_name>_PARM_<n>, where n is
9435 the parameter number starting from 1, and counting from the left.
9436 The first parameter is passed in
9437 \begin_inset Quotes eld
9441 \begin_inset Quotes erd
9444 for One bye parameter,
9445 \begin_inset Quotes eld
9449 \begin_inset Quotes erd
9453 \begin_inset Quotes eld
9457 \begin_inset Quotes erd
9461 \begin_inset Quotes eld
9465 \begin_inset Quotes erd
9468 for four bytes, the variable name for the second parameter will be _<function_n
9473 Assemble the assembler routine with the following command:
9480 asx8051 -losg asmfunc.asm
9487 Then compile and link the assembler routine to the C source file with the
9495 sdcc cfunc.c asmfunc.rel
9496 \layout Subsubsection
9498 Assembler Routine(reentrant
9499 \begin_inset LatexCommand \index{reentrant}
9504 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
9511 In this case the second parameter onwards will be passed on the stack, the
9512 parameters are pushed from right to left i.e.
9513 after the call the left most parameter will be on the top of the stack.
9519 extern int asm_func(unsigned char, unsigned char);
9523 int c_func (unsigned char i, unsigned char j) reentrant
9531 return asm_func(i,j);
9545 return c_func(10,9);
9550 The corresponding assembler routine is:
9656 The compiling and linking procedure remains the same, however note the extra
9657 entry & exit linkage required for the assembler code, _bp is the stack
9658 frame pointer and is used to compute the offset into the stack for parameters
9659 and local variables.
9663 \begin_inset LatexCommand \index{int (16 bit)}
9668 \begin_inset LatexCommand \index{long (32 bit)}
9675 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
9676 multiplication and modulus operations are implemented by support routines.
9677 These support routines are all developed in ANSI-C to facilitate porting
9678 to other MCUs, although some model specific assembler optimizations are
9680 The following files contain the described routines, all of them can be
9681 found in <installdir>/share/sdcc/lib.
9687 \begin_inset Tabular
9688 <lyxtabular version="3" rows="11" columns="2">
9690 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9691 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9692 <row topline="true" bottomline="true">
9693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9714 <row topline="true">
9715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9728 16 bit multiplication
9732 <row topline="true">
9733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9746 signed 16 bit division (calls _divuint)
9750 <row topline="true">
9751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9764 unsigned 16 bit division
9768 <row topline="true">
9769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9782 signed 16 bit modulus (calls _moduint)
9786 <row topline="true">
9787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9800 unsigned 16 bit modulus
9804 <row topline="true">
9805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9818 32 bit multiplication
9822 <row topline="true">
9823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9836 signed 32 division (calls _divulong)
9840 <row topline="true">
9841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9854 unsigned 32 division
9858 <row topline="true">
9859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9872 signed 32 bit modulus (calls _modulong)
9876 <row topline="true" bottomline="true">
9877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9890 unsigned 32 bit modulus
9903 Since they are compiled as
9908 \begin_inset LatexCommand \index{reentrant}
9913 \begin_inset LatexCommand \index{interrupt}
9917 service routines should not do any of the above operations.
9918 If this is unavoidable then the above routines will need to be compiled
9932 \begin_inset LatexCommand \index{-\/-stack-auto}
9938 option, after which the source program will have to be compiled with
9951 \begin_inset LatexCommand \index{-\/-int-long-rent}
9958 Notice that you don't have to call this routines directly.
9959 The compiler will use them automatically every time a integer operation
9963 Floating Point Support
9964 \begin_inset LatexCommand \index{Floating point support}
9971 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9972 floating point support routines are derived from gcc's floatlib.c and consists
9973 of the following routines:
9981 \begin_inset Tabular
9982 <lyxtabular version="3" rows="17" columns="2">
9984 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9985 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9986 <row topline="true" bottomline="true">
9987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10013 <row topline="true">
10014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10045 add floating point numbers
10049 <row topline="true">
10050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10081 subtract floating point numbers
10085 <row topline="true">
10086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10117 divide floating point numbers
10121 <row topline="true">
10122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10153 multiply floating point numbers
10157 <row topline="true">
10158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10189 convert floating point to unsigned char
10193 <row topline="true">
10194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10225 convert floating point to signed char
10229 <row topline="true">
10230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10261 convert floating point to unsigned int
10265 <row topline="true">
10266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10297 convert floating point to signed int
10301 <row topline="true">
10302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10342 convert floating point to unsigned long
10346 <row topline="true">
10347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10378 convert floating point to signed long
10382 <row topline="true">
10383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10414 convert unsigned char to floating point
10418 <row topline="true">
10419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10450 convert char to floating point number
10454 <row topline="true">
10455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10486 convert unsigned int to floating point
10490 <row topline="true">
10491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10522 convert int to floating point numbers
10526 <row topline="true">
10527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10558 convert unsigned long to floating point number
10562 <row topline="true" bottomline="true">
10563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10594 convert long to floating point number
10607 Note if all these routines are used simultaneously the data space might
10609 For serious floating point usage it is strongly recommended that the large
10611 Also notice that you don't have to call this routines directly.
10612 The compiler will use them automatically every time a floating point operation
10616 MCS51 Memory Models
10617 \begin_inset LatexCommand \index{Memory model}
10622 \begin_inset LatexCommand \index{MCS51 memory}
10629 SDCC allows two memory models for MCS51 code,
10638 Modules compiled with different memory models should
10642 be combined together or the results would be unpredictable.
10643 The library routines supplied with the compiler are compiled as both small
10645 The compiled library modules are contained in separate directories as small
10646 and large so that you can link to either set.
10650 When the large model is used all variables declared without a storage class
10651 will be allocated into the external ram, this includes all parameters and
10652 local variables (for non-reentrant
10653 \begin_inset LatexCommand \index{reentrant}
10658 When the small model is used variables without storage class are allocated
10659 in the internal ram.
10662 Judicious usage of the processor specific storage classes
10663 \begin_inset LatexCommand \index{Storage class}
10667 and the 'reentrant' function type will yield much more efficient code,
10668 than using the large model.
10669 Several optimizations are disabled when the program is compiled using the
10670 large model, it is therefore strongly recommended that the small model
10671 be used unless absolutely required.
10674 DS390 Memory Models
10675 \begin_inset LatexCommand \index{Memory model}
10680 \begin_inset LatexCommand \index{DS390 memory model}
10687 The only model supported is Flat 24
10688 \begin_inset LatexCommand \index{Flat 24 (memory model)}
10693 This generates code for the 24 bit contiguous addressing mode of the Dallas
10695 In this mode, up to four meg of external RAM or code space can be directly
10697 See the data sheets at www.dalsemi.com for further information on this part.
10701 Note that the compiler does not generate any code to place the processor
10702 into 24 bitmode (although
10706 in the ds390 libraries will do that for you).
10712 \begin_inset LatexCommand \index{Tinibios (DS390)}
10716 , the boot loader or similar code must ensure that the processor is in 24
10717 bit contiguous addressing mode before calling the SDCC startup code.
10735 option, variables will by default be placed into the XDATA segment.
10740 Segments may be placed anywhere in the 4 meg address space using the usual
10752 Note that if any segments are located above 64K, the -r flag must be passed
10753 to the linker to generate the proper segment relocations, and the Intel
10754 HEX output format must be used.
10755 The -r flag can be passed to the linker by using the option
10759 on the sdcc command line.
10760 However, currently the linker can not handle code segments > 64k.
10764 \begin_inset LatexCommand \index{Pragmas}
10771 SDCC supports the following #pragma directives.
10775 \begin_inset LatexCommand \index{\#pragma SAVE}
10779 - this will save all current options to the SAVE/RESTORE stack.
10784 \begin_inset LatexCommand \index{\#pragma RESTORE}
10788 - will restore saved options from the last save.
10789 SAVEs & RESTOREs can be nested.
10790 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
10791 RESTORE pulls current options from the stack.
10796 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10800 - will stop global common subexpression elimination.
10804 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10808 - will stop loop induction optimizations.
10812 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
10816 - will not generate code for boundary value checking, when switch statements
10817 are turned into jump-tables (dangerous).
10822 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
10826 - the compiler will not overlay the parameters and local variables of a
10831 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
10835 - the compiler will not warn you anymore for obvious mistakes, you'r on
10840 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
10844 - Will not do loop reversal optimization
10848 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10852 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
10854 \begin_inset LatexCommand \index{push/pop}
10858 instruction in ISR function (using interrupt
10859 \begin_inset LatexCommand \index{interrupt}
10864 The directive should be placed immediately before the ISR function definition
10865 and it affects ALL ISR functions following it.
10866 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
10867 EXCLUDE\SpecialChar ~
10869 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10877 \begin_inset LatexCommand \index{\#pragma NOIV}
10881 - Do not generate interrupt vector table entries for all ISR functions
10882 defined after the pragma.
10883 This is useful in cases where the interrupt vector table must be defined
10884 manually, or when there is a secondary, manually defined interrupt vector
10886 for the autovector feature of the Cypress EZ-USB FX2).
10890 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10895 \begin_inset LatexCommand \index{function prologue}
10899 function1[,function2[,function3...]] - The compiler by default uses a caller
10900 saves convention for register saving across function calls, however this
10901 can cause unnecessary register pushing & popping when calling small functions
10902 from larger functions.
10903 This option can be used to switch off the register saving convention for
10904 the function names specified.
10905 The compiler will not save registers when calling these functions, extra
10906 code need to be manually inserted at the entry & exit for these functions
10907 to save & restore the registers used by these functions, this can SUBSTANTIALLY
10908 reduce code & improve run time performance of the generated code.
10909 In the future the compiler (with inter procedural analysis) may be able
10910 to determine the appropriate scheme to use for each function call.
10921 -callee-saves command line option is used, the function names specified
10922 in #pragma\SpecialChar ~
10924 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10928 is appended to the list of functions specified in the command line.
10931 The pragma's are intended to be used to turn-off certain optimizations which
10932 might cause the compiler to generate extra stack / data space to store
10933 compiler generated temporary variables.
10934 This usually happens in large functions.
10935 Pragma directives should be used as shown in the following example, they
10936 are used to control options & optimizations for a given function; pragmas
10937 should be placed before and/or after a function, placing pragma's inside
10938 a function body could have unpredictable results.
10944 \begin_inset LatexCommand \index{\#pragma SAVE}
10955 /* save the current settings */
10958 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10967 /* turnoff global subexpression elimination */
10969 #pragma NOINDUCTION
10970 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10974 /* turn off induction optimizations */
10997 \begin_inset LatexCommand \index{\#pragma RESTORE}
11001 /* turn the optimizations back on */
11004 The compiler will generate a warning message when extra space is allocated.
11005 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11006 changing options for a function.
11009 Defines Created by the Compiler
11010 \begin_inset LatexCommand \index{Defines created by the compiler}
11017 The compiler creates the following #defines
11018 \begin_inset LatexCommand \index{\#defines}
11028 \begin_inset Tabular
11029 <lyxtabular version="3" rows="10" columns="2">
11031 <column alignment="center" valignment="top" leftline="true" width="0(null)">
11032 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
11033 <row topline="true" bottomline="true">
11034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11055 <row topline="true">
11056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11062 \begin_inset LatexCommand \index{SDCC}
11069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11074 this Symbol is always defined
11078 <row topline="true">
11079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11085 \begin_inset LatexCommand \index{SDCC\_mcs51}
11090 \begin_inset LatexCommand \index{SDCC\_ds390}
11095 \begin_inset LatexCommand \index{SDCC\_z80}
11102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11107 depending on the model used (e.g.: -mds390
11111 <row topline="true">
11112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11118 \begin_inset LatexCommand \index{\_\_mcs51}
11123 \begin_inset LatexCommand \index{\_\_ds390}
11128 \begin_inset LatexCommand \index{\_\_z80}
11135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11140 depending on the model used (e.g.
11145 <row topline="true">
11146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11152 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
11159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11182 <row topline="true">
11183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11189 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
11196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11219 <row topline="true">
11220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11226 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
11233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11256 <row topline="true">
11257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11263 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
11270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11293 <row topline="true">
11294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11300 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
11307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11320 <row topline="true" bottomline="true">
11321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11327 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
11334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11356 Debugging with SDCDB
11357 \begin_inset LatexCommand \index{sdcdb}
11364 SDCC is distributed with a source level debugger
11365 \begin_inset LatexCommand \index{Debugger}
11370 The debugger uses a command line interface, the command repertoire of the
11371 debugger has been kept as close to gdb
11372 \begin_inset LatexCommand \index{gdb}
11376 (the GNU debugger) as possible.
11377 The configuration and build process is part of the standard compiler installati
11378 on, which also builds and installs the debugger in the target directory
11379 specified during configuration.
11380 The debugger allows you debug BOTH at the C source and at the ASM source
11382 Sdcdb is available on Unix platforms only.
11385 Compiling for Debugging
11388 The \SpecialChar \-
11390 debug option must be specified for all files for which debug information
11391 is to be generated.
11392 The complier generates a .adb file for each of these files.
11393 The linker creates the .cdb file from the .adb files and the address information.
11394 This .cdb is used by the debugger.
11397 How the Debugger Works
11410 -debug option is specified the compiler generates extra symbol information
11411 some of which are put into the the assembler source and some are put into
11413 Then the linker creates the .cdb file from the individual .adb files with
11414 the address information for the symbols.
11415 The debugger reads the symbolic information generated by the compiler &
11416 the address information generated by the linker.
11417 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
11418 execution is controlled by the debugger.
11419 When a command is issued for the debugger, it translates it into appropriate
11420 commands for the simulator.
11423 Starting the Debugger
11426 The debugger can be started using the following command line.
11427 (Assume the file you are debugging has the file name foo).
11441 The debugger will look for the following files.
11444 foo.c - the source file.
11447 foo.cdb - the debugger symbol information file.
11450 foo.ihx - the Intel hex format
11451 \begin_inset LatexCommand \index{Intel hex format}
11458 Command Line Options.
11471 -directory=<source file directory> this option can used to specify the directory
11473 The debugger will look into the directory list specified for source, cdb
11475 The items in the directory list must be separated by ':', e.g.
11476 if the source files can be in the directories /home/src1 and /home/src2,
11487 -directory option should be -
11497 -directory=/home/src1:/home/src2.
11498 Note there can be no spaces in the option.
11502 -cd <directory> - change to the <directory>.
11505 -fullname - used by GUI front ends.
11508 -cpu <cpu-type> - this argument is passed to the simulator please see the
11509 simulator docs for details.
11512 -X <Clock frequency > this options is passed to the simulator please see
11513 the simulator docs for details.
11516 -s <serial port file> passed to simulator see the simulator docs for details.
11519 -S <serial in,out> passed to simulator see the simulator docs for details.
11525 As mentioned earlier the command interface for the debugger has been deliberatel
11526 y kept as close the GNU debugger gdb, as possible.
11527 This will help the integration with existing graphical user interfaces
11528 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
11529 If you use a graphical user interface for the debugger you can skip the
11531 \layout Subsubsection*
11533 break [line | file:line | function | file:function]
11536 Set breakpoint at specified line or function:
11545 sdcdb>break foo.c:100
11547 sdcdb>break funcfoo
11549 sdcdb>break foo.c:funcfoo
11550 \layout Subsubsection*
11552 clear [line | file:line | function | file:function ]
11555 Clear breakpoint at specified line or function:
11564 sdcdb>clear foo.c:100
11566 sdcdb>clear funcfoo
11568 sdcdb>clear foo.c:funcfoo
11569 \layout Subsubsection*
11574 Continue program being debugged, after breakpoint.
11575 \layout Subsubsection*
11580 Execute till the end of the current function.
11581 \layout Subsubsection*
11586 Delete breakpoint number 'n'.
11587 If used without any option clear ALL user defined break points.
11588 \layout Subsubsection*
11590 info [break | stack | frame | registers ]
11593 info break - list all breakpoints
11596 info stack - show the function call stack.
11599 info frame - show information about the current execution frame.
11602 info registers - show content of all registers.
11603 \layout Subsubsection*
11608 Step program until it reaches a different source line.
11609 \layout Subsubsection*
11614 Step program, proceeding through subroutine calls.
11615 \layout Subsubsection*
11620 Start debugged program.
11621 \layout Subsubsection*
11626 Print type information of the variable.
11627 \layout Subsubsection*
11632 print value of variable.
11633 \layout Subsubsection*
11638 load the given file name.
11639 Note this is an alternate method of loading file for debugging.
11640 \layout Subsubsection*
11645 print information about current frame.
11646 \layout Subsubsection*
11651 Toggle between C source & assembly source.
11652 \layout Subsubsection*
11654 ! simulator command
11657 Send the string following '!' to the simulator, the simulator response is
11659 Note the debugger does not interpret the command being sent to the simulator,
11660 so if a command like 'go' is sent the debugger can loose its execution
11661 context and may display incorrect values.
11662 \layout Subsubsection*
11669 My name is Bobby Brown"
11672 Interfacing with XEmacs
11673 \begin_inset LatexCommand \index{XEmacs}
11678 \begin_inset LatexCommand \index{Emacs}
11685 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
11686 sdcdb.el and sdcdbsrc.el.
11687 These two files can be found in the $(prefix)/bin directory after the installat
11689 These files need to be loaded into XEmacs for the interface to work.
11690 This can be done at XEmacs startup time by inserting the following into
11691 your '.xemacs' file (which can be found in your HOME directory):
11697 (load-file sdcdbsrc.el)
11703 .xemacs is a lisp file so the () around the command is REQUIRED.
11704 The files can also be loaded dynamically while XEmacs is running, set the
11705 environment variable 'EMACSLOADPATH' to the installation bin directory
11706 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
11707 To start the interface enter the following command:
11721 You will prompted to enter the file name to be debugged.
11726 The command line options that are passed to the simulator directly are bound
11727 to default values in the file sdcdbsrc.el.
11728 The variables are listed below, these values maybe changed as required.
11731 sdcdbsrc-cpu-type '51
11734 sdcdbsrc-frequency '11059200
11737 sdcdbsrc-serial nil
11740 The following is a list of key mapping for the debugger interface.
11748 ;; Current Listing ::
11750 ;;key\SpecialChar ~
11765 binding\SpecialChar ~
11789 ;;---\SpecialChar ~
11804 ------\SpecialChar ~
11844 sdcdb-next-from-src\SpecialChar ~
11870 sdcdb-back-from-src\SpecialChar ~
11896 sdcdb-cont-from-src\SpecialChar ~
11906 SDCDB continue command
11922 sdcdb-step-from-src\SpecialChar ~
11948 sdcdb-whatis-c-sexp\SpecialChar ~
11958 SDCDB ptypecommand for data at
12022 sdcdbsrc-delete\SpecialChar ~
12036 SDCDB Delete all breakpoints if no arg
12084 given or delete arg (C-u arg x)
12100 sdcdbsrc-frame\SpecialChar ~
12115 SDCDB Display current frame if no arg,
12164 given or display frame arg
12229 sdcdbsrc-goto-sdcdb\SpecialChar ~
12239 Goto the SDCDB output buffer
12255 sdcdb-print-c-sexp\SpecialChar ~
12266 SDCDB print command for data at
12330 sdcdbsrc-goto-sdcdb\SpecialChar ~
12340 Goto the SDCDB output buffer
12356 sdcdbsrc-mode\SpecialChar ~
12372 Toggles Sdcdbsrc mode (turns it off)
12376 ;; C-c C-f\SpecialChar ~
12384 sdcdb-finish-from-src\SpecialChar ~
12392 SDCDB finish command
12396 ;; C-x SPC\SpecialChar ~
12404 sdcdb-break\SpecialChar ~
12422 Set break for line with point
12424 ;; ESC t\SpecialChar ~
12434 sdcdbsrc-mode\SpecialChar ~
12450 Toggle Sdcdbsrc mode
12452 ;; ESC m\SpecialChar ~
12462 sdcdbsrc-srcmode\SpecialChar ~
12484 Here are a few guidelines that will help the compiler generate more efficient
12485 code, some of the tips are specific to this compiler others are generally
12486 good programming practice.
12489 Use the smallest data type to represent your data-value.
12490 If it is known in advance that the value is going to be less than 256 then
12491 use an 'unsigned char' instead of a 'short' or 'int'.
12494 Use unsigned when it is known in advance that the value is not going to
12496 This helps especially if you are doing division or multiplication.
12499 NEVER jump into a LOOP.
12502 Declare the variables to be local whenever possible, especially loop control
12503 variables (induction).
12506 Since the compiler does not always do implicit integral promotion, the programme
12507 r should do an explicit cast when integral promotion is required.
12510 Reducing the size of division, multiplication & modulus operations can reduce
12511 code size substantially.
12512 Take the following code for example.
12518 foobar(unsigned int p1, unsigned char ch)
12526 unsigned char ch1 = p1 % ch ;
12537 For the modulus operation the variable ch will be promoted to unsigned int
12538 first then the modulus operation will be performed (this will lead to a
12539 call to support routine _moduint()), and the result will be casted to a
12541 If the code is changed to
12546 foobar(unsigned int p1, unsigned char ch)
12554 unsigned char ch1 = (unsigned char)p1 % ch ;
12565 It would substantially reduce the code generated (future versions of the
12566 compiler will be smart enough to detect such optimization opportunities).
12570 Have a look at the assembly listing to get a
12571 \begin_inset Quotes sld
12575 \begin_inset Quotes srd
12578 for the code generation.
12581 Notes on MCS51 memory
12582 \begin_inset LatexCommand \index{MCS51 memory}
12589 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12590 RAM memory which is structured as follows
12594 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12597 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12599 - Bytes 30-7F - 80 bytes for general purpose use.
12604 Additionally some members of the MCS51 family may have up to 128 bytes of
12605 additional, indirectly addressable, internal RAM memory (
12610 Furthermore, some chips may have some built in external memory (
12614 ) which should not be confused with the internal, directly addressable RAM
12620 Sometimes this built in
12624 memory has to be activated before using it (you can probably find this
12625 information on the datasheet of the microcontroller your are using).
12628 Normally SDCC will only use the first bank
12629 \begin_inset LatexCommand \index{bank}
12633 of registers (register bank 0), but it is possible to specify that other
12634 banks of registers should be used in interrupt
12635 \begin_inset LatexCommand \index{interrupt}
12640 By default, the compiler will place the stack after the last byte of allocated
12641 memory for variables.
12642 For example, if the first 2 banks of registers are used, and only four
12647 variables, it will position the base of the internal stack at address 20
12649 This implies that as the stack
12650 \begin_inset LatexCommand \index{stack}
12654 grows, it will use up the remaining register banks, and the 16 bytes used
12655 by the 128 bit variables, and 80 bytes for general purpose use.
12656 If any bit variables are used, the data variables will be placed after
12657 the byte holding the last bit variable.
12658 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12663 variables will be placed starting at address 0x22.
12675 \begin_inset LatexCommand \index{-\/-data-loc}
12679 to specify the start address of the
12693 -iram-size to specify the size of the total internal RAM (
12705 By default the 8051 linker will place the stack after the last byte of data
12718 \begin_inset LatexCommand \index{-\/-stack-loc}
12722 allows you to specify the start of the stack, i.e.
12723 you could start it after any data in the general purpose area.
12724 If your microcontroller has additional indirectly addressable internal
12729 ) you can place the stack on it.
12730 You may also need to use -
12741 \begin_inset LatexCommand \index{-\/-data-loc}
12745 to set the start address of the external RAM (
12760 \begin_inset LatexCommand \index{-\/-data-loc}
12764 to specify its size.
12765 Same goes for the code memory, using -
12776 \begin_inset LatexCommand \index{-\/-data-loc}
12791 \begin_inset LatexCommand \index{-\/-data-loc}
12796 If in doubt, don't specify any options and see if the resulting memory
12797 layout is appropriate, then you can adjust it.
12800 The 8051 linker generates two files with memory allocation information.
12801 The first, with extension .map shows all the variables and segments.
12802 The second with extension .mem shows the final memory layout.
12803 The linker will complaint either if memory segments overlap, there is not
12804 enough memory, or there is not enough space for stack.
12805 If you get any linking warnings and/or errors related to stack or segments
12806 allocation, take a look at either the .map or .mem files to find out what
12808 The .mem file may even suggest a solution to the problem.
12812 \begin_inset LatexCommand \index{Tools}
12816 included in the distribution
12820 \begin_inset Tabular
12821 <lyxtabular version="3" rows="12" columns="3">
12823 <column alignment="center" valignment="top" leftline="true" width="0pt">
12824 <column alignment="center" valignment="top" leftline="true" width="0pt">
12825 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12826 <row topline="true" bottomline="true">
12827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12852 <row topline="true">
12853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12866 Simulator for various architectures
12869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12878 <row topline="true">
12879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12892 header file conversion
12895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12900 sdcc/support/scripts
12904 <row topline="true">
12905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12918 header file conversion
12921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12926 sdcc/support/scripts
12930 <row topline="true">
12931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12965 <row topline="true">
12966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13000 <row topline="true">
13001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13035 <row topline="true">
13036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13070 <row topline="true">
13071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13105 <row topline="true">
13106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13140 <row topline="true">
13141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13175 <row topline="true" bottomline="true">
13176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13219 Related open source tools
13220 \begin_inset LatexCommand \index{Related tools}
13228 \begin_inset Tabular
13229 <lyxtabular version="3" rows="8" columns="3">
13231 <column alignment="center" valignment="top" leftline="true" width="0pt">
13232 <column alignment="block" valignment="top" leftline="true" width="30line%">
13233 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13234 <row topline="true" bottomline="true">
13235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13260 <row topline="true">
13261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13267 \begin_inset LatexCommand \index{gpsim}
13274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13288 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13296 <row topline="true">
13297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13319 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
13327 <row topline="true">
13328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13334 \begin_inset LatexCommand \index{srecord}
13341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13346 Object file conversion, checksumming, ...
13349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13355 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13363 <row topline="true">
13364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13370 \begin_inset LatexCommand \index{objdump}
13377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13382 Object file conversion, ...
13385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13390 Part of binutils (should be there anyway)
13394 <row topline="true">
13395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13401 \begin_inset LatexCommand \index{doxygen}
13408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13413 Source code documentation system
13416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13422 \begin_inset LatexCommand \url{http://www.doxygen.org}
13430 <row topline="true">
13431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13437 \begin_inset LatexCommand \index{splint}
13444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13449 Statically checks c sources
13452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13458 \begin_inset LatexCommand \url{http://www.splint.org}
13466 <row topline="true" bottomline="true">
13467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13473 \begin_inset LatexCommand \index{ddd}
13480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13485 Debugger, serves nicely as GUI to sdcdb
13486 \begin_inset LatexCommand \index{sdcdb}
13493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13499 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13516 Related documentation / recommended reading
13520 \begin_inset Tabular
13521 <lyxtabular version="3" rows="5" columns="3">
13523 <column alignment="center" valignment="top" leftline="true" width="0pt">
13524 <column alignment="block" valignment="top" leftline="true" width="30line%">
13525 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13526 <row topline="true" bottomline="true">
13527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13552 <row topline="true">
13553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13568 Advanced Compiler Design and Implementation
13571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13580 <row topline="true">
13581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13604 \begin_inset LatexCommand \index{C Reference card}
13611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13617 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13625 <row topline="true">
13626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13631 test_suite_spec.pdf
13634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13639 sdcc regression test
13640 \begin_inset LatexCommand \index{Regression test}
13647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13656 <row topline="true" bottomline="true">
13657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13688 sdcc internal documentation
13691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13710 \begin_inset LatexCommand \index{Support}
13717 SDCC has grown to be a large project.
13718 The compiler alone (without the preprocessor, assembler and linker) is
13719 about 40,000 lines of code (blank stripped).
13720 The open source nature of this project is a key to its continued growth
13722 You gain the benefit and support of many active software developers and
13724 Is SDCC perfect? No, that's why we need your help.
13725 The developers take pride in fixing reported bugs.
13726 You can help by reporting the bugs and helping other SDCC users.
13727 There are lots of ways to contribute, and we encourage you to take part
13728 in making SDCC a great software package.
13732 The SDCC project is hosted on the sdcc sourceforge site at
13733 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
13738 You'll find the complete set of mailing lists
13739 \begin_inset LatexCommand \index{Mailing list}
13743 , forums, bug reporting system, patch submission
13744 \begin_inset LatexCommand \index{Patch submission}
13749 \begin_inset LatexCommand \index{download}
13753 area and cvs code repository
13754 \begin_inset LatexCommand \index{cvs code repository}
13762 \begin_inset LatexCommand \index{Bugs}
13767 \begin_inset LatexCommand \index{Reporting bugs}
13774 The recommended way of reporting bugs is using the infrastructure of the
13776 You can follow the status of bug reports there and have an overview about
13780 Bug reports are automatically forwarded to the developer mailing list and
13781 will be fixed ASAP.
13782 When reporting a bug, it is very useful to include a small test program
13783 (the smaller the better) which reproduces the problem.
13784 If you can isolate the problem by looking at the generated assembly code,
13785 this can be very helpful.
13786 Compiling your program with the -
13797 \begin_inset LatexCommand \index{-\/-dumpall}
13801 option can sometimes be useful in locating optimization problems.
13802 When reporting a bug please maker sure you:
13805 Attach the code you are compiling with SDCC.
13809 Specify the exact command you use to run SDCC, or attach your Makefile.
13813 Specify the SDCC version (type "sdcc -v"), your platform, and operating
13818 Provide an exact copy of any error message or incorrect output.
13822 Put something meaningful in the subject of your message.
13825 Please attempt to include these 5 important parts, as applicable, in all
13826 requests for support or when reporting any problems or bugs with SDCC.
13827 Though this will make your message lengthy, it will greatly improve your
13828 chance that SDCC users and developers will be able to help you.
13829 Some SDCC developers are frustrated by bug reports without code provided
13830 that they can use to reproduce and ultimately fix the problem, so please
13831 be sure to provide sample code if you are reporting a bug!
13834 Please have a short check that you are using a recent version of SDCC and
13835 the bug is not yet known.
13836 This is the link for reporting bugs:
13837 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
13844 Requesting Features
13845 \begin_inset LatexCommand \label{sub:Requesting-Features}
13850 \begin_inset LatexCommand \index{Feature request}
13855 \begin_inset LatexCommand \index{Requesting features}
13862 Like bug reports feature requests are forwarded to the developer mailing
13864 This is the link for requesting features:
13865 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
13875 These links should take you directly to the
13876 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
13886 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
13887 automated messages (mid 2003)
13891 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
13895 , lists and forums are archived so if you are lucky someone already had
13900 \begin_inset LatexCommand \index{Changelog}
13907 You can follow the status of the cvs version
13908 \begin_inset LatexCommand \index{version}
13912 of SDCC by watching the file
13913 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
13917 in the cvs-repository.
13921 \begin_inset LatexCommand \index{Release policy}
13928 Historically there often were long delays between official releases and
13929 the sourceforge download area tends to get not updated at all.
13930 Current excuses might refer to problems with live range analysis, but if
13931 this is fixed, the next problem rising is that another excuse will have
13933 Kidding aside, we have to get better there! On the other hand there are
13934 daily snapshots available at
13935 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
13939 , and you can always built the very last version (hopefully with many bugs
13940 fixed, and features added) from the source code available at
13941 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
13949 \begin_inset LatexCommand \index{Examples}
13956 You'll find some small examples in the directory sdcc/device/examples/
13959 Maybe we should include some links to real world applications.
13960 Preferably pointer to pointers (one for each architecture) so this stays
13965 \begin_inset LatexCommand \index{Quality control}
13972 The compiler is passed through nightly compile and build checks.
13978 \begin_inset LatexCommand \index{Regression test}
13982 check that SDCC itself compiles flawlessly on several platforms and checks
13983 the quality of the code generated by SDCC by running the code through simulator
13985 There is a separate document
13988 \begin_inset LatexCommand \index{Test suite}
13997 You'll find the test code in the directory
13999 sdcc/support/regression
14002 You can run these tests manually by running
14006 in this directory (or f.e.
14011 if you don't want to run the complete tests).
14012 The test code might also be interesting if you want to look for examples
14013 \begin_inset LatexCommand \index{Examples}
14017 checking corner cases of SDCC or if you plan to submit patches
14018 \begin_inset LatexCommand \index{Patch submission}
14025 The pic port uses a different set of regression tests, you'll find them
14028 sdcc/src/regression
14033 SDCC Technical Data
14037 \begin_inset LatexCommand \index{Optimizations}
14044 SDCC performs a host of standard optimizations in addition to some MCU specific
14047 \layout Subsubsection
14049 Sub-expression Elimination
14050 \begin_inset LatexCommand \index{Subexpression elimination}
14057 The compiler does local and global common subexpression elimination, e.g.:
14068 will be translated to
14080 Some subexpressions are not as obvious as the above example, e.g.:
14090 In this case the address arithmetic a->b[i] will be computed only once;
14091 the equivalent code in C would be.
14103 The compiler will try to keep these temporary variables in registers.
14104 \layout Subsubsection
14106 Dead-Code Elimination
14107 \begin_inset LatexCommand \index{Dead-code elimination}
14128 i = 1; \SpecialChar ~
14137 global = 1;\SpecialChar ~
14150 global = 3;\SpecialChar ~
14176 \layout Subsubsection
14179 \begin_inset LatexCommand \index{Copy propagation}
14235 Note: the dead stores created by this copy propagation will be eliminated
14236 by dead-code elimination.
14237 \layout Subsubsection
14240 \begin_inset LatexCommand \index{Loop optimization}
14247 Two types of loop optimizations are done by SDCC loop invariant lifting
14248 and strength reduction of loop induction variables.
14249 In addition to the strength reduction the optimizer marks the induction
14250 variables and the register allocator tries to keep the induction variables
14251 in registers for the duration of the loop.
14252 Because of this preference of the register allocator
14253 \begin_inset LatexCommand \index{Register allocation}
14257 , loop induction optimization causes an increase in register pressure, which
14258 may cause unwanted spilling of other temporary variables into the stack
14259 \begin_inset LatexCommand \index{stack}
14264 The compiler will generate a warning message when it is forced to allocate
14265 extra space either on the stack or data space.
14266 If this extra space allocation is undesirable then induction optimization
14267 can be eliminated either for the entire source file (with -
14277 -noinduction option) or for a given function only using #pragma\SpecialChar ~
14279 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
14292 for (i = 0 ; i < 100 ; i ++)
14308 for (i = 0; i < 100; i++)
14317 As mentioned previously some loop invariants are not as apparent, all static
14318 address computations are also moved out of the loop.
14323 \begin_inset LatexCommand \index{Strength reduction}
14327 , this optimization substitutes an expression by a cheaper expression:
14332 for (i=0;i < 100; i++)
14350 for (i=0;i< 100;i++) {
14356 ar[itemp1] = itemp2;
14373 The more expensive multiplication
14374 \begin_inset LatexCommand \index{Multiplication}
14378 is changed to a less expensive addition.
14379 \layout Subsubsection
14382 \begin_inset LatexCommand \index{Loop reversing}
14389 This optimization is done to reduce the overhead of checking loop boundaries
14390 for every iteration.
14391 Some simple loops can be reversed and implemented using a
14392 \begin_inset Quotes eld
14395 decrement and jump if not zero
14396 \begin_inset Quotes erd
14400 SDCC checks for the following criterion to determine if a loop is reversible
14401 (note: more sophisticated compilers use data-dependency analysis to make
14402 this determination, SDCC uses a more simple minded analysis).
14405 The 'for' loop is of the form
14411 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
14421 The <for body> does not contain
14422 \begin_inset Quotes eld
14426 \begin_inset Quotes erd
14430 \begin_inset Quotes erd
14436 All goto's are contained within the loop.
14439 No function calls within the loop.
14442 The loop control variable <sym> is not assigned any value within the loop
14445 The loop control variable does NOT participate in any arithmetic operation
14449 There are NO switch statements in the loop.
14450 \layout Subsubsection
14452 Algebraic Simplifications
14455 SDCC does numerous algebraic simplifications, the following is a small sub-set
14456 of these optimizations.
14461 i = j + 0 ; /* changed to */ i = j;
14463 i /= 2;\SpecialChar ~
14467 /* changed to */ i >>= 1;
14469 i = j - j ; /* changed to */ i = 0;
14471 i = j / 1 ; /* changed to */ i = j;
14474 Note the subexpressions
14475 \begin_inset LatexCommand \index{Subexpression}
14479 given above are generally introduced by macro expansions or as a result
14480 of copy/constant propagation.
14481 \layout Subsubsection
14483 'switch' Statements
14484 \begin_inset LatexCommand \index{switch statement}
14491 SDCC changes switch statements to jump tables
14492 \begin_inset LatexCommand \index{jump tables}
14496 when the following conditions are true.
14500 The case labels are in numerical sequence, the labels need not be in order,
14501 and the starting number need not be one or zero.
14507 switch(i) {\SpecialChar ~
14538 case 4: ...\SpecialChar ~
14570 case 5: ...\SpecialChar ~
14602 case 3: ...\SpecialChar ~
14634 case 6: ...\SpecialChar ~
14702 Both the above switch statements will be implemented using a jump-table.
14703 The example to the right side is slightly more efficient as the check for
14704 the lower bound of the jump-table is not needed.
14708 The number of case labels is at least three, since it takes two conditional
14709 statements to handle the boundary conditions.
14712 The number of case labels is less than 84, since each label takes 3 bytes
14713 and a jump-table can be utmost 256 bytes long.
14716 Switch statements which have gaps in the numeric sequence or those that
14717 have more that 84 case labels can be split into more than one switch statement
14718 for efficient code generation, e.g.:
14768 If the above switch statement is broken down into two switch statements
14807 case 9: \SpecialChar ~
14823 case 12:\SpecialChar ~
14830 then both the switch statements will be implemented using jump-tables whereas
14831 the unmodified switch statement will not be.
14832 You might also consider dummy cases 0 and 5 to 8 in this example.
14833 The pragma NOJTBOUND
14834 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
14838 can be used to turn off checking the
14851 \layout Subsubsection
14853 Bit-shifting Operations
14854 \begin_inset LatexCommand \index{Bit shifting}
14861 Bit shifting is one of the most frequently used operation in embedded programmin
14863 SDCC tries to implement bit-shift operations in the most efficient way
14879 generates the following code:
14893 In general SDCC will never setup a loop if the shift count is known.
14935 Note that SDCC stores numbers in little-endian format (i.e.
14936 lowest order first).
14937 \layout Subsubsection
14940 \begin_inset LatexCommand \index{Bit rotation}
14947 A special case of the bit-shift operation is bit rotation, SDCC recognizes
14948 the following expression to be a left bit-rotation:
14958 i = ((i << 1) | (i >> 7));
14967 will generate the following code:
14986 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
14987 ns of this case will also be recognized as bit-rotation, i.e.:
14992 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
14993 \layout Subsubsection
14996 \begin_inset LatexCommand \index{Highest Order Bit}
15003 It is frequently required to obtain the highest order bit of an integral
15004 type (long, int, short or char types).
15005 SDCC recognizes the following expression to yield the highest order bit
15006 and generates optimized code for it, e.g.:
15028 hob = (gint >> 15) & 1;
15038 will generate the following code:
15071 000A E5*01\SpecialChar ~
15098 000C 23\SpecialChar ~
15129 000D 54 01\SpecialChar ~
15156 000F F5*02\SpecialChar ~
15184 Variations of this case however will
15189 It is a standard C expression, so I heartily recommend this be the only
15190 way to get the highest order bit, (it is portable).
15191 Of course it will be recognized even if it is embedded in other expressions,
15197 xyz = gint + ((gint >> 15) & 1);
15200 will still be recognized.
15201 \layout Subsubsection
15204 \begin_inset LatexCommand \index{Peephole optimizer}
15211 The compiler uses a rule based, pattern matching and re-writing mechanism
15212 for peep-hole optimization.
15217 a peep-hole optimizer by Christopher W.
15218 Fraser (cwfraser@microsoft.com).
15219 A default set of rules are compiled into the compiler, additional rules
15220 may be added with the
15233 \begin_inset LatexCommand \index{-\/-peep-file}
15240 The rule language is best illustrated with examples.
15264 The above rule will change the following assembly
15265 \begin_inset LatexCommand \index{Assembler routines}
15287 Note: All occurrences of a
15291 (pattern variable) must denote the same string.
15292 With the above rule, the assembly sequence:
15302 will remain unmodified.
15306 Other special case optimizations may be added by the user (via
15322 some variants of the 8051 MCU allow only
15331 The following two rules will change all
15350 replace { lcall %1 } by { acall %1 }
15352 replace { ljmp %1 } by { ajmp %1 }
15357 inline-assembler code
15359 is also passed through the peep hole optimizer, thus the peephole optimizer
15360 can also be used as an assembly level macro expander.
15361 The rules themselves are MCU dependent whereas the rule language infra-structur
15362 e is MCU independent.
15363 Peephole optimization rules for other MCU can be easily programmed using
15368 The syntax for a rule is as follows:
15373 rule := replace [ restart ] '{' <assembly sequence> '
15411 <assembly sequence> '
15429 '}' [if <functionName> ] '
15434 <assembly sequence> := assembly instruction (each instruction including
15435 labels must be on a separate line).
15439 The optimizer will apply to the rules one by one from the top in the sequence
15440 of their appearance, it will terminate when all rules are exhausted.
15441 If the 'restart' option is specified, then the optimizer will start matching
15442 the rules again from the top, this option for a rule is expensive (performance)
15443 , it is intended to be used in situations where a transformation will trigger
15444 the same rule again.
15445 An example of this (not a good one, it has side effects) is the following
15468 Note that the replace pattern cannot be a blank, but can be a comment line.
15469 Without the 'restart' option only the inner most 'pop' 'push' pair would
15470 be eliminated, i.e.:
15500 the restart option the rule will be applied again to the resulting code
15501 and then all the pop-push pairs will be eliminated to yield:
15511 A conditional function can be attached to a rule.
15512 Attaching rules are somewhat more involved, let me illustrate this with
15539 The optimizer does a look-up of a function name table defined in function
15544 in the source file SDCCpeeph.c, with the name
15549 If it finds a corresponding entry the function is called.
15550 Note there can be no parameters specified for these functions, in this
15555 is crucial, since the function
15559 expects to find the label in that particular variable (the hash table containin
15560 g the variable bindings is passed as a parameter).
15561 If you want to code more such functions, take a close look at the function
15562 labelInRange and the calling mechanism in source file SDCCpeeph.c.
15563 Currently implemented are
15565 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
15566 24bitMode, portIsDS390, 24bitModeAndPortDS390
15575 I know this whole thing is a little kludgey, but maybe some day we will
15576 have some better means.
15577 If you are looking at this file, you will see the default rules that are
15578 compiled into the compiler, you can add your own rules in the default set
15579 there if you get tired of specifying the -
15599 <pending: this is messy and incomplete>
15604 Compiler support routines (_gptrget, _mulint etc)
15607 Stdclib functions (puts, printf, strcat etc)
15610 Math functions (sin, pow, sqrt etc)
15614 \begin_inset LatexCommand \index{Libraries}
15618 included in SDCC should have a license at least as liberal as the GNU Lesser
15619 General Public License
15620 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15631 license statements for the libraries are missing.
15632 sdcc/device/lib/ser_ir.c f.e.
15633 comes with a GPL (as opposed to LGPL) License - this will not be liberal
15634 enough for many embedded programmers.
15638 \begin_inset LatexCommand \label{sub:External-Stack}
15643 \begin_inset LatexCommand \index{stack}
15648 \begin_inset LatexCommand \index{External stack}
15655 The external stack is located at the start of the external ram segment,
15656 and is 256 bytes in size.
15667 -xstack option is used to compile the program, the parameters and local
15668 variables of all reentrant functions are allocated in this area.
15669 This option is provided for programs with large stack space requirements.
15670 When used with the -
15680 -stack-auto option, all parameters and local variables are allocated on
15681 the external stack (note support libraries will need to be recompiled with
15685 The compiler outputs the higher order address byte of the external ram segment
15686 into PORT P2, therefore when using the External Stack option, this port
15687 MAY NOT be used by the application program.
15691 \begin_inset LatexCommand \index{ANSI-compliance}
15698 Deviations from the compliance:
15701 functions are not always reentrant.
15704 structures cannot be assigned values directly, cannot be passed as function
15705 parameters or assigned to each other and cannot be a return value from
15732 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
15743 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
15765 return rets;/* is invalid in SDCC although allowed in ANSI */
15772 \begin_inset LatexCommand \index{long long (not supported)}
15777 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
15785 \begin_inset LatexCommand \index{double (not supported)}
15789 ' precision floating point
15790 \begin_inset LatexCommand \index{Floating point support}
15797 No support for setjmp and longjmp (for now).
15801 \begin_inset LatexCommand \index{K\&R style}
15805 function declarations are NOT allowed.
15811 foo(i,j) /* this old style of function declarations */
15813 int i,j; /* are valid in ANSI but not valid in SDCC */
15828 functions declared as pointers must be dereferenced during the call.
15839 /* has to be called like this */
15841 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
15845 Cyclomatic Complexity
15846 \begin_inset LatexCommand \index{Cyclomatic complexity}
15853 Cyclomatic complexity of a function is defined as the number of independent
15854 paths the program can take during execution of the function.
15855 This is an important number since it defines the number test cases you
15856 have to generate to validate the function.
15857 The accepted industry standard for complexity number is 10, if the cyclomatic
15858 complexity reported by SDCC exceeds 10 you should think about simplification
15859 of the function logic.
15860 Note that the complexity level is not related to the number of lines of
15861 code in a function.
15862 Large functions can have low complexity, and small functions can have large
15868 SDCC uses the following formula to compute the complexity:
15873 complexity = (number of edges in control flow graph) - (number of nodes
15874 in control flow graph) + 2;
15878 Having said that the industry standard is 10, you should be aware that in
15879 some cases it be may unavoidable to have a complexity level of less than
15881 For example if you have switch statement with more than 10 case labels,
15882 each case label adds one to the complexity level.
15883 The complexity level is by no means an absolute measure of the algorithmic
15884 complexity of the function, it does however provide a good starting point
15885 for which functions you might look at for further optimization.
15889 \layout Subsubsection
15891 The Z80 and gbz80 port
15894 SDCC can target both the Zilog
15895 \begin_inset LatexCommand \index{Z80}
15899 and the Nintendo Gameboy's Z80-like gbz80
15900 \begin_inset LatexCommand \index{GameBoy Z80}
15905 The Z80 port is passed through the same
15908 \begin_inset LatexCommand \index{Regression test}
15914 as MCS51 and DS390 ports, so floating point support, support for long variables
15915 and bitfield support is fine.
15918 As always, the code is the authoritative reference - see z80/ralloc.c and
15920 The stack frame is similar to that generated by the IAR Z80 compiler.
15921 IX is used as the base pointer, HL is used as a temporary register, and
15922 BC and DE are available for holding variables.
15923 IY is currently unused.
15924 Return values are stored in HL.
15925 One bad side effect of using IX as the base pointer is that a functions
15926 stack frame is limited to 127 bytes - this will be fixed in a later version.
15929 Retargetting for other MCUs.
15932 The issues for retargetting the compiler are far too numerous to be covered
15934 What follows is a brief description of each of the seven phases of the
15935 compiler and its MCU dependency.
15938 Parsing the source and building the annotated parse tree.
15939 This phase is largely MCU independent (except for the language extensions).
15940 Syntax & semantic checks are also done in this phase, along with some initial
15941 optimizations like back patching labels and the pattern matching optimizations
15942 like bit-rotation etc.
15945 The second phase involves generating an intermediate code which can be easy
15946 manipulated during the later phases.
15947 This phase is entirely MCU independent.
15948 The intermediate code generation assumes the target machine has unlimited
15949 number of registers, and designates them with the name iTemp.
15950 The compiler can be made to dump a human readable form of the code generated
15964 This phase does the bulk of the standard optimizations and is also MCU independe
15966 This phase can be broken down into several sub-phases:
15970 Break down intermediate code (iCode) into basic blocks.
15972 Do control flow & data flow analysis on the basic blocks.
15974 Do local common subexpression elimination, then global subexpression elimination
15976 Dead code elimination
15980 If loop optimizations caused any changes then do 'global subexpression eliminati
15981 on' and 'dead code elimination' again.
15984 This phase determines the live-ranges; by live range I mean those iTemp
15985 variables defined by the compiler that still survive after all the optimization
15987 Live range analysis
15988 \begin_inset LatexCommand \index{Live range analysis}
15992 is essential for register allocation, since these computation determines
15993 which of these iTemps will be assigned to registers, and for how long.
15996 Phase five is register allocation.
15997 There are two parts to this process.
16001 The first part I call 'register packing' (for lack of a better term).
16002 In this case several MCU specific expression folding is done to reduce
16007 The second part is more MCU independent and deals with allocating registers
16008 to the remaining live ranges.
16009 A lot of MCU specific code does creep into this phase because of the limited
16010 number of index registers available in the 8051.
16013 The Code generation phase is (unhappily), entirely MCU dependent and very
16014 little (if any at all) of this code can be reused for other MCU.
16015 However the scheme for allocating a homogenized assembler operand for each
16016 iCode operand may be reused.
16019 As mentioned in the optimization section the peep-hole optimizer is rule
16020 based system, which can reprogrammed for other MCUs.
16024 \begin_inset LatexCommand \index{Compiler internals}
16031 The anatomy of the compiler
16036 This is an excerpt from an article published in Circuit Cellar Magazine
16038 It's a little outdated (the compiler is much more efficient now and user/develo
16039 per friendly), but pretty well exposes the guts of it all.
16045 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
16046 It is fairly easy to retarget for other 8-bit MCU.
16047 Here we take a look at some of the internals of the compiler.
16052 \begin_inset LatexCommand \index{Parsing}
16059 Parsing the input source file and creating an AST (Annotated Syntax Tree
16060 \begin_inset LatexCommand \index{Annotated syntax tree}
16065 This phase also involves propagating types (annotating each node of the
16066 parse tree with type information) and semantic analysis.
16067 There are some MCU specific parsing rules.
16068 For example the storage classes, the extended storage classes are MCU specific
16069 while there may be a xdata storage class for 8051 there is no such storage
16070 class for z80 or Atmel AVR.
16071 SDCC allows MCU specific storage class extensions, i.e.
16072 xdata will be treated as a storage class specifier when parsing 8051 C
16073 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
16078 \begin_inset LatexCommand \index{iCode}
16085 Intermediate code generation.
16086 In this phase the AST is broken down into three-operand form (iCode).
16087 These three operand forms are represented as doubly linked lists.
16088 ICode is the term given to the intermediate form generated by the compiler.
16089 ICode example section shows some examples of iCode generated for some simple
16090 C source functions.
16094 \begin_inset LatexCommand \index{Optimizations}
16101 Bulk of the target independent optimizations is performed in this phase.
16102 The optimizations include constant propagation, common sub-expression eliminati
16103 on, loop invariant code movement, strength reduction of loop induction variables
16104 and dead-code elimination.
16107 Live range analysis
16108 \begin_inset LatexCommand \index{Live range analysis}
16115 During intermediate code generation phase, the compiler assumes the target
16116 machine has infinite number of registers and generates a lot of temporary
16118 The live range computation determines the lifetime of each of these compiler-ge
16119 nerated temporaries.
16120 A picture speaks a thousand words.
16121 ICode example sections show the live range annotations for each of the
16123 It is important to note here, each iCode is assigned a number in the order
16124 of its execution in the function.
16125 The live ranges are computed in terms of these numbers.
16126 The from number is the number of the iCode which first defines the operand
16127 and the to number signifies the iCode which uses this operand last.
16130 Register Allocation
16131 \begin_inset LatexCommand \index{Register allocation}
16138 The register allocation determines the type and number of registers needed
16140 In most MCUs only a few registers can be used for indirect addressing.
16141 In case of 8051 for example the registers R0 & R1 can be used to indirectly
16142 address the internal ram and DPTR to indirectly address the external ram.
16143 The compiler will try to allocate the appropriate register to pointer variables
16145 ICode example section shows the operands annotated with the registers assigned
16147 The compiler will try to keep operands in registers as much as possible;
16148 there are several schemes the compiler uses to do achieve this.
16149 When the compiler runs out of registers the compiler will check to see
16150 if there are any live operands which is not used or defined in the current
16151 basic block being processed, if there are any found then it will push that
16152 operand and use the registers in this block, the operand will then be popped
16153 at the end of the basic block.
16157 There are other MCU specific considerations in this phase.
16158 Some MCUs have an accumulator; very short-lived operands could be assigned
16159 to the accumulator instead of general-purpose register.
16165 Figure II gives a table of iCode operations supported by the compiler.
16166 The code generation involves translating these operations into corresponding
16167 assembly code for the processor.
16168 This sounds overly simple but that is the essence of code generation.
16169 Some of the iCode operations are generated on a MCU specific manner for
16170 example, the z80 port does not use registers to pass parameters so the
16171 SEND and RECV iCode operations will not be generated, and it also does
16172 not support JUMPTABLES.
16179 <Where is Figure II ?>
16183 \begin_inset LatexCommand \index{iCode}
16190 This section shows some details of iCode.
16191 The example C code does not do anything useful; it is used as an example
16192 to illustrate the intermediate code generated by the compiler.
16204 /* This function does nothing useful.
16211 for the purpose of explaining iCode */
16214 short function (data int *x)
16222 short i=10; /* dead initialization eliminated */
16227 short sum=10; /* dead initialization eliminated */
16240 while (*x) *x++ = *p++;
16254 /* compiler detects i,j to be induction variables */
16258 for (i = 0, j = 10 ; i < 10 ; i++, j
16284 mul += i * 3; /* this multiplication remains */
16290 gint += j * 3;/* this multiplication changed to addition */
16304 In addition to the operands each iCode contains information about the filename
16305 and line it corresponds to in the source file.
16306 The first field in the listing should be interpreted as follows:
16311 Filename(linenumber: iCode Execution sequence number : ICode hash table
16312 key : loop depth of the iCode).
16317 Then follows the human readable form of the ICode operation.
16318 Each operand of this triplet form can be of three basic types a) compiler
16319 generated temporary b) user defined variable c) a constant value.
16320 Note that local variables and parameters are replaced by compiler generated
16323 \begin_inset LatexCommand \index{Live range analysis}
16327 are computed only for temporaries (i.e.
16328 live ranges are not computed for global variables).
16330 \begin_inset LatexCommand \index{Register allocation}
16334 are allocated for temporaries only.
16335 Operands are formatted in the following manner:
16340 Operand Name [lr live-from : live-to ] { type information } [ registers
16346 As mentioned earlier the live ranges are computed in terms of the execution
16347 sequence number of the iCodes, for example
16349 the iTemp0 is live from (i.e.
16350 first defined in iCode with execution sequence number 3, and is last used
16351 in the iCode with sequence number 5).
16352 For induction variables such as iTemp21 the live range computation extends
16353 the lifetime from the start to the end of the loop.
16355 The register allocator used the live range information to allocate registers,
16356 the same registers may be used for different temporaries if their live
16357 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
16358 iTemp17 since their live ranges do not overlap.
16359 In addition the allocator also takes into consideration the type and usage
16360 of a temporary, for example itemp6 is a pointer to near space and is used
16361 as to fetch data from (i.e.
16362 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
16363 Some short lived temporaries are allocated to special registers which have
16364 meaning to the code generator e.g.
16365 iTemp13 is allocated to a pseudo register CC which tells the back end that
16366 the temporary is used only for a conditional jump the code generation makes
16367 use of this information to optimize a compare and jump ICode.
16369 There are several loop optimizations
16370 \begin_inset LatexCommand \index{Loop optimization}
16374 performed by the compiler.
16375 It can detect induction variables iTemp21(i) and iTemp23(j).
16376 Also note the compiler does selective strength reduction
16377 \begin_inset LatexCommand \index{Strength reduction}
16382 the multiplication of an induction variable in line 18 (gint = j * 3) is
16383 changed to addition, a new temporary iTemp17 is allocated and assigned
16384 a initial value, a constant 3 is then added for each iteration of the loop.
16385 The compiler does not change the multiplication
16386 \begin_inset LatexCommand \index{Multiplication}
16390 in line 17 however since the processor does support an 8 * 8 bit multiplication.
16392 Note the dead code elimination
16393 \begin_inset LatexCommand \index{Dead-code elimination}
16397 optimization eliminated the dead assignments in line 7 & 8 to I and sum
16405 Sample.c (5:1:0:0) _entry($9) :
16410 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
16415 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
16420 Sample.c(11:4:53:0) preHeaderLbl0($11) :
16425 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
16431 Sample.c(11:6:5:1) _whilecontinue_0($1) :
16436 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
16442 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16447 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
16453 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
16459 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
16465 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
16471 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
16472 * int}[r0] + 0x2 {short}
16477 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
16482 Sample.c(11:17:21:0)_whilebreak_0($3) :
16487 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16492 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16497 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16502 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16507 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16512 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16517 Sample.c(15:24:26:1)_forcond_0($4) :
16522 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16528 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16533 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16534 + ITemp21 [lr21:38]{short}[r4]
16539 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16545 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16546 + iTemp15 [lr29:30]{short}[r1]
16551 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16557 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16563 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16569 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16575 Sample.c(19:38:47:1) goto _forcond_0($4)
16580 Sample.c(19:39:48:0)_forbreak_0($7) :
16585 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16586 + ITemp11 [lr19:40]{short}[r3]
16591 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16596 Sample.c(20:42:51:0)_return($8) :
16601 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16607 Finally the code generated for this function:
16648 ; ----------------------------------------------
16653 ; function function
16658 ; ----------------------------------------------
16668 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16680 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16692 ;_whilecontinue_0($1) :
16702 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16707 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16766 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16785 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16832 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16872 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16898 ; iTemp6 [lr5:16]{_near * int}[r0] =
16903 ; iTemp6 [lr5:16]{_near * int}[r0] +
16920 ; goto _whilecontinue_0($1)
16932 ; _whilebreak_0($3) :
16942 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16954 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16966 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16978 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16997 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
17026 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
17031 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
17076 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
17081 ; iTemp21 [lr21:38]{short}[r4]
17107 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
17140 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
17145 ; iTemp15 [lr29:30]{short}[r1]
17164 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
17211 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
17258 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
17270 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
17284 cjne r5,#0xff,00104$
17296 ; goto _forcond_0($4)
17308 ; _forbreak_0($7) :
17318 ; ret iTemp24 [lr40:41]{short}
17361 A few words about basic block successors, predecessors and dominators
17364 Successors are basic blocks
17365 \begin_inset LatexCommand \index{Basic blocks}
17369 that might execute after this basic block.
17371 Predecessors are basic blocks that might execute before reaching this basic
17374 Dominators are basic blocks that WILL execute before reaching this basic
17408 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
17411 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
17414 c) domVect of [BB4] = BB1 ...
17415 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
17423 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
17433 Thanks to all the other volunteer developers who have helped with coding,
17434 testing, web-page creation, distribution sets, etc.
17435 You know who you are :-)
17442 This document was initially written by Sandeep Dutta
17445 All product names mentioned herein may be trademarks
17446 \begin_inset LatexCommand \index{Trademarks}
17450 of their respective companies.
17457 To avoid confusion, the installation and building options for sdcc itself
17458 (chapter 2) are not part of the index.
17462 \begin_inset LatexCommand \printindex{}