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">
1161 <row bottomline="true">
1162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1189 <row bottomline="true">
1190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1241 \begin_inset Quotes srd
1245 \begin_inset Quotes srd
1259 \begin_inset Quotes srd
1263 \begin_inset Quotes srd
1291 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1300 \begin_inset Quotes srd
1303 i586-mingw32msvc-gcc
1304 \begin_inset Quotes srd
1308 \begin_inset Quotes srd
1311 i586-mingw32msvc-g++
1312 \begin_inset Quotes srd
1320 \begin_inset Quotes srd
1323 i586-mingw32msvc-ranlib
1324 \begin_inset Quotes srd
1332 \begin_inset Quotes srd
1335 i586-mingw32msvc-strip
1336 \begin_inset Quotes srd
1354 \begin_inset Quotes srd
1358 \begin_inset Quotes srd
1376 \begin_inset Quotes srd
1380 \begin_inset Quotes srd
1388 \begin_inset Quotes srd
1392 \begin_inset Quotes srd
1400 \begin_inset Quotes srd
1404 \begin_inset Quotes srd
1412 \begin_inset Quotes srd
1416 \begin_inset Quotes srd
1423 sdccconf_h_dir_separator=
1424 \begin_inset Quotes srd
1436 \begin_inset Quotes srd
1453 -disable-device-lib-build
1481 -host=i586-mingw32msvc -
1491 -build=unknown-unknown-linux-gnu
1495 \begin_inset Quotes sld
1499 \begin_inset Quotes srd
1502 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1511 \begin_inset Quotes srd
1515 \begin_inset Quotes srd
1523 \begin_inset Quotes srd
1527 \begin_inset Quotes srd
1545 \begin_inset Quotes srd
1549 \begin_inset Quotes srd
1567 \begin_inset Quotes srd
1571 \begin_inset Quotes srd
1579 \begin_inset Quotes srd
1583 \begin_inset Quotes srd
1591 \begin_inset Quotes srd
1595 \begin_inset Quotes srd
1603 \begin_inset Quotes srd
1607 \begin_inset Quotes srd
1614 sdccconf_h_dir_separator=
1615 \begin_inset Quotes srd
1627 \begin_inset Quotes srd
1647 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1658 -C' turns on caching, which gives a little bit extra speed.
1659 However if options are changed, it can be necessary to delete the config.cache
1664 \begin_inset LatexCommand \index{Install paths}
1670 \added_space_top medskip \align center
1672 \begin_inset Tabular
1673 <lyxtabular version="3" rows="5" columns="4">
1675 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1676 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1677 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1678 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
1679 <row topline="true" bottomline="true">
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1721 <row topline="true">
1722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1761 <row topline="true">
1762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 $DATADIR/ $INCLUDE_DIR_SUFFIX
1780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1785 /usr/local/share/sdcc/include
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1817 $DATADIR/$LIB_DIR_SUFFIX
1820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1825 /usr/local/share/sdcc/lib
1828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1841 <row topline="true" bottomline="true">
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1865 /usr/local/share/sdcc/doc
1868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1890 *compiler, preprocessor, assembler, and linker
1896 is auto-appended by the compiler, e.g.
1897 small, large, z80, ds390 etc
1900 The install paths can still be changed during `make install` with e.g.:
1903 make install prefix=$(HOME)/local/sdcc
1906 Of course this doesn't change the search paths compiled into the binaries.
1910 \begin_inset LatexCommand \index{Search path}
1917 Some search paths or parts of them are determined by configure variables
1922 , see section above).
1923 Further search paths are determined by environment variables during runtime.
1926 The paths searched when running the compiler are as follows (the first catch
1932 Binary files (preprocessor, assembler and linker)
1938 \begin_inset Tabular
1939 <lyxtabular version="3" rows="4" columns="3">
1941 <column alignment="block" valignment="top" leftline="true" width="0in">
1942 <column alignment="block" valignment="top" leftline="true" width="0in">
1943 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1944 <row topline="true" bottomline="true">
1945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1970 <row topline="true">
1971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2000 <row topline="true">
2001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2006 Path of argv[0] (if available)
2009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2026 <row topline="true" bottomline="true">
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2068 \begin_inset Tabular
2069 <lyxtabular version="3" rows="6" columns="3">
2071 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2072 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2073 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2074 <row topline="true" bottomline="true">
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2100 <row topline="true">
2101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2156 <row topline="true">
2157 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2182 <row topline="true">
2183 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2197 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2220 <row topline="true">
2221 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2302 <row topline="true" bottomline="true">
2303 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2319 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2324 /usr/local/share/sdcc/
2329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2357 -nostdinc disables the last two search paths.
2367 With the exception of
2368 \begin_inset Quotes sld
2382 \begin_inset Quotes srd
2389 is auto-appended by the compiler (e.g.
2390 small, large, z80, ds390 etc.).
2397 \begin_inset Tabular
2398 <lyxtabular version="3" rows="6" columns="3">
2400 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2401 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2402 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2403 <row topline="true" bottomline="true">
2404 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2412 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2429 <row topline="true">
2430 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2485 <row topline="true">
2486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2498 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2525 <row topline="true">
2526 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2537 $LIB_DIR_SUFFIX/<model>
2540 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2554 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2571 <row topline="true">
2572 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2587 $LIB_DIR_SUFFIX/<model>
2590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2699 <row topline="true" bottomline="true">
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2709 $LIB_DIR_SUFFIX/<model>
2712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2717 /usr/local/share/sdcc/
2724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2742 Don't delete any of the stray spaces in the table above without checking
2743 the HTML output (last line)!
2759 -nostdlib disables the last two search paths.
2763 \begin_inset LatexCommand \index{Building SDCC}
2768 \layout Subsubsection
2770 Building SDCC on Linux
2771 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2780 Download the source package
2782 either from the SDCC CVS repository or from the
2783 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2789 , it will be named something like sdcc
2802 Bring up a command line terminal, such as xterm.
2807 Unpack the file using a command like:
2810 "tar -xzf sdcc.src.tar.gz
2815 , this will create a sub-directory called sdcc with all of the sources.
2818 Change directory into the main SDCC directory, for example type:
2835 This configures the package for compilation on your system.
2851 All of the source packages will compile, this can take a while.
2867 This copies the binary executables, the include files, the libraries and
2868 the documentation to the install directories.
2869 \layout Subsubsection
2871 Building SDCC on OSX 2.x
2874 Follow the instruction for Linux.
2878 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2879 )) fails to compile SDCC.
2880 Fortunately there's also gcc 2.9.x installed, which works fine.
2881 This compiler can be selected by running 'configure' with:
2884 ./configure CC=gcc2 CXX=g++2
2885 \layout Subsubsection
2887 Cross compiling SDCC on Linux for Windows
2890 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2891 See section 'Configure Options'.
2892 \layout Subsubsection
2894 Building SDCC on Windows
2897 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2899 They use Unix-sockets, which are not available on Win32.
2900 \layout Subsubsection
2902 Building SDCC using Cygwin and Mingw32
2905 For building and installing a Cygwin executable follow the instructions
2911 \begin_inset Quotes sld
2915 \begin_inset Quotes srd
2918 Win32-binary can be built, which will not need the Cygwin-DLL.
2919 For the necessary 'configure' options see section 'configure options' or
2920 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2924 In order to install Cygwin on Windows download setup.exe from
2925 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2931 \begin_inset Quotes sld
2934 default text file type
2935 \begin_inset Quotes srd
2939 \begin_inset Quotes sld
2943 \begin_inset Quotes srd
2946 and download/install at least the following packages.
2947 Some packages are selected by default, others will be automatically selected
2948 because of dependencies with the manually selected packages.
2949 Never deselect these packages!
2958 gcc ; version 3.x is fine, no need to use the old 2.9x
2961 binutils ; selected with gcc
2967 rxvt ; a nice console, which makes life much easier under windoze (see below)
2970 man ; not really needed for building SDCC, but you'll miss it sooner or
2974 less ; not really needed for building SDCC, but you'll miss it sooner or
2978 cvs ; only if you use CVS access
2981 If you want to develop something you'll need:
2984 python ; for the regression tests
2987 gdb ; the gnu debugger, together with the nice GUI
2988 \begin_inset Quotes sld
2992 \begin_inset Quotes srd
2998 openssh ; to access the CF or commit changes
3001 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3002 use autoconf-stable!
3005 rxvt is a nice console with history.
3006 Replace in your cygwin.bat the line
3025 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3028 -bg black -fg white -geometry 100x65 -e bash -
3041 Text selected with the mouse is automatically copied to the clipboard, pasting
3042 works with shift-insert.
3046 The other good tip is to make sure you have no //c/-style paths anywhere,
3047 use /cygdrive/c/ instead.
3048 Using // invokes a network lookup which is very slow.
3050 \begin_inset Quotes sld
3054 \begin_inset Quotes srd
3057 is too long, you can change it with e.g.
3063 SDCC sources use the unix line ending LF.
3064 Life is much easier, if you store the source tree on a drive which is mounted
3066 And use an editor which can handle LF-only line endings.
3067 Make sure not to commit files with windows line endings.
3068 The tabulator spacing used in the project is 8.
3069 \layout Subsubsection
3071 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3076 Download the source package
3078 either from the SDCC CVS repository or from the
3079 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3085 , it will be named something like sdcc
3092 SDCC is distributed with all the projects, workspaces, and files you need
3093 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3094 doesn't build under MSVC).
3095 The workspace name is 'sdcc.dsw'.
3096 Please note that as it is now, all the executables are created in a folder
3100 Once built you need to copy the executables from sdcc
3104 bin before running SDCC.
3109 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3110 flex.exe, and gawk.exe.
3111 One good place to get them is
3112 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3120 Download the file UnxUtils
3121 \begin_inset LatexCommand \index{UnxUtils}
3126 Now you have to install the utilities and setup MSVC so it can locate the
3128 Here there are two alternatives (choose one!):
3135 a) Extract UnxUtils.zip to your C:
3137 hard disk PRESERVING the original paths, otherwise bison won't work.
3138 (If you are using WinZip make certain that 'Use folder names' is selected)
3142 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3143 in 'Show directories for:' select 'Executable files', and in the directories
3144 window add a new path: 'C:
3154 (As a side effect, you get a bunch of Unix utilities that could be useful,
3155 such as diff and patch.)
3162 This one avoids extracting a bunch of files you may not use, but requires
3167 a) Create a directory were to put the tools needed, or use a directory already
3175 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3176 to such directory WITHOUT preserving the original paths.
3177 (If you are using WinZip make certain that 'Use folder names' is not selected)
3181 c) Rename bison.exe to '_bison.exe'.
3185 d) Create a batch file 'bison.bat' in 'C:
3189 ' and add these lines:
3209 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3213 Steps 'c' and 'd' are needed because bison requires by default that the
3214 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3215 '/usr/local/share/' I think.
3216 So it is necessary to tell bison where those files are located if they
3217 are not in such directory.
3218 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3222 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3223 in 'Show directories for:' select 'Executable files', and in the directories
3224 window add a new path: 'c:
3227 Note that you can use any other path instead of 'c:
3229 util', even the path where the Visual C++ tools are, probably: 'C:
3233 Microsoft Visual Studio
3238 So you don't have to execute step 'e' :)
3242 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3243 the executables from sdcc
3247 bin, and you can compile using sdcc.
3248 \layout Subsubsection
3250 Building SDCC Using Borland
3253 From the sdcc directory, run the command "make -f Makefile.bcc".
3254 This should regenerate all the .exe files in the bin directory except for
3255 sdcdb.exe (which currently doesn't build under Borland C++).
3258 If you modify any source files and need to rebuild, be aware that the dependenci
3259 es may not be correctly calculated.
3260 The safest option is to delete all .obj files and run the build again.
3261 From a Cygwin BASH prompt, this can easily be done with the command (be
3262 sure you are in the sdcc directory):
3272 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3274 ) -print -exec rm {}
3283 or on Windows NT/2000/XP from the command prompt with the command:
3290 del /s *.obj *.lib *.rul
3293 from the sdcc directory.
3294 \layout Subsubsection
3296 Windows Install Using a Binary Package
3297 \begin_inset LatexCommand \label{sub:Windows-Install}
3304 Download the binary package from
3305 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3309 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3310 This should unpack to a group of sub-directories.
3311 An example directory structure after unpacking the mingw32 package is:
3316 bin for the executables, c:
3324 lib for the include and libraries.
3327 Adjust your environment variable PATH to include the location of the bin
3328 directory or start sdcc using the full path.
3331 Building the Documentation
3334 If the necessary tools are installed it is as easy as changing into the
3335 doc directory and typing
3339 \begin_inset Quotes srd
3343 \begin_inset Quotes srd
3350 If you want to avoid installing the tools you will have some success with
3351 a bootable Knoppix CD
3352 \begin_inset LatexCommand \url{http://www.knopper.net}
3359 Testing the SDCC Compiler
3362 The first thing you should do after installing your SDCC compiler is to
3378 \begin_inset LatexCommand \index{version}
3385 at the prompt, and the program should run and tell you the version.
3386 If it doesn't run, or gives a message about not finding sdcc program, then
3387 you need to check over your installation.
3388 Make sure that the sdcc bin directory is in your executable search path
3389 defined by the PATH environment setting (see the Trouble-shooting section
3391 Make sure that the sdcc program is in the bin folder, if not perhaps something
3392 did not install correctly.
3400 is commonly installed as described in section
3401 \begin_inset Quotes sld
3404 Install and search paths
3405 \begin_inset Quotes srd
3414 Make sure the compiler works on a very simple example.
3415 Type in the following test.c program using your favorite
3441 Compile this using the following command:
3450 If all goes well, the compiler will generate a test.asm and test.rel file.
3451 Congratulations, you've just compiled your first program with SDCC.
3452 We used the -c option to tell SDCC not to link the generated code, just
3453 to keep things simple for this step.
3461 The next step is to try it with the linker.
3471 If all goes well the compiler will link with the libraries and produce
3472 a test.ihx output file.
3477 (no test.ihx, and the linker generates warnings), then the problem is most
3478 likely that sdcc cannot find the
3482 usr/local/share/sdcc/lib directory
3486 (see the Install trouble-shooting section for suggestions).
3494 The final test is to ensure sdcc can use the
3498 header files and libraries.
3499 Edit test.c and change it to the following:
3516 strcpy(str1, "testing");
3523 Compile this by typing
3530 This should generate a test.ihx output file, and it should give no warnings
3531 such as not finding the string.h file.
3532 If it cannot find the string.h file, then the problem is that sdcc cannot
3533 find the /usr/local/share/sdcc/include directory
3537 (see the Install trouble-shooting section for suggestions).
3555 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3559 to find exactly where SDCC is looking for the include and lib files.
3562 Install Trouble-shooting
3563 \begin_inset LatexCommand \index{Install trouble-shooting}
3568 \layout Subsubsection
3570 SDCC does not build correctly.
3573 A thing to try is starting from scratch by unpacking the .tgz source package
3574 again in an empty directory.
3582 ./configure 2>&1 | tee configure.log
3596 make 2>&1 | tee make.log
3603 If anything goes wrong, you can review the log files to locate the problem.
3604 Or a relevant part of this can be attached to an email that could be helpful
3605 when requesting help from the mailing list.
3606 \layout Subsubsection
3609 \begin_inset Quotes sld
3613 \begin_inset Quotes srd
3620 \begin_inset Quotes sld
3624 \begin_inset Quotes srd
3627 command is a script that analyzes your system and performs some configuration
3628 to ensure the source package compiles on your system.
3629 It will take a few minutes to run, and will compile a few tests to determine
3630 what compiler features are installed.
3631 \layout Subsubsection
3634 \begin_inset Quotes sld
3638 \begin_inset Quotes srd
3644 This runs the GNU make tool, which automatically compiles all the source
3645 packages into the final installed binary executables.
3646 \layout Subsubsection
3649 \begin_inset Quotes sld
3653 \begin_inset Quotes erd
3659 This will install the compiler, other executables libraries and include
3660 files into the appropriate directories.
3662 \begin_inset Quotes sld
3665 Install and Search PATHS
3666 \begin_inset Quotes srd
3671 On most systems you will need super-user privileges to do this.
3677 SDCC is not just a compiler, but a collection of tools by various developers.
3678 These include linkers, assemblers, simulators and other components.
3679 Here is a summary of some of the components.
3680 Note that the included simulator and assembler have separate documentation
3681 which you can find in the source package in their respective directories.
3682 As SDCC grows to include support for other processors, other packages from
3683 various developers are included and may have their own sets of documentation.
3687 You might want to look at the files which are installed in <installdir>.
3688 At the time of this writing, we find the following programs for gcc-builds:
3692 In <installdir>/bin:
3695 sdcc - The compiler.
3698 sdcpp - The C preprocessor.
3701 asx8051 - The assembler for 8051 type processors.
3708 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3711 aslink -The linker for 8051 type processors.
3718 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3721 s51 - The ucSim 8051 simulator.
3724 sdcdb - The source debugger.
3727 packihx - A tool to pack (compress) Intel hex files.
3730 In <installdir>/share/sdcc/include
3736 In <installdir>/share/sdcc/lib
3739 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3743 In <installdir>/share/sdcc/doc
3749 As development for other processors proceeds, this list will expand to include
3750 executables to support processors like AVR, PIC, etc.
3751 \layout Subsubsection
3756 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3757 the assembler and linkage editor.
3758 \layout Subsubsection
3761 \begin_inset LatexCommand \index{sdcpp}
3765 - The C-Preprocessor
3768 The preprocessor is a modified version of the GNU preprocessor.
3769 The C preprocessor is used to pull in #include sources, process #ifdef
3770 statements, #defines and so on.
3771 \layout Subsubsection
3773 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3777 This is retargettable assembler & linkage editor, it was developed by Alan
3779 John Hartman created the version for 8051, and I (Sandeep) have made some
3780 enhancements and bug fixes for it to work properly with SDCC.
3781 \layout Subsubsection
3784 \begin_inset LatexCommand \index{s51}
3791 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3792 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3797 The simulator is built as part of the build process.
3798 For more information visit Daniel's web site at:
3799 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3804 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3806 \layout Subsubsection
3809 \begin_inset LatexCommand \index{sdcdb}
3813 - Source Level Debugger
3816 Sdcdb is the companion source level debugger.
3817 The current version of the debugger uses Daniel's Simulator S51
3818 \begin_inset LatexCommand \index{s51}
3822 , but can be easily changed to use other simulators.
3829 \layout Subsubsection
3831 Single Source File Projects
3834 For single source file 8051 projects the process is very simple.
3835 Compile your programs with the following command
3838 "sdcc sourcefile.c".
3842 This will compile, assemble and link your source file.
3843 Output files are as follows
3847 \begin_inset LatexCommand \index{.asm}
3852 \begin_inset LatexCommand \index{Assembler source}
3856 file created by the compiler
3860 \begin_inset LatexCommand \index{.lst}
3865 \begin_inset LatexCommand \index{Assembler listing}
3869 file created by the Assembler
3873 \begin_inset LatexCommand \index{.rst}
3878 \begin_inset LatexCommand \index{Assembler listing}
3882 file updated with linkedit information, created by linkage editor
3886 \begin_inset LatexCommand \index{.sym}
3891 \begin_inset LatexCommand \index{Symbol listing}
3895 for the sourcefile, created by the assembler
3899 \begin_inset LatexCommand \index{.rel}
3904 \begin_inset LatexCommand \index{Object file}
3908 created by the assembler, input to Linkage editor
3912 \begin_inset LatexCommand \index{.map}
3917 \begin_inset LatexCommand \index{Memory map}
3921 for the load module, created by the Linker
3925 \begin_inset LatexCommand \index{.mem}
3929 - A file with a summary of the memory usage
3933 \begin_inset LatexCommand \index{.ihx}
3937 - The load module in Intel hex format
3938 \begin_inset LatexCommand \index{Intel hex format}
3942 (you can select the Motorola S19 format
3943 \begin_inset LatexCommand \index{Motorola S19 format}
3958 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3963 If you need another format you might want to use
3970 \begin_inset LatexCommand \index{objdump}
3981 \begin_inset LatexCommand \index{srecord}
3989 \begin_inset LatexCommand \index{.adb}
3993 - An intermediate file containing debug information needed to create the
4005 \begin_inset LatexCommand \index{-\/-debug}
4013 \begin_inset LatexCommand \index{.cdb}
4017 - An optional file (with -
4027 -debug) containing debug information
4032 \begin_inset LatexCommand \index{. (no extension)}
4037 \begin_inset LatexCommand \index{AOMF51}
4041 file containing debug information (with -
4052 This format is commonly used by third party tools (debuggers
4053 \begin_inset LatexCommand \index{Debugger}
4057 , simulators, emulators)
4061 \begin_inset LatexCommand \index{.dump*}
4065 - Dump file to debug the compiler it self (with -
4075 -dumpall) (see section
4076 \begin_inset Quotes sld
4079 Anatomy of the compiler
4080 \begin_inset Quotes srd
4084 \layout Subsubsection
4086 Projects with Multiple Source Files
4089 SDCC can compile only ONE file at a time.
4090 Let us for example assume that you have a project containing the following
4095 foo1.c (contains some functions)
4097 foo2.c (contains some more functions)
4099 foomain.c (contains more functions and the function main)
4107 The first two files will need to be compiled separately with the commands:
4139 Then compile the source file containing the
4144 \begin_inset LatexCommand \index{Linker}
4148 the files together with the following command:
4156 foomain.c\SpecialChar ~
4157 foo1.rel\SpecialChar ~
4162 \begin_inset LatexCommand \index{.rel}
4174 can be separately compiled as well:
4185 sdcc foomain.rel foo1.rel foo2.rel
4192 The file containing the
4207 file specified in the command line, since the linkage editor processes
4208 file in the order they are presented to it.
4209 The linker is invoked from sdcc using a script file with extension .lnk
4210 \begin_inset LatexCommand \index{.lnk}
4215 You can view this file to troubleshoot linking problems such as those arising
4216 from missing libraries.
4217 \layout Subsubsection
4219 Projects with Additional Libraries
4220 \begin_inset LatexCommand \index{Libraries}
4227 Some reusable routines may be compiled into a library, see the documentation
4228 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4232 \begin_inset LatexCommand \index{.lib}
4239 Libraries created in this manner can be included in the command line.
4240 Make sure you include the -L <library-path> option to tell the linker where
4241 to look for these files if they are not in the current directory.
4242 Here is an example, assuming you have the source file
4254 (if that is not the same as your current project):
4261 sdcc foomain.c foolib.lib -L mylib
4272 must be an absolute path name.
4276 The most efficient way to use libraries is to keep separate modules in separate
4278 The lib file now should name all the modules.rel
4279 \begin_inset LatexCommand \index{rel}
4284 For an example see the standard library file
4288 in the directory <installdir>/share/lib/small.
4291 Command Line Options
4292 \begin_inset LatexCommand \index{Command Line Options}
4297 \layout Subsubsection
4299 Processor Selection Options
4300 \begin_inset LatexCommand \index{Options processor selection}
4305 \begin_inset LatexCommand \index{Processor selection options}
4311 \labelwidthstring 00.00.0000
4316 \begin_inset LatexCommand \index{-mmcs51}
4322 Generate code for the Intel MCS51
4323 \begin_inset LatexCommand \index{MCS51}
4327 family of processors.
4328 This is the default processor target.
4330 \labelwidthstring 00.00.0000
4335 \begin_inset LatexCommand \index{-mds390}
4341 Generate code for the Dallas DS80C390
4342 \begin_inset LatexCommand \index{DS80C390}
4348 \labelwidthstring 00.00.0000
4353 \begin_inset LatexCommand \index{-mds400}
4359 Generate code for the Dallas DS80C400
4360 \begin_inset LatexCommand \index{DS80C400}
4366 \labelwidthstring 00.00.0000
4371 \begin_inset LatexCommand \index{-mz80}
4377 Generate code for the Zilog Z80
4378 \begin_inset LatexCommand \index{Z80}
4382 family of processors.
4384 \labelwidthstring 00.00.0000
4389 \begin_inset LatexCommand \index{-mgbz80}
4395 Generate code for the GameBoy Z80
4396 \begin_inset LatexCommand \index{GameBoy Z80}
4402 \labelwidthstring 00.00.0000
4407 \begin_inset LatexCommand \index{-mavr}
4413 Generate code for the Atmel AVR
4414 \begin_inset LatexCommand \index{AVR}
4418 processor (In development, not complete).
4419 AVR users should probably have a look at avr-gcc
4420 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4427 I think it is fair to direct users there for now.
4428 Open source is also about avoiding unnecessary work .
4429 But I didn't find the 'official' link.
4431 \labelwidthstring 00.00.0000
4436 \begin_inset LatexCommand \index{-mpic14}
4442 Generate code for the Microchip PIC 14
4443 \begin_inset LatexCommand \index{PIC14}
4447 -bit processors (p16f84 and variants).
4450 p16f627 p16f628 p16f84 p16f873 p16f877?
4452 \labelwidthstring 00.00.0000
4457 \begin_inset LatexCommand \index{-mpic16}
4463 Generate code for the Microchip PIC 16
4464 \begin_inset LatexCommand \index{PIC16}
4468 -bit processors (p18f452 and variants).
4470 \labelwidthstring 00.00.0000
4476 Generate code for the Toshiba TLCS-900H
4477 \begin_inset LatexCommand \index{TLCS-900H}
4481 processor (In development, not complete).
4483 \labelwidthstring 00.00.0000
4488 \begin_inset LatexCommand \index{-mxa51}
4494 Generate code for the Phillips XA51
4495 \begin_inset LatexCommand \index{XA51}
4499 processor (In development, not complete).
4500 \layout Subsubsection
4502 Preprocessor Options
4503 \begin_inset LatexCommand \index{Options preprocessor}
4508 \begin_inset LatexCommand \index{Preprocessor options}
4514 \labelwidthstring 00.00.0000
4519 \begin_inset LatexCommand \index{-I<path>}
4525 The additional location where the pre processor will look for <..h> or
4526 \begin_inset Quotes eld
4530 \begin_inset Quotes erd
4535 \labelwidthstring 00.00.0000
4540 \begin_inset LatexCommand \index{-D<macro[=value]>}
4546 Command line definition of macros.
4547 Passed to the preprocessor.
4549 \labelwidthstring 00.00.0000
4554 \begin_inset LatexCommand \index{-M}
4560 Tell the preprocessor to output a rule suitable for make describing the
4561 dependencies of each object file.
4562 For each source file, the preprocessor outputs one make-rule whose target
4563 is the object file name for that source file and whose dependencies are
4564 all the files `#include'd in it.
4565 This rule may be a single line or may be continued with `
4567 '-newline if it is long.
4568 The list of rules is printed on standard output instead of the preprocessed
4571 \begin_inset LatexCommand \index{-E}
4577 \labelwidthstring 00.00.0000
4582 \begin_inset LatexCommand \index{-C}
4588 Tell the preprocessor not to discard comments.
4589 Used with the `-E' option.
4591 \labelwidthstring 00.00.0000
4596 \begin_inset LatexCommand \index{-MM}
4607 Like `-M' but the output mentions only the user header files included with
4609 \begin_inset Quotes eld
4613 System header files included with `#include <file>' are omitted.
4615 \labelwidthstring 00.00.0000
4620 \begin_inset LatexCommand \index{-Aquestion(answer)}
4626 Assert the answer answer for question, in case it is tested with a preprocessor
4627 conditional such as `#if #question(answer)'.
4628 `-A-' disables the standard assertions that normally describe the target
4631 \labelwidthstring 00.00.0000
4636 \begin_inset LatexCommand \index{-Umacro}
4642 Undefine macro macro.
4643 `-U' options are evaluated after all `-D' options, but before any `-include'
4644 and `-imacros' options.
4646 \labelwidthstring 00.00.0000
4651 \begin_inset LatexCommand \index{-dM}
4657 Tell the preprocessor to output only a list of the macro definitions that
4658 are in effect at the end of preprocessing.
4659 Used with the `-E' option.
4661 \labelwidthstring 00.00.0000
4666 \begin_inset LatexCommand \index{-dD}
4672 Tell the preprocessor to pass all macro definitions into the output, in
4673 their proper sequence in the rest of the output.
4675 \labelwidthstring 00.00.0000
4680 \begin_inset LatexCommand \index{-dN}
4691 Like `-dD' except that the macro arguments and contents are omitted.
4692 Only `#define name' is included in the output.
4693 \layout Subsubsection
4696 \begin_inset LatexCommand \index{Options linker}
4701 \begin_inset LatexCommand \index{Linker options}
4707 \labelwidthstring 00.00.0000
4727 \begin_inset LatexCommand \index{-\/-lib-path}
4732 \begin_inset LatexCommand \index{-L -\/-lib-path}
4741 <absolute path to additional libraries> This option is passed to the linkage
4742 editor's additional libraries
4743 \begin_inset LatexCommand \index{Libraries}
4748 The path name must be absolute.
4749 Additional library files may be specified in the command line.
4750 See section Compiling programs for more details.
4752 \labelwidthstring 00.00.0000
4769 \begin_inset LatexCommand \index{-\/-xram-loc}
4773 <Value> The start location of the external ram
4774 \begin_inset LatexCommand \index{xdata}
4778 , default value is 0.
4779 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4789 -xram-loc 0x8000 or -
4801 \labelwidthstring 00.00.0000
4818 \begin_inset LatexCommand \index{-\/-code-loc}
4822 <Value> The start location of the code
4823 \begin_inset LatexCommand \index{code}
4827 segment, default value 0.
4828 Note when this option is used the interrupt vector table is also relocated
4829 to the given address.
4830 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4840 -code-loc 0x8000 or -
4852 \labelwidthstring 00.00.0000
4869 \begin_inset LatexCommand \index{-\/-stack-loc}
4873 <Value> By default the stack
4874 \begin_inset LatexCommand \index{stack}
4878 is placed after the data segment.
4879 Using this option the stack can be placed anywhere in the internal memory
4881 The value entered can be in Hexadecimal or Decimal format, e.g.
4892 -stack-loc 0x20 or -
4903 Since the sp register is incremented before a push or call, the initial
4904 sp will be set to one byte prior the provided value.
4905 The provided value should not overlap any other memory areas such as used
4906 register banks or the data segment and with enough space for the current
4909 \labelwidthstring 00.00.0000
4926 \begin_inset LatexCommand \index{-\/-data-loc}
4930 <Value> The start location of the internal ram data
4931 \begin_inset LatexCommand \index{data}
4936 The value entered can be in Hexadecimal or Decimal format, eg.
4958 (By default, the start location of the internal ram data segment is set
4959 as low as possible in memory, taking into account the used register banks
4960 and the bit segment at address 0x20.
4961 For example if register banks 0 and 1 are used without bit variables, the
4962 data segment will be set, if -
4972 -data-loc is not used, to location 0x10.)
4974 \labelwidthstring 00.00.0000
4991 \begin_inset LatexCommand \index{-\/-idata-loc}
4995 <Value> The start location of the indirectly addressable internal ram
4996 \begin_inset LatexCommand \index{idata}
5000 , default value is 0x80.
5001 The value entered can be in Hexadecimal or Decimal format, eg.
5012 -idata-loc 0x88 or -
5024 \labelwidthstring 00.00.0000
5039 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5048 The linker output (final object code) is in Intel Hex format.
5049 \begin_inset LatexCommand \index{Intel hex format}
5053 (This is the default option).
5055 \labelwidthstring 00.00.0000
5070 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5079 The linker output (final object code) is in Motorola S19 format
5080 \begin_inset LatexCommand \index{Motorola S19 format}
5085 \layout Subsubsection
5088 \begin_inset LatexCommand \index{Options MCS51}
5093 \begin_inset LatexCommand \index{MCS51 options}
5099 \labelwidthstring 00.00.0000
5114 \begin_inset LatexCommand \index{-\/-model-small}
5125 Generate code for Small Model programs see section Memory Models for more
5127 This is the default model.
5129 \labelwidthstring 00.00.0000
5144 \begin_inset LatexCommand \index{-\/-model-large}
5150 Generate code for Large model programs see section Memory Models for more
5152 If this option is used all source files in the project should be compiled
5155 \labelwidthstring 00.00.0000
5170 \begin_inset LatexCommand \index{-\/-xstack}
5176 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5177 variables and passing parameters.
5178 See section on external stack for more details.
5180 \labelwidthstring 00.00.0000
5197 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5201 Causes the linker to check if the internal ram usage is within limits of
5204 \labelwidthstring 00.00.0000
5221 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5225 Causes the linker to check if the external ram usage is within limits of
5228 \labelwidthstring 00.00.0000
5245 \begin_inset LatexCommand \index{-\/-data-loc}
5249 Causes the linker to check if the code memory usage is within limits of
5251 \layout Subsubsection
5254 \begin_inset LatexCommand \index{Options DS390}
5259 \begin_inset LatexCommand \index{DS390 options}
5265 \labelwidthstring 00.00.0000
5282 \begin_inset LatexCommand \index{-\/-model-flat24}
5292 Generate 24-bit flat mode code.
5293 This is the one and only that the ds390 code generator supports right now
5294 and is default when using
5299 See section Memory Models for more details.
5301 \labelwidthstring 00.00.0000
5318 \begin_inset LatexCommand \index{-\/-stack-10bit}
5322 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5323 This is the one and only that the ds390 code generator supports right now
5324 and is default when using
5329 In this mode, the stack is located in the lower 1K of the internal RAM,
5330 which is mapped to 0x400000.
5331 Note that the support is incomplete, since it still uses a single byte
5332 as the stack pointer.
5333 This means that only the lower 256 bytes of the potential 1K stack space
5334 will actually be used.
5335 However, this does allow you to reclaim the precious 256 bytes of low RAM
5336 for use for the DATA and IDATA segments.
5337 The compiler will not generate any code to put the processor into 10 bit
5339 It is important to ensure that the processor is in this mode before calling
5340 any re-entrant functions compiled with this option.
5341 In principle, this should work with the
5354 \begin_inset LatexCommand \index{-\/-stack-auto}
5360 option, but that has not been tested.
5361 It is incompatible with the
5374 \begin_inset LatexCommand \index{-\/-xstack}
5381 It also only makes sense if the processor is in 24 bit contiguous addressing
5394 -model-flat24 option
5397 \layout Subsubsection
5400 \begin_inset LatexCommand \index{Options Z80}
5405 \begin_inset LatexCommand \index{Z80 options}
5411 \labelwidthstring 00.00.0000
5428 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5438 Force a called function to always save BC.
5440 \labelwidthstring 00.00.0000
5457 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5461 When linking, skip the standard crt0.o object file.
5462 You must provide your own crt0.o for your system when linking.
5464 \layout Subsubsection
5466 Optimization Options
5467 \begin_inset LatexCommand \index{Options optimization}
5472 \begin_inset LatexCommand \index{Optimization options}
5478 \labelwidthstring 00.00.0000
5493 \begin_inset LatexCommand \index{-\/-nogcse}
5499 Will not do global subexpression elimination, this option may be used when
5500 the compiler creates undesirably large stack/data spaces to store compiler
5502 A warning message will be generated when this happens and the compiler
5503 will indicate the number of extra bytes it allocated.
5504 It recommended that this option NOT be used, #pragma\SpecialChar ~
5506 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5510 can be used to turn off global subexpression elimination
5511 \begin_inset LatexCommand \index{Subexpression elimination}
5515 for a given function only.
5517 \labelwidthstring 00.00.0000
5532 \begin_inset LatexCommand \index{-\/-noinvariant}
5538 Will not do loop invariant optimizations, this may be turned off for reasons
5539 explained for the previous option.
5540 For more details of loop optimizations performed see section Loop Invariants.It
5541 recommended that this option NOT be used, #pragma\SpecialChar ~
5543 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5547 can be used to turn off invariant optimizations for a given function only.
5549 \labelwidthstring 00.00.0000
5564 \begin_inset LatexCommand \index{-\/-noinduction}
5570 Will not do loop induction optimizations, see section strength reduction
5571 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5574 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5578 can be used to turn off induction optimizations for a given function only.
5580 \labelwidthstring 00.00.0000
5595 \begin_inset LatexCommand \index{-\/-nojtbound}
5606 Will not generate boundary condition check when switch statements
5607 \begin_inset LatexCommand \index{switch statement}
5611 are implemented using jump-tables.
5612 See section Switch Statements for more details.
5613 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5615 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5619 can be used to turn off boundary checking for jump tables for a given function
5622 \labelwidthstring 00.00.0000
5637 \begin_inset LatexCommand \index{-\/-noloopreverse}
5646 Will not do loop reversal
5647 \begin_inset LatexCommand \index{Loop reversing}
5653 \labelwidthstring 00.00.0000
5670 \begin_inset LatexCommand \index{-\/-nolabelopt }
5674 Will not optimize labels (makes the dumpfiles more readable).
5676 \labelwidthstring 00.00.0000
5691 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5697 Will not memcpy initialized data from code space into xdata space.
5698 This saves a few bytes in code space if you don't have initialized data.
5699 \layout Subsubsection
5702 \begin_inset LatexCommand \index{Options other}
5708 \labelwidthstring 00.00.0000
5724 \begin_inset LatexCommand \index{-\/-compile-only}
5729 \begin_inset LatexCommand \index{-c -\/-compile-only}
5735 will compile and assemble the source, but will not call the linkage editor.
5737 \labelwidthstring 00.00.0000
5756 \begin_inset LatexCommand \index{-\/-c1mode}
5762 reads the preprocessed source from standard input and compiles it.
5763 The file name for the assembler output must be specified using the -o option.
5765 \labelwidthstring 00.00.0000
5770 \begin_inset LatexCommand \index{-E}
5776 Run only the C preprocessor.
5777 Preprocess all the C source files specified and output the results to standard
5780 \labelwidthstring 00.00.0000
5786 \begin_inset LatexCommand \index{-o <path/file>}
5792 The output path resp.
5793 file where everything will be placed.
5794 If the parameter is a path, it must have a trailing slash (or backslash
5795 for the Windows binaries) to be recognized as a path.
5798 \labelwidthstring 00.00.0000
5813 \begin_inset LatexCommand \index{-\/-stack-auto}
5824 All functions in the source file will be compiled as
5829 \begin_inset LatexCommand \index{reentrant}
5834 the parameters and local variables will be allocated on the stack
5835 \begin_inset LatexCommand \index{stack}
5840 see section Parameters and Local Variables for more details.
5841 If this option is used all source files in the project should be compiled
5845 \labelwidthstring 00.00.0000
5860 \begin_inset LatexCommand \index{-\/-callee-saves}
5864 function1[,function2][,function3]....
5867 The compiler by default uses a caller saves convention for register saving
5868 across function calls, however this can cause unnecessary register pushing
5869 & popping when calling small functions from larger functions.
5870 This option can be used to switch the register saving convention for the
5871 function names specified.
5872 The compiler will not save registers when calling these functions, no extra
5873 code will be generated at the entry & exit (function prologue
5876 \begin_inset LatexCommand \index{function prologue}
5885 \begin_inset LatexCommand \index{function epilogue}
5891 ) for these functions to save & restore the registers used by these functions,
5892 this can SUBSTANTIALLY reduce code & improve run time performance of the
5894 In the future the compiler (with inter procedural analysis) will be able
5895 to determine the appropriate scheme to use for each function call.
5896 DO NOT use this option for built-in functions such as _mulint..., if this
5897 option is used for a library function the appropriate library function
5898 needs to be recompiled with the same option.
5899 If the project consists of multiple source files then all the source file
5900 should be compiled with the same -
5910 -callee-saves option string.
5911 Also see #pragma\SpecialChar ~
5913 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5919 \labelwidthstring 00.00.0000
5934 \begin_inset LatexCommand \index{-\/-debug}
5943 When this option is used the compiler will generate debug information, that
5944 can be used with the SDCDB.
5945 The debug information is collected in a file with .cdb extension.
5946 For more information see documentation for SDCDB.
5948 \labelwidthstring 00.00.0000
5953 \begin_inset LatexCommand \index{-S}
5964 Stop after the stage of compilation proper; do not assemble.
5965 The output is an assembler code file for the input file specified.
5967 \labelwidthstring 00.00.0000
5971 -Wa_asmOption[,asmOption]
5974 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5979 Pass the asmOption to the assembler.
5981 \labelwidthstring 00.00.0000
5985 -Wl_linkOption[,linkOption]
5988 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5993 Pass the linkOption to the linker.
5995 \labelwidthstring 00.00.0000
6010 \begin_inset LatexCommand \index{-\/-int-long-reent}
6016 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6017 Note by default these libraries are compiled as non-reentrant.
6018 See section Installation for more details.
6020 \labelwidthstring 00.00.0000
6035 \begin_inset LatexCommand \index{-\/-cyclomatic}
6044 This option will cause the compiler to generate an information message for
6045 each function in the source file.
6046 The message contains some
6050 information about the function.
6051 The number of edges and nodes the compiler detected in the control flow
6052 graph of the function, and most importantly the
6054 cyclomatic complexity
6055 \begin_inset LatexCommand \index{Cyclomatic complexity}
6061 see section on Cyclomatic Complexity for more details.
6063 \labelwidthstring 00.00.0000
6078 \begin_inset LatexCommand \index{-\/-float-reent}
6087 Floating point library is compiled as reentrant
6088 \begin_inset LatexCommand \index{reentrant}
6093 See section Installation for more details.
6095 \labelwidthstring 00.00.0000
6110 \begin_inset LatexCommand \index{-\/-nooverlay}
6116 The compiler will not overlay parameters and local variables of any function,
6117 see section Parameters and local variables for more details.
6119 \labelwidthstring 00.00.0000
6134 \begin_inset LatexCommand \index{-\/-main-return}
6140 This option can be used when the code generated is called by a monitor
6142 The compiler will generate a 'ret' upon return from the 'main'
6143 \begin_inset LatexCommand \index{main return}
6148 The default option is to lock up i.e.
6155 \labelwidthstring 00.00.0000
6172 \begin_inset LatexCommand \index{-\/-peep-file}
6176 <filename> This option can be used to use additional rules to be used by
6177 the peep hole optimizer.
6178 See section Peep Hole optimizations for details on how to write these rules.
6180 \labelwidthstring 00.00.0000
6195 \begin_inset LatexCommand \index{-\/-no-peep}
6201 Disable peep-hole optimization.
6203 \labelwidthstring 00.00.0000
6218 \begin_inset LatexCommand \index{-\/-peep-asm}
6224 Pass the inline assembler code through the peep hole optimizer.
6225 This can cause unexpected changes to inline assembler code, please go through
6226 the peephole optimizer
6227 \begin_inset LatexCommand \index{Peephole optimizer}
6231 rules defined in the source file tree '<target>/peeph.def' before using
6234 \labelwidthstring 00.00.0000
6249 \begin_inset LatexCommand \index{-\/-nostdincl}
6255 This will prevent the compiler from passing on the default include path
6256 to the preprocessor.
6258 \labelwidthstring 00.00.0000
6273 \begin_inset LatexCommand \index{-\/-nostdlib}
6279 This will prevent the compiler from passing on the default library
6280 \begin_inset LatexCommand \index{Libraries}
6286 \labelwidthstring 00.00.0000
6301 \begin_inset LatexCommand \index{-\/-verbose}
6307 Shows the various actions the compiler is performing.
6309 \labelwidthstring 00.00.0000
6314 \begin_inset LatexCommand \index{-V}
6320 Shows the actual commands the compiler is executing.
6322 \labelwidthstring 00.00.0000
6337 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6343 Hides your ugly and inefficient c-code from the asm file, so you can always
6344 blame the compiler :).
6346 \labelwidthstring 00.00.0000
6361 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6367 Include i-codes in the asm file.
6368 Sounds like noise but is most helpful for debugging the compiler itself.
6370 \labelwidthstring 00.00.0000
6385 \begin_inset LatexCommand \index{-\/-less-pedantic}
6391 Disable some of the more pedantic warnings (jwk burps: please be more specific
6394 \labelwidthstring 00.00.0000
6409 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6415 Display the directories in the compiler's search path
6417 \labelwidthstring 00.00.0000
6432 \begin_inset LatexCommand \index{-\/-vc}
6438 Display errors and warnings using MSVC style, so you can use SDCC with
6441 \labelwidthstring 00.00.0000
6456 \begin_inset LatexCommand \index{-\/-use-stdout}
6462 Send errors and warnings to stdout instead of stderr.
6463 \layout Subsubsection
6465 Intermediate Dump Options
6466 \begin_inset LatexCommand \index{Options intermediate dump}
6471 \begin_inset LatexCommand \index{Intermediate dump options}
6478 The following options are provided for the purpose of retargetting and debugging
6480 These provided a means to dump the intermediate code (iCode
6481 \begin_inset LatexCommand \index{iCode}
6485 ) generated by the compiler in human readable form at various stages of
6486 the compilation process.
6489 \labelwidthstring 00.00.0000
6504 \begin_inset LatexCommand \index{-\/-dumpraw}
6510 This option will cause the compiler to dump the intermediate code into
6513 <source filename>.dumpraw
6515 just after the intermediate code has been generated for a function, i.e.
6516 before any optimizations are done.
6518 \begin_inset LatexCommand \index{Basic blocks}
6522 at this stage ordered in the depth first number, so they may not be in
6523 sequence of execution.
6525 \labelwidthstring 00.00.0000
6540 \begin_inset LatexCommand \index{-\/-dumpgcse}
6546 Will create a dump of iCode's, after global subexpression elimination
6547 \begin_inset LatexCommand \index{Global subexpression elimination}
6553 <source filename>.dumpgcse.
6555 \labelwidthstring 00.00.0000
6570 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6576 Will create a dump of iCode's, after deadcode elimination
6577 \begin_inset LatexCommand \index{Dead-code elimination}
6583 <source filename>.dumpdeadcode.
6585 \labelwidthstring 00.00.0000
6600 \begin_inset LatexCommand \index{-\/-dumploop}
6609 Will create a dump of iCode's, after loop optimizations
6610 \begin_inset LatexCommand \index{Loop optimization}
6616 <source filename>.dumploop.
6618 \labelwidthstring 00.00.0000
6633 \begin_inset LatexCommand \index{-\/-dumprange}
6642 Will create a dump of iCode's, after live range analysis
6643 \begin_inset LatexCommand \index{Live range analysis}
6649 <source filename>.dumprange.
6651 \labelwidthstring 00.00.0000
6666 \begin_inset LatexCommand \index{-\/-dumlrange}
6672 Will dump the life ranges
6673 \begin_inset LatexCommand \index{Live range analysis}
6679 \labelwidthstring 00.00.0000
6694 \begin_inset LatexCommand \index{-\/-dumpregassign}
6703 Will create a dump of iCode's, after register assignment
6704 \begin_inset LatexCommand \index{Register assignment}
6710 <source filename>.dumprassgn.
6712 \labelwidthstring 00.00.0000
6727 \begin_inset LatexCommand \index{-\/-dumplrange}
6733 Will create a dump of the live ranges of iTemp's
6735 \labelwidthstring 00.00.0000
6750 \begin_inset LatexCommand \index{-\/-dumpall}
6761 Will cause all the above mentioned dumps to be created.
6762 \layout Subsubsection
6764 Redirecting output on Windows Shells
6767 By default SDCC writes it's error messages to
6768 \begin_inset Quotes sld
6772 \begin_inset Quotes srd
6776 To force all messages to
6777 \begin_inset Quotes sld
6781 \begin_inset Quotes srd
6805 \begin_inset LatexCommand \index{-\/-use-stdout}
6810 Aditionaly, if you happen to have visual studio installed in your windows
6811 machine, you can use it to compile your sources using a custom build and
6827 \begin_inset LatexCommand \index{-\/-vc}
6832 Something like this should work:
6876 -model-large -c $(InputPath)
6879 Environment variables
6880 \begin_inset LatexCommand \index{Environment variables}
6887 SDCC recognizes the following environment variables:
6889 \labelwidthstring 00.00.0000
6894 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6900 SDCC installs a signal handler
6901 \begin_inset LatexCommand \index{signal handler}
6905 to be able to delete temporary files after an user break (^C) or an exception.
6906 If this environment variable is set, SDCC won't install the signal handler
6907 in order to be able to debug SDCC.
6909 \labelwidthstring 00.00.0000
6916 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
6922 Path, where temporary files will be created.
6923 The order of the variables is the search order.
6924 In a standard *nix environment these variables are not set, and there's
6925 no need to set them.
6926 On Windows it's recommended to set one of them.
6928 \labelwidthstring 00.00.0000
6933 \begin_inset LatexCommand \index{SDCC\_HOME}
6940 \begin_inset Quotes sld
6943 2.3 Install and search paths
6944 \begin_inset Quotes srd
6949 \labelwidthstring 00.00.0000
6954 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6961 \begin_inset Quotes sld
6964 2.3 Install and search paths
6965 \begin_inset Quotes srd
6970 \labelwidthstring 00.00.0000
6975 \begin_inset LatexCommand \index{SDCC\_LIB}
6982 \begin_inset Quotes sld
6985 2.3 Install and search paths
6986 \begin_inset Quotes srd
6992 There are some more environment variables recognized by SDCC, but these
6993 are solely used for debugging purposes.
6994 They can change or disappear very quickly, and will never be documented.
6997 MCS51/DS390 Storage Class
6998 \begin_inset LatexCommand \index{Storage class}
7005 In addition to the ANSI storage classes SDCC allows the following MCS51
7006 specific storage classes.
7007 \layout Subsubsection
7010 \begin_inset LatexCommand \index{data}
7021 storage class for Small Memory model.
7022 Variables declared with this storage class will be allocated in the directly
7023 addressable portion of the internal RAM of a 8051, e.g.:
7028 data unsigned char test_data;
7031 Writing 0x01 to this variable generates the assembly code:
7036 75*00 01\SpecialChar ~
7042 \layout Subsubsection
7045 \begin_inset LatexCommand \index{xdata}
7052 Variables declared with this storage class will be placed in the external
7058 storage class for Large Memory model, e.g.:
7063 xdata unsigned char test_xdata;
7066 Writing 0x01 to this variable generates the assembly code:
7071 90s00r00\SpecialChar ~
7100 \layout Subsubsection
7103 \begin_inset LatexCommand \index{idata}
7110 Variables declared with this storage class will be allocated into the indirectly
7111 addressable portion of the internal ram of a 8051, e.g.:
7116 idata unsigned char test_idata;
7119 Writing 0x01 to this variable generates the assembly code:
7146 \layout Subsubsection
7149 \begin_inset LatexCommand \index{pdata}
7156 Paged xdata access is currently not as straightforward as using the other
7157 addressing modes of a 8051.
7158 The following example writes 0x01 to the address pointed to.
7159 Please note, pdata access physically accesses xdata memory.
7160 The high byte of the address is determined by port P2 (or in case of some
7161 8051 variants by a separate Special Function Register).
7166 pdata unsigned char *test_pdata_ptr;
7178 test_pdata_ptr = (pdata *)0xfe;
7184 *test_pdata_ptr = 1;
7189 Generates the assembly code:
7194 75*01 FE\SpecialChar ~
7198 _test_pdata_ptr,#0xFE
7230 Be extremely carefull if you use pdata together with the -
7241 \begin_inset LatexCommand \index{-\/-xstack}
7246 \layout Subsubsection
7249 \begin_inset LatexCommand \index{code}
7256 'Variables' declared with this storage class will be placed in the code
7262 code unsigned char test_code;
7265 Read access to this variable generates the assembly code:
7270 90s00r6F\SpecialChar ~
7273 mov dptr,#_test_code
7296 \layout Subsubsection
7299 \begin_inset LatexCommand \index{bit}
7306 This is a data-type and a storage class specifier.
7307 When a variable is declared as a bit, it is allocated into the bit addressable
7308 memory of 8051, e.g.:
7316 Writing 1 to this variable generates the assembly code:
7330 \layout Subsubsection
7333 \begin_inset LatexCommand \index{sfr}
7338 \begin_inset LatexCommand \index{sbit}
7345 Like the bit keyword,
7349 signifies both a data-type and storage class, they are used to describe
7350 the special function registers and special bit variables of a 8051, eg:
7356 \begin_inset LatexCommand \index{at}
7360 0x80 P0;\SpecialChar ~
7361 /* special function register P0 at location 0x80 */
7363 sbit at 0xd7 CY; /* CY (Carry Flag
7364 \begin_inset LatexCommand \index{Flags}
7369 \begin_inset LatexCommand \index{Carry flag}
7374 \layout Subsubsection
7377 \begin_inset LatexCommand \index{Pointers}
7381 to MCS51/DS390 specific memory spaces
7384 SDCC allows (via language extensions) pointers to explicitly point to any
7385 of the memory spaces
7386 \begin_inset LatexCommand \index{Memory model}
7391 In addition to the explicit pointers, the compiler uses (by default) generic
7392 pointers which can be used to point to any of the memory spaces.
7396 Pointer declaration examples:
7401 /* pointer physically in internal ram pointing to object in external ram
7404 xdata unsigned char * data p;
7408 /* pointer physically in external ram pointing to object in internal ram
7411 data unsigned char * xdata p;
7415 /* pointer physically in code rom pointing to data in xdata space */
7417 xdata unsigned char * code p;
7421 /* pointer physically in code space pointing to data in code space */
7423 code unsigned char * code p;
7427 /* the following is a generic pointer physically located in xdata space
7433 Well you get the idea.
7438 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7451 The highest order byte of the
7455 pointers contains the data space information.
7456 Assembler support routines are called whenever data is stored or retrieved
7462 These are useful for developing reusable library
7463 \begin_inset LatexCommand \index{Libraries}
7468 Explicitly specifying the pointer type will generate the most efficient
7473 \begin_inset LatexCommand \index{Absolute addressing}
7480 Data items can be assigned an absolute address with the
7483 \begin_inset LatexCommand \index{at}
7489 keyword, in addition to a storage class, e.g.:
7495 \begin_inset LatexCommand \index{xdata}
7500 \begin_inset LatexCommand \index{at}
7504 0x7ffe unsigned int chksum;
7507 In the above example the variable chksum will located at 0x7ffe and 0x7fff
7508 of the external ram.
7509 The compiler does not actually reserve any space for variables declared
7510 in this way (they are implemented with an equate in the assembler).
7511 Thus it is left to the programmer to make sure there are no overlaps with
7512 other variables that are declared without the absolute address.
7513 The assembler listing file (.lst
7514 \begin_inset LatexCommand \index{.lst}
7518 ) and the linker output files (.rst
7519 \begin_inset LatexCommand \index{.rst}
7524 \begin_inset LatexCommand \index{.map}
7528 ) are good places to look for such overlaps.
7531 In case of memory mapped I/O devices the keyword
7535 should be used to tell the compiler that accesses might not be optimized
7542 \begin_inset LatexCommand \index{volatile}
7547 \begin_inset LatexCommand \index{xdata}
7552 \begin_inset LatexCommand \index{at}
7556 0x8000 unsigned char PORTA_8255;
7559 Absolute address can be specified for variables in all storage classes,
7566 \begin_inset LatexCommand \index{bit}
7571 \begin_inset LatexCommand \index{at}
7578 The above example will allocate the variable at offset 0x02 in the bit-addressab
7580 There is no real advantage to assigning absolute addresses to variables
7581 in this manner, unless you want strict control over all the variables allocated.
7582 One possible use would be to write hardware portable code.
7583 For example, if you have a routine that uses one or more of the microcontroller
7584 I/O pins, and such pins are different for two different hardwares, you
7585 can declare the I/O pins in your routine using:
7590 extern volatile bit SDI;
7592 extern volatile bit SCLK;
7594 extern volatile bit CPOL;
7598 void DS1306_put(unsigned char value)
7606 unsigned char mask=0x80;
7630 SDI=(value & mask)?1:0;
7671 Then, someplace in the code for the first hardware you would use
7676 bit at 0x80 SDI;\SpecialChar ~
7680 /* I/O port 0, bit 0 */
7682 bit at 0x81 SCLK;\SpecialChar ~
7685 /* I/O port 0, bit 1 */
7687 bit CPOL;\SpecialChar ~
7698 /* This is a variable, let the linker allocate this one */
7701 Similarly, for the second hardware you would use
7706 bit at 0x83 SDI;\SpecialChar ~
7710 /* I/O port 0, bit 3 */
7712 bit at 0x91 SCLK;\SpecialChar ~
7715 /* I/O port 1, bit 1 */
7717 bit CPOL;\SpecialChar ~
7728 /* This is a variable, let the linker allocate this one */
7731 and you can use the same hardware dependent routine without changes, as
7732 for example in a library.
7733 This is somehow similar to sbit, but only one absolute address has to be
7734 specified in the whole project.
7738 \begin_inset LatexCommand \index{Parameters}
7743 \begin_inset LatexCommand \index{Local variable}
7750 Automatic (local) variables and parameters to functions can either be placed
7751 on the stack or in data-space.
7752 The default action of the compiler is to place these variables in the internal
7753 RAM (for small model) or external RAM (for large model).
7754 This in fact makes them
7757 \begin_inset LatexCommand \index{static}
7763 so by default functions are non-reentrant
7764 \begin_inset LatexCommand \index{reentrant}
7772 They can be placed on the stack
7773 \begin_inset LatexCommand \index{stack}
7790 \begin_inset LatexCommand \index{-\/-stack-auto}
7796 option or by using the
7799 \begin_inset LatexCommand \index{reentrant}
7805 keyword in the function declaration, e.g.:
7810 unsigned char foo(char i) reentrant
7824 Since stack space on 8051 is limited, the
7842 option should be used sparingly.
7843 Note that the reentrant keyword just means that the parameters & local
7844 variables will be allocated to the stack, it
7848 mean that the function is register bank independent.
7852 Local variables can be assigned storage classes and absolute
7853 \begin_inset LatexCommand \index{Absolute addressing}
7870 xdata unsigned char i;
7882 data at 0x31 unsigned char j;
7894 In the above example the variable
7898 will be allocated in the external ram,
7902 in bit addressable space and
7921 or when a function is declared as
7925 this should only be done for static variables.
7928 Parameters however are not allowed any storage class, (storage classes for
7929 parameters will be ignored), their allocation is governed by the memory
7930 model in use, and the reentrancy options.
7934 \begin_inset LatexCommand \label{sub:Overlaying}
7939 \begin_inset LatexCommand \index{Overlaying}
7947 \begin_inset LatexCommand \index{reentrant}
7951 functions SDCC will try to reduce internal ram space usage by overlaying
7952 parameters and local variables of a function (if possible).
7953 Parameters and local variables of a function will be allocated to an overlayabl
7954 e segment if the function has
7956 no other function calls and the function is non-reentrant and the memory
7958 \begin_inset LatexCommand \index{Memory model}
7965 If an explicit storage class
7966 \begin_inset LatexCommand \index{Storage class}
7970 is specified for a local variable, it will NOT be overlayed.
7973 Note that the compiler (not the linkage editor) makes the decision for overlayin
7975 Functions that are called from an interrupt service routine should be preceded
7976 by a #pragma\SpecialChar ~
7978 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7982 if they are not reentrant.
7985 Also note that the compiler does not do any processing of inline
7986 \begin_inset LatexCommand \index{inline}
7990 assembler code, so the compiler might incorrectly assign local variables
7991 and parameters of a function into the overlay segment if the inline assembler
7992 code calls other c-functions that might use the overlay.
7993 In that case the #pragma\SpecialChar ~
7994 NOOVERLAY should be used.
7997 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7999 \begin_inset LatexCommand \index{Multiplication}
8004 \begin_inset LatexCommand \index{Division}
8008 will NOT be overlayed since these are implemented using external functions,
8017 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8023 void set_error(unsigned char errcd)
8039 void some_isr () interrupt
8040 \begin_inset LatexCommand \index{interrupt}
8070 In the above example the parameter
8078 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8080 not present, this could cause unpredictable runtime behavior when called
8082 The #pragma\SpecialChar ~
8083 NOOVERLAY ensures that the parameters and local variables for
8084 the function are NOT overlayed.
8087 Interrupt Service Routines
8090 SDCC allows interrupt service routines to be coded in C, with some extended
8096 void timer_isr (void) interrupt 1 using 1
8110 The optional number following the
8113 \begin_inset LatexCommand \index{interrupt}
8119 keyword is the interrupt number this routine will service.
8120 When present, the compiler will insert a call to this routine in the interrupt
8121 vector table for the interrupt number specified.
8126 keyword can be used to tell the compiler to use the specified register
8127 bank (8051 specific) when generating code for this function.
8128 Note that when some function is called from an interrupt service routine
8129 it should be preceded by a #pragma\SpecialChar ~
8131 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8135 if it is not reentrant.
8136 Furthermore nonreentrant functions should not be called from the main program
8137 while the interrupt service routine might be active.
8138 If the interrupt service routines changes variables which are accessed
8139 by other functions these variables should be declared
8144 \begin_inset LatexCommand \index{volatile}
8152 A special note here, int (16 bit) and long (32 bit) integer division
8153 \begin_inset LatexCommand \index{Division}
8158 \begin_inset LatexCommand \index{Multiplication}
8163 \begin_inset LatexCommand \index{Modulus}
8167 operations are implemented using external support routines developed in
8168 ANSI-C, if an interrupt service routine needs to do any of these operations
8169 then the support routines (as mentioned in a following section) will have
8170 to be recompiled using the
8183 \begin_inset LatexCommand \index{-\/-stack-auto}
8189 option and the source file will need to be compiled using the
8204 \begin_inset LatexCommand \index{-\/-int-long-rent}
8211 If you have multiple source files in your project, interrupt service routines
8212 can be present in any of them, but a prototype of the isr MUST be present
8213 or included in the file that contains the function
8220 Interrupt numbers and the corresponding address & descriptions for the Standard
8221 8051/8052 are listed below.
8222 SDCC will automatically adjust the interrupt vector table to the maximum
8223 interrupt number specified.
8229 \begin_inset Tabular
8230 <lyxtabular version="3" rows="7" columns="3">
8232 <column alignment="center" valignment="top" leftline="true" width="0in">
8233 <column alignment="center" valignment="top" leftline="true" width="0in">
8234 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
8235 <row topline="true" bottomline="true">
8236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8261 <row topline="true">
8262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8287 <row topline="true">
8288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8313 <row topline="true">
8314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8339 <row topline="true">
8340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8365 <row topline="true">
8366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8391 <row topline="true" bottomline="true">
8392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8426 If the interrupt service routine is defined without
8429 \begin_inset LatexCommand \index{using}
8435 a register bank or with register bank 0 (using 0), the compiler will save
8436 the registers used by itself on the stack upon entry and restore them at
8437 exit, however if such an interrupt service routine calls another function
8438 then the entire register bank will be saved on the stack.
8439 This scheme may be advantageous for small interrupt service routines which
8440 have low register usage.
8443 If the interrupt service routine is defined to be using a specific register
8448 are save and restored, if such an interrupt service routine calls another
8449 function (using another register bank) then the entire register bank of
8450 the called function will be saved on the stack.
8451 This scheme is recommended for larger interrupt service routines.
8454 Calling other functions from an interrupt service routine is not recommended,
8455 avoid it if possible.
8457 For some pitfalls see section
8458 \begin_inset LatexCommand \ref{sub:Overlaying}
8462 about Overlaying and section
8463 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8467 about Functions using private banks.
8477 <TODO: this isn't implemented at all!>
8483 A special keyword may be associated with a function declaring it as
8488 SDCC will generate code to disable all interrupts upon entry to a critical
8489 function and enable them back before returning.
8490 Note that nesting critical functions may cause unpredictable results.
8516 The critical attribute maybe used with other attributes like
8522 \begin_inset LatexCommand \label{sub:Naked-Functions}
8527 \begin_inset LatexCommand \index{Naked functions}
8534 A special keyword may be associated with a function declaring it as
8537 \begin_inset LatexCommand \index{\_naked}
8548 function modifier attribute prevents the compiler from generating prologue
8549 \begin_inset LatexCommand \index{function prologue}
8554 \begin_inset LatexCommand \index{function epilogue}
8558 code for that function.
8559 This means that the user is entirely responsible for such things as saving
8560 any registers that may need to be preserved, selecting the proper register
8561 bank, generating the
8565 instruction at the end, etc.
8566 Practically, this means that the contents of the function must be written
8567 in inline assembler.
8568 This is particularly useful for interrupt functions, which can have a large
8569 (and often unnecessary) prologue/epilogue.
8570 For example, compare the code generated by these two functions:
8576 \begin_inset LatexCommand \index{volatile}
8580 data unsigned char counter;
8584 void simpleInterrupt(void) interrupt
8585 \begin_inset LatexCommand \index{interrupt}
8603 void nakedInterrupt(void) interrupt 2 _naked
8612 \begin_inset LatexCommand \index{\_asm}
8641 ; MUST explicitly include ret or reti in _naked function.
8648 \begin_inset LatexCommand \index{\_endasm}
8657 For an 8051 target, the generated simpleInterrupt looks like:
8798 whereas nakedInterrupt looks like:
8822 ; MUST explicitly include ret or reti in _naked function.
8825 The #pragma directive EXCLUDE
8826 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
8830 also allows to reduce pushing & popping the registers.
8833 While there is nothing preventing you from writing C code inside a _naked
8834 function, there are many ways to shoot yourself in the foot doing this,
8835 and it is recommended that you stick to inline assembler.
8838 Functions using private banks
8839 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
8844 \begin_inset LatexCommand \index{bank}
8854 \begin_inset LatexCommand \index{using}
8860 attribute (which tells the compiler to use a register bank other than the
8861 default bank zero) should only be applied to
8864 \begin_inset LatexCommand \index{interrupt}
8870 functions (see note 1 below).
8871 This will in most circumstances make the generated ISR code more efficient
8872 since it will not have to save registers on the stack.
8879 attribute will have no effect on the generated code for a
8883 function (but may occasionally be useful anyway
8889 possible exception: if a function is called ONLY from 'interrupt' functions
8890 using a particular bank, it can be declared with the same 'using' attribute
8891 as the calling 'interrupt' functions.
8892 For instance, if you have several ISRs using bank one, and all of them
8893 call memcpy(), it might make sense to create a specialized version of memcpy()
8894 'using 1', since this would prevent the ISR from having to save bank zero
8895 to the stack on entry and switch to bank zero before calling the function
8902 (pending: I don't think this has been done yet)
8909 function using a non-zero bank will assume that it can trash that register
8910 bank, and will not save it.
8911 Since high-priority interrupts
8912 \begin_inset LatexCommand \index{interrupt priority}
8916 can interrupt low-priority ones on the 8051 and friends, this means that
8917 if a high-priority ISR
8921 a particular bank occurs while processing a low-priority ISR
8925 the same bank, terrible and bad things can happen.
8926 To prevent this, no single register bank should be
8930 by both a high priority and a low priority ISR.
8931 This is probably most easily done by having all high priority ISRs use
8932 one bank and all low priority ISRs use another.
8933 If you have an ISR which can change priority at runtime, you're on your
8934 own: I suggest using the default bank zero and taking the small performance
8938 It is most efficient if your ISR calls no other functions.
8939 If your ISR must call other functions, it is most efficient if those functions
8940 use the same bank as the ISR (see note 1 below); the next best is if the
8941 called functions use bank zero.
8942 It is very inefficient to call a function using a different, non-zero bank
8948 \begin_inset LatexCommand \label{sub:Startup-Code}
8953 \begin_inset LatexCommand \index{Startup code}
8960 The compiler inserts a call to the C routine
8962 _sdcc_external_startup()
8963 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8972 at the start of the CODE area.
8973 This routine is in the runtime library
8974 \begin_inset LatexCommand \index{Runtime library}
8979 By default this routine returns 0, if this routine returns a non-zero value,
8980 the static & global variable initialization will be skipped and the function
8981 main will be invoked.
8982 Otherwise static & global variables will be initialized before the function
8986 _sdcc_external_startup()
8988 routine to your program to override the default if you need to setup hardware
8989 or perform some other critical operation prior to static & global variable
8991 See also the compiler option
9010 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9017 Inline Assembler Code
9018 \begin_inset LatexCommand \index{Assembler routines}
9025 SDCC allows the use of in-line assembler with a few restriction as regards
9027 All labels defined within inline assembler code
9035 where nnnn is a number less than 100 (which implies a limit of utmost 100
9036 inline assembler labels
9044 It is strongly recommended that each assembly instruction (including labels)
9045 be placed in a separate line (as the example shows).
9059 \begin_inset LatexCommand \index{-\/-peep-asm}
9065 command line option is used, the inline assembler code will be passed through
9066 the peephole optimizer
9067 \begin_inset LatexCommand \index{Peephole optimizer}
9072 This might cause some unexpected changes in the inline assembler code.
9073 Please go through the peephole optimizer rules defined in file
9077 carefully before using this option.
9083 \begin_inset LatexCommand \index{\_asm}
9113 \begin_inset LatexCommand \index{\_endasm}
9120 The inline assembler code can contain any valid code understood by the assembler
9121 , this includes any assembler directives and comment lines.
9122 The compiler does not do any validation of the code within the
9132 Inline assembler code cannot reference any C-Labels, however it can reference
9134 \begin_inset LatexCommand \index{Labels}
9138 defined by the inline assembler, e.g.:
9163 ; some assembler code
9183 /* some more c code */
9185 clabel:\SpecialChar ~
9187 /* inline assembler cannot reference this label */
9199 $0003: ;label (can be reference by inline assembler only)
9211 /* some more c code */
9216 In other words inline assembly code can access labels defined in inline
9217 assembly within the scope of the function.
9218 The same goes the other way, ie.
9219 labels defines in inline assembly CANNOT be accessed by C statements.
9222 An example acessing a C variable is in section
9223 \begin_inset LatexCommand \ref{sub:Naked-Functions}
9230 Interfacing with Assembler Code
9231 \begin_inset LatexCommand \index{Assembler routines}
9236 \layout Subsubsection
9238 Global Registers used for Parameter Passing
9239 \begin_inset LatexCommand \index{Parameter passing}
9246 The compiler always uses the global registers
9249 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9254 \begin_inset LatexCommand \index{B (register)}
9263 \begin_inset LatexCommand \index{ACC}
9269 to pass the first parameter to a routine.
9270 The second parameter onwards is either allocated on the stack (for reentrant
9281 -stack-auto is used) or in data / xdata memory (depending on the memory
9284 \layout Subsubsection
9286 Assembler Routine(non-reentrant
9287 \begin_inset LatexCommand \index{reentrant}
9292 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
9299 In the following example the function c_func calls an assembler routine
9300 asm_func, which takes two parameters.
9305 extern int asm_func(unsigned char, unsigned char);
9309 int c_func (unsigned char i, unsigned char j)
9317 return asm_func(i,j);
9331 return c_func(10,9);
9336 The corresponding assembler function is:
9341 .globl _asm_func_PARM_2
9405 add a,_asm_func_PARM_2
9430 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9447 Note here that the return values are placed in 'dpl' - One byte return value,
9448 'dpl' LSB & 'dph' MSB for two byte values.
9449 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9450 b' & 'acc' for four byte values.
9453 The parameter naming convention is _<function_name>_PARM_<n>, where n is
9454 the parameter number starting from 1, and counting from the left.
9455 The first parameter is passed in
9456 \begin_inset Quotes eld
9460 \begin_inset Quotes erd
9463 for One bye parameter,
9464 \begin_inset Quotes eld
9468 \begin_inset Quotes erd
9472 \begin_inset Quotes eld
9476 \begin_inset Quotes erd
9480 \begin_inset Quotes eld
9484 \begin_inset Quotes erd
9487 for four bytes, the variable name for the second parameter will be _<function_n
9492 Assemble the assembler routine with the following command:
9499 asx8051 -losg asmfunc.asm
9506 Then compile and link the assembler routine to the C source file with the
9514 sdcc cfunc.c asmfunc.rel
9515 \layout Subsubsection
9517 Assembler Routine(reentrant
9518 \begin_inset LatexCommand \index{reentrant}
9523 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
9530 In this case the second parameter onwards will be passed on the stack, the
9531 parameters are pushed from right to left i.e.
9532 after the call the left most parameter will be on the top of the stack.
9538 extern int asm_func(unsigned char, unsigned char);
9542 int c_func (unsigned char i, unsigned char j) reentrant
9550 return asm_func(i,j);
9564 return c_func(10,9);
9569 The corresponding assembler routine is:
9675 The compiling and linking procedure remains the same, however note the extra
9676 entry & exit linkage required for the assembler code, _bp is the stack
9677 frame pointer and is used to compute the offset into the stack for parameters
9678 and local variables.
9682 \begin_inset LatexCommand \index{int (16 bit)}
9687 \begin_inset LatexCommand \index{long (32 bit)}
9694 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
9695 multiplication and modulus operations are implemented by support routines.
9696 These support routines are all developed in ANSI-C to facilitate porting
9697 to other MCUs, although some model specific assembler optimizations are
9699 The following files contain the described routines, all of them can be
9700 found in <installdir>/share/sdcc/lib.
9706 \begin_inset Tabular
9707 <lyxtabular version="3" rows="11" columns="2">
9709 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9710 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9711 <row topline="true" bottomline="true">
9712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9733 <row topline="true">
9734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9747 16 bit multiplication
9751 <row topline="true">
9752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9765 signed 16 bit division (calls _divuint)
9769 <row topline="true">
9770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9783 unsigned 16 bit division
9787 <row topline="true">
9788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9801 signed 16 bit modulus (calls _moduint)
9805 <row topline="true">
9806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9819 unsigned 16 bit modulus
9823 <row topline="true">
9824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9837 32 bit multiplication
9841 <row topline="true">
9842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9855 signed 32 division (calls _divulong)
9859 <row topline="true">
9860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9873 unsigned 32 division
9877 <row topline="true">
9878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9891 signed 32 bit modulus (calls _modulong)
9895 <row topline="true" bottomline="true">
9896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9909 unsigned 32 bit modulus
9922 Since they are compiled as
9927 \begin_inset LatexCommand \index{reentrant}
9932 \begin_inset LatexCommand \index{interrupt}
9936 service routines should not do any of the above operations.
9937 If this is unavoidable then the above routines will need to be compiled
9951 \begin_inset LatexCommand \index{-\/-stack-auto}
9957 option, after which the source program will have to be compiled with
9970 \begin_inset LatexCommand \index{-\/-int-long-rent}
9977 Notice that you don't have to call this routines directly.
9978 The compiler will use them automatically every time a integer operation
9982 Floating Point Support
9983 \begin_inset LatexCommand \index{Floating point support}
9990 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9991 floating point support routines are derived from gcc's floatlib.c and consists
9992 of the following routines:
10000 \begin_inset Tabular
10001 <lyxtabular version="3" rows="17" columns="2">
10003 <column alignment="center" valignment="top" leftline="true" width="0(null)">
10004 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
10005 <row topline="true" bottomline="true">
10006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10032 <row topline="true">
10033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10064 add floating point numbers
10068 <row topline="true">
10069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10100 subtract floating point numbers
10104 <row topline="true">
10105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10136 divide floating point numbers
10140 <row topline="true">
10141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10172 multiply floating point numbers
10176 <row topline="true">
10177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10208 convert floating point to unsigned char
10212 <row topline="true">
10213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10244 convert floating point to signed char
10248 <row topline="true">
10249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10280 convert floating point to unsigned int
10284 <row topline="true">
10285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10316 convert floating point to signed int
10320 <row topline="true">
10321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10361 convert floating point to unsigned long
10365 <row topline="true">
10366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10397 convert floating point to signed long
10401 <row topline="true">
10402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10433 convert unsigned char to floating point
10437 <row topline="true">
10438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10469 convert char to floating point number
10473 <row topline="true">
10474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10505 convert unsigned int to floating point
10509 <row topline="true">
10510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10541 convert int to floating point numbers
10545 <row topline="true">
10546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10577 convert unsigned long to floating point number
10581 <row topline="true" bottomline="true">
10582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10613 convert long to floating point number
10626 Note if all these routines are used simultaneously the data space might
10628 For serious floating point usage it is strongly recommended that the large
10630 Also notice that you don't have to call this routines directly.
10631 The compiler will use them automatically every time a floating point operation
10635 MCS51 Memory Models
10636 \begin_inset LatexCommand \index{Memory model}
10641 \begin_inset LatexCommand \index{MCS51 memory}
10648 SDCC allows two memory models for MCS51 code,
10657 Modules compiled with different memory models should
10661 be combined together or the results would be unpredictable.
10662 The library routines supplied with the compiler are compiled as both small
10664 The compiled library modules are contained in separate directories as small
10665 and large so that you can link to either set.
10669 When the large model is used all variables declared without a storage class
10670 will be allocated into the external ram, this includes all parameters and
10671 local variables (for non-reentrant
10672 \begin_inset LatexCommand \index{reentrant}
10677 When the small model is used variables without storage class are allocated
10678 in the internal ram.
10681 Judicious usage of the processor specific storage classes
10682 \begin_inset LatexCommand \index{Storage class}
10686 and the 'reentrant' function type will yield much more efficient code,
10687 than using the large model.
10688 Several optimizations are disabled when the program is compiled using the
10689 large model, it is therefore strongly recommended that the small model
10690 be used unless absolutely required.
10693 DS390 Memory Models
10694 \begin_inset LatexCommand \index{Memory model}
10699 \begin_inset LatexCommand \index{DS390 memory model}
10706 The only model supported is Flat 24
10707 \begin_inset LatexCommand \index{Flat 24 (memory model)}
10712 This generates code for the 24 bit contiguous addressing mode of the Dallas
10714 In this mode, up to four meg of external RAM or code space can be directly
10716 See the data sheets at www.dalsemi.com for further information on this part.
10720 Note that the compiler does not generate any code to place the processor
10721 into 24 bitmode (although
10725 in the ds390 libraries will do that for you).
10731 \begin_inset LatexCommand \index{Tinibios (DS390)}
10735 , the boot loader or similar code must ensure that the processor is in 24
10736 bit contiguous addressing mode before calling the SDCC startup code.
10754 option, variables will by default be placed into the XDATA segment.
10759 Segments may be placed anywhere in the 4 meg address space using the usual
10771 Note that if any segments are located above 64K, the -r flag must be passed
10772 to the linker to generate the proper segment relocations, and the Intel
10773 HEX output format must be used.
10774 The -r flag can be passed to the linker by using the option
10778 on the sdcc command line.
10779 However, currently the linker can not handle code segments > 64k.
10783 \begin_inset LatexCommand \index{Pragmas}
10790 SDCC supports the following #pragma directives.
10794 \begin_inset LatexCommand \index{\#pragma SAVE}
10798 - this will save all current options to the SAVE/RESTORE stack.
10803 \begin_inset LatexCommand \index{\#pragma RESTORE}
10807 - will restore saved options from the last save.
10808 SAVEs & RESTOREs can be nested.
10809 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
10810 RESTORE pulls current options from the stack.
10815 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10819 - will stop global common subexpression elimination.
10823 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10827 - will stop loop induction optimizations.
10831 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
10835 - will not generate code for boundary value checking, when switch statements
10836 are turned into jump-tables (dangerous).
10841 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
10845 - the compiler will not overlay the parameters and local variables of a
10850 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
10854 - the compiler will not warn you anymore for obvious mistakes, you'r on
10859 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
10863 - Will not do loop reversal optimization
10867 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10871 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
10873 \begin_inset LatexCommand \index{push/pop}
10877 instruction in ISR function (using interrupt
10878 \begin_inset LatexCommand \index{interrupt}
10883 The directive should be placed immediately before the ISR function definition
10884 and it affects ALL ISR functions following it.
10885 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
10886 EXCLUDE\SpecialChar ~
10888 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10896 \begin_inset LatexCommand \index{\#pragma NOIV}
10900 - Do not generate interrupt vector table entries for all ISR functions
10901 defined after the pragma.
10902 This is useful in cases where the interrupt vector table must be defined
10903 manually, or when there is a secondary, manually defined interrupt vector
10905 for the autovector feature of the Cypress EZ-USB FX2).
10909 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10914 \begin_inset LatexCommand \index{function prologue}
10918 function1[,function2[,function3...]] - The compiler by default uses a caller
10919 saves convention for register saving across function calls, however this
10920 can cause unnecessary register pushing & popping when calling small functions
10921 from larger functions.
10922 This option can be used to switch off the register saving convention for
10923 the function names specified.
10924 The compiler will not save registers when calling these functions, extra
10925 code need to be manually inserted at the entry & exit for these functions
10926 to save & restore the registers used by these functions, this can SUBSTANTIALLY
10927 reduce code & improve run time performance of the generated code.
10928 In the future the compiler (with inter procedural analysis) may be able
10929 to determine the appropriate scheme to use for each function call.
10940 -callee-saves command line option is used, the function names specified
10941 in #pragma\SpecialChar ~
10943 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10947 is appended to the list of functions specified in the command line.
10950 The pragma's are intended to be used to turn-off certain optimizations which
10951 might cause the compiler to generate extra stack / data space to store
10952 compiler generated temporary variables.
10953 This usually happens in large functions.
10954 Pragma directives should be used as shown in the following example, they
10955 are used to control options & optimizations for a given function; pragmas
10956 should be placed before and/or after a function, placing pragma's inside
10957 a function body could have unpredictable results.
10963 \begin_inset LatexCommand \index{\#pragma SAVE}
10974 /* save the current settings */
10977 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10986 /* turnoff global subexpression elimination */
10988 #pragma NOINDUCTION
10989 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10993 /* turn off induction optimizations */
11016 \begin_inset LatexCommand \index{\#pragma RESTORE}
11020 /* turn the optimizations back on */
11023 The compiler will generate a warning message when extra space is allocated.
11024 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11025 changing options for a function.
11028 Defines Created by the Compiler
11029 \begin_inset LatexCommand \index{Defines created by the compiler}
11036 The compiler creates the following #defines
11037 \begin_inset LatexCommand \index{\#defines}
11047 \begin_inset Tabular
11048 <lyxtabular version="3" rows="10" columns="2">
11050 <column alignment="center" valignment="top" leftline="true" width="0(null)">
11051 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
11052 <row topline="true" bottomline="true">
11053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11074 <row topline="true">
11075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11081 \begin_inset LatexCommand \index{SDCC}
11088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11093 this Symbol is always defined
11097 <row topline="true">
11098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11104 \begin_inset LatexCommand \index{SDCC\_mcs51}
11109 \begin_inset LatexCommand \index{SDCC\_ds390}
11114 \begin_inset LatexCommand \index{SDCC\_z80}
11121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11126 depending on the model used (e.g.: -mds390
11130 <row topline="true">
11131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11137 \begin_inset LatexCommand \index{\_\_mcs51}
11142 \begin_inset LatexCommand \index{\_\_ds390}
11147 \begin_inset LatexCommand \index{\_\_z80}
11154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11159 depending on the model used (e.g.
11164 <row topline="true">
11165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11171 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
11178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11201 <row topline="true">
11202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11208 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
11215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11238 <row topline="true">
11239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11245 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
11252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11275 <row topline="true">
11276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11282 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
11289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11312 <row topline="true">
11313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11319 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
11326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11339 <row topline="true" bottomline="true">
11340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11346 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
11353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11375 Debugging with SDCDB
11376 \begin_inset LatexCommand \index{sdcdb}
11383 SDCC is distributed with a source level debugger
11384 \begin_inset LatexCommand \index{Debugger}
11389 The debugger uses a command line interface, the command repertoire of the
11390 debugger has been kept as close to gdb
11391 \begin_inset LatexCommand \index{gdb}
11395 (the GNU debugger) as possible.
11396 The configuration and build process is part of the standard compiler installati
11397 on, which also builds and installs the debugger in the target directory
11398 specified during configuration.
11399 The debugger allows you debug BOTH at the C source and at the ASM source
11401 Sdcdb is available on Unix platforms only.
11404 Compiling for Debugging
11407 The \SpecialChar \-
11409 debug option must be specified for all files for which debug information
11410 is to be generated.
11411 The complier generates a .adb file for each of these files.
11412 The linker creates the .cdb file from the .adb files and the address information.
11413 This .cdb is used by the debugger.
11416 How the Debugger Works
11429 -debug option is specified the compiler generates extra symbol information
11430 some of which are put into the the assembler source and some are put into
11432 Then the linker creates the .cdb file from the individual .adb files with
11433 the address information for the symbols.
11434 The debugger reads the symbolic information generated by the compiler &
11435 the address information generated by the linker.
11436 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
11437 execution is controlled by the debugger.
11438 When a command is issued for the debugger, it translates it into appropriate
11439 commands for the simulator.
11442 Starting the Debugger
11445 The debugger can be started using the following command line.
11446 (Assume the file you are debugging has the file name foo).
11460 The debugger will look for the following files.
11463 foo.c - the source file.
11466 foo.cdb - the debugger symbol information file.
11469 foo.ihx - the Intel hex format
11470 \begin_inset LatexCommand \index{Intel hex format}
11477 Command Line Options.
11490 -directory=<source file directory> this option can used to specify the directory
11492 The debugger will look into the directory list specified for source, cdb
11494 The items in the directory list must be separated by ':', e.g.
11495 if the source files can be in the directories /home/src1 and /home/src2,
11506 -directory option should be -
11516 -directory=/home/src1:/home/src2.
11517 Note there can be no spaces in the option.
11521 -cd <directory> - change to the <directory>.
11524 -fullname - used by GUI front ends.
11527 -cpu <cpu-type> - this argument is passed to the simulator please see the
11528 simulator docs for details.
11531 -X <Clock frequency > this options is passed to the simulator please see
11532 the simulator docs for details.
11535 -s <serial port file> passed to simulator see the simulator docs for details.
11538 -S <serial in,out> passed to simulator see the simulator docs for details.
11544 As mentioned earlier the command interface for the debugger has been deliberatel
11545 y kept as close the GNU debugger gdb, as possible.
11546 This will help the integration with existing graphical user interfaces
11547 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
11548 If you use a graphical user interface for the debugger you can skip the
11550 \layout Subsubsection*
11552 break [line | file:line | function | file:function]
11555 Set breakpoint at specified line or function:
11564 sdcdb>break foo.c:100
11566 sdcdb>break funcfoo
11568 sdcdb>break foo.c:funcfoo
11569 \layout Subsubsection*
11571 clear [line | file:line | function | file:function ]
11574 Clear breakpoint at specified line or function:
11583 sdcdb>clear foo.c:100
11585 sdcdb>clear funcfoo
11587 sdcdb>clear foo.c:funcfoo
11588 \layout Subsubsection*
11593 Continue program being debugged, after breakpoint.
11594 \layout Subsubsection*
11599 Execute till the end of the current function.
11600 \layout Subsubsection*
11605 Delete breakpoint number 'n'.
11606 If used without any option clear ALL user defined break points.
11607 \layout Subsubsection*
11609 info [break | stack | frame | registers ]
11612 info break - list all breakpoints
11615 info stack - show the function call stack.
11618 info frame - show information about the current execution frame.
11621 info registers - show content of all registers.
11622 \layout Subsubsection*
11627 Step program until it reaches a different source line.
11628 \layout Subsubsection*
11633 Step program, proceeding through subroutine calls.
11634 \layout Subsubsection*
11639 Start debugged program.
11640 \layout Subsubsection*
11645 Print type information of the variable.
11646 \layout Subsubsection*
11651 print value of variable.
11652 \layout Subsubsection*
11657 load the given file name.
11658 Note this is an alternate method of loading file for debugging.
11659 \layout Subsubsection*
11664 print information about current frame.
11665 \layout Subsubsection*
11670 Toggle between C source & assembly source.
11671 \layout Subsubsection*
11673 ! simulator command
11676 Send the string following '!' to the simulator, the simulator response is
11678 Note the debugger does not interpret the command being sent to the simulator,
11679 so if a command like 'go' is sent the debugger can loose its execution
11680 context and may display incorrect values.
11681 \layout Subsubsection*
11688 My name is Bobby Brown"
11691 Interfacing with XEmacs
11692 \begin_inset LatexCommand \index{XEmacs}
11697 \begin_inset LatexCommand \index{Emacs}
11704 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
11705 sdcdb.el and sdcdbsrc.el.
11706 These two files can be found in the $(prefix)/bin directory after the installat
11708 These files need to be loaded into XEmacs for the interface to work.
11709 This can be done at XEmacs startup time by inserting the following into
11710 your '.xemacs' file (which can be found in your HOME directory):
11716 (load-file sdcdbsrc.el)
11722 .xemacs is a lisp file so the () around the command is REQUIRED.
11723 The files can also be loaded dynamically while XEmacs is running, set the
11724 environment variable 'EMACSLOADPATH' to the installation bin directory
11725 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
11726 To start the interface enter the following command:
11740 You will prompted to enter the file name to be debugged.
11745 The command line options that are passed to the simulator directly are bound
11746 to default values in the file sdcdbsrc.el.
11747 The variables are listed below, these values maybe changed as required.
11750 sdcdbsrc-cpu-type '51
11753 sdcdbsrc-frequency '11059200
11756 sdcdbsrc-serial nil
11759 The following is a list of key mapping for the debugger interface.
11767 ;; Current Listing ::
11769 ;;key\SpecialChar ~
11784 binding\SpecialChar ~
11808 ;;---\SpecialChar ~
11823 ------\SpecialChar ~
11863 sdcdb-next-from-src\SpecialChar ~
11889 sdcdb-back-from-src\SpecialChar ~
11915 sdcdb-cont-from-src\SpecialChar ~
11925 SDCDB continue command
11941 sdcdb-step-from-src\SpecialChar ~
11967 sdcdb-whatis-c-sexp\SpecialChar ~
11977 SDCDB ptypecommand for data at
12041 sdcdbsrc-delete\SpecialChar ~
12055 SDCDB Delete all breakpoints if no arg
12103 given or delete arg (C-u arg x)
12119 sdcdbsrc-frame\SpecialChar ~
12134 SDCDB Display current frame if no arg,
12183 given or display frame arg
12248 sdcdbsrc-goto-sdcdb\SpecialChar ~
12258 Goto the SDCDB output buffer
12274 sdcdb-print-c-sexp\SpecialChar ~
12285 SDCDB print command for data at
12349 sdcdbsrc-goto-sdcdb\SpecialChar ~
12359 Goto the SDCDB output buffer
12375 sdcdbsrc-mode\SpecialChar ~
12391 Toggles Sdcdbsrc mode (turns it off)
12395 ;; C-c C-f\SpecialChar ~
12403 sdcdb-finish-from-src\SpecialChar ~
12411 SDCDB finish command
12415 ;; C-x SPC\SpecialChar ~
12423 sdcdb-break\SpecialChar ~
12441 Set break for line with point
12443 ;; ESC t\SpecialChar ~
12453 sdcdbsrc-mode\SpecialChar ~
12469 Toggle Sdcdbsrc mode
12471 ;; ESC m\SpecialChar ~
12481 sdcdbsrc-srcmode\SpecialChar ~
12503 Here are a few guidelines that will help the compiler generate more efficient
12504 code, some of the tips are specific to this compiler others are generally
12505 good programming practice.
12508 Use the smallest data type to represent your data-value.
12509 If it is known in advance that the value is going to be less than 256 then
12510 use an 'unsigned char' instead of a 'short' or 'int'.
12513 Use unsigned when it is known in advance that the value is not going to
12515 This helps especially if you are doing division or multiplication.
12518 NEVER jump into a LOOP.
12521 Declare the variables to be local whenever possible, especially loop control
12522 variables (induction).
12525 Since the compiler does not always do implicit integral promotion, the programme
12526 r should do an explicit cast when integral promotion is required.
12529 Reducing the size of division, multiplication & modulus operations can reduce
12530 code size substantially.
12531 Take the following code for example.
12537 foobar(unsigned int p1, unsigned char ch)
12545 unsigned char ch1 = p1 % ch ;
12556 For the modulus operation the variable ch will be promoted to unsigned int
12557 first then the modulus operation will be performed (this will lead to a
12558 call to support routine _moduint()), and the result will be casted to a
12560 If the code is changed to
12565 foobar(unsigned int p1, unsigned char ch)
12573 unsigned char ch1 = (unsigned char)p1 % ch ;
12584 It would substantially reduce the code generated (future versions of the
12585 compiler will be smart enough to detect such optimization opportunities).
12589 Have a look at the assembly listing to get a
12590 \begin_inset Quotes sld
12594 \begin_inset Quotes srd
12597 for the code generation.
12600 Notes on MCS51 memory
12601 \begin_inset LatexCommand \index{MCS51 memory}
12608 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12609 RAM memory which is structured as follows
12613 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12616 - Bytes 20-2F - 16 bytes to hold 128 bit
12617 \begin_inset LatexCommand \index{bit}
12623 - Bytes 30-7F - 80 bytes for general purpose use.
12628 Additionally some members of the MCS51 family may have up to 128 bytes of
12629 additional, indirectly addressable, internal RAM memory (
12634 \begin_inset LatexCommand \index{idata}
12639 Furthermore, some chips may have some built in external memory (
12644 \begin_inset LatexCommand \index{xdata}
12648 ) which should not be confused with the internal, directly addressable RAM
12654 \begin_inset LatexCommand \index{data}
12659 Sometimes this built in
12663 memory has to be activated before using it (you can probably find this
12664 information on the datasheet of the microcontroller your are using).
12667 Normally SDCC will only use the first bank
12668 \begin_inset LatexCommand \index{bank}
12672 of registers (register bank 0), but it is possible to specify that other
12673 banks of registers should be used in interrupt
12674 \begin_inset LatexCommand \index{interrupt}
12679 By default, the compiler will place the stack after the last byte of allocated
12680 memory for variables.
12681 For example, if the first 2 banks of registers are used, and only four
12686 variables, it will position the base of the internal stack at address 20
12688 This implies that as the stack
12689 \begin_inset LatexCommand \index{stack}
12693 grows, it will use up the remaining register banks, and the 16 bytes used
12694 by the 128 bit variables, and 80 bytes for general purpose use.
12695 If any bit variables are used, the data variables will be placed after
12696 the byte holding the last bit variable.
12697 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12702 variables will be placed starting at address 0x22.
12714 \begin_inset LatexCommand \index{-\/-data-loc}
12718 to specify the start address of the
12732 -iram-size to specify the size of the total internal RAM (
12744 By default the 8051 linker will place the stack after the last byte of data
12757 \begin_inset LatexCommand \index{-\/-stack-loc}
12761 allows you to specify the start of the stack, i.e.
12762 you could start it after any data in the general purpose area.
12763 If your microcontroller has additional indirectly addressable internal
12768 ) you can place the stack on it.
12769 You may also need to use -
12780 \begin_inset LatexCommand \index{-\/-data-loc}
12784 to set the start address of the external RAM (
12799 \begin_inset LatexCommand \index{-\/-data-loc}
12803 to specify its size.
12804 Same goes for the code memory, using -
12815 \begin_inset LatexCommand \index{-\/-data-loc}
12830 \begin_inset LatexCommand \index{-\/-data-loc}
12835 If in doubt, don't specify any options and see if the resulting memory
12836 layout is appropriate, then you can adjust it.
12839 The 8051 linker generates two files with memory allocation information.
12840 The first, with extension .map shows all the variables and segments.
12841 The second with extension .mem shows the final memory layout.
12842 The linker will complaint either if memory segments overlap, there is not
12843 enough memory, or there is not enough space for stack.
12844 If you get any linking warnings and/or errors related to stack or segments
12845 allocation, take a look at either the .map or .mem files to find out what
12847 The .mem file may even suggest a solution to the problem.
12851 \begin_inset LatexCommand \index{Tools}
12855 included in the distribution
12859 \begin_inset Tabular
12860 <lyxtabular version="3" rows="12" columns="3">
12862 <column alignment="center" valignment="top" leftline="true" width="0pt">
12863 <column alignment="center" valignment="top" leftline="true" width="0pt">
12864 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12865 <row topline="true" bottomline="true">
12866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12891 <row topline="true">
12892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12905 Simulator for various architectures
12908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12917 <row topline="true">
12918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12931 header file conversion
12934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12939 sdcc/support/scripts
12943 <row topline="true">
12944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12957 header file conversion
12960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12965 sdcc/support/scripts
12969 <row topline="true">
12970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13004 <row topline="true">
13005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13039 <row topline="true">
13040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13074 <row topline="true">
13075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13109 <row topline="true">
13110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13144 <row topline="true">
13145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13179 <row topline="true">
13180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13214 <row topline="true" bottomline="true">
13215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13258 Related open source tools
13259 \begin_inset LatexCommand \index{Related tools}
13267 \begin_inset Tabular
13268 <lyxtabular version="3" rows="8" columns="3">
13270 <column alignment="center" valignment="top" leftline="true" width="0pt">
13271 <column alignment="block" valignment="top" leftline="true" width="30line%">
13272 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13273 <row topline="true" bottomline="true">
13274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13299 <row topline="true">
13300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13306 \begin_inset LatexCommand \index{gpsim}
13313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13327 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13335 <row topline="true">
13336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13358 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
13366 <row topline="true">
13367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13373 \begin_inset LatexCommand \index{srecord}
13380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13385 Object file conversion, checksumming, ...
13388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13394 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13402 <row topline="true">
13403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13409 \begin_inset LatexCommand \index{objdump}
13416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13421 Object file conversion, ...
13424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13429 Part of binutils (should be there anyway)
13433 <row topline="true">
13434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13440 \begin_inset LatexCommand \index{doxygen}
13447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13452 Source code documentation system
13455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13461 \begin_inset LatexCommand \url{http://www.doxygen.org}
13469 <row topline="true">
13470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13476 \begin_inset LatexCommand \index{splint}
13483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13488 Statically checks c sources
13491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13497 \begin_inset LatexCommand \url{http://www.splint.org}
13505 <row topline="true" bottomline="true">
13506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13512 \begin_inset LatexCommand \index{ddd}
13519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13524 Debugger, serves nicely as GUI to sdcdb
13525 \begin_inset LatexCommand \index{sdcdb}
13532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13538 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13555 Related documentation / recommended reading
13559 \begin_inset Tabular
13560 <lyxtabular version="3" rows="5" columns="3">
13562 <column alignment="center" valignment="top" leftline="true" width="0pt">
13563 <column alignment="block" valignment="top" leftline="true" width="30line%">
13564 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13565 <row topline="true" bottomline="true">
13566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13591 <row topline="true">
13592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13607 Advanced Compiler Design and Implementation
13610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13619 <row topline="true">
13620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13643 \begin_inset LatexCommand \index{C Reference card}
13650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13656 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13664 <row topline="true">
13665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13670 test_suite_spec.pdf
13673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13678 sdcc regression test
13679 \begin_inset LatexCommand \index{Regression test}
13686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13695 <row topline="true" bottomline="true">
13696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13727 sdcc internal documentation
13730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13749 \begin_inset LatexCommand \index{Support}
13756 SDCC has grown to be a large project.
13757 The compiler alone (without the preprocessor, assembler and linker) is
13758 well over 100,000 lines of code (blank stripped).
13759 The open source nature of this project is a key to its continued growth
13761 You gain the benefit and support of many active software developers and
13763 Is SDCC perfect? No, that's why we need your help.
13764 The developers take pride in fixing reported bugs.
13765 You can help by reporting the bugs and helping other SDCC users.
13766 There are lots of ways to contribute, and we encourage you to take part
13767 in making SDCC a great software package.
13771 The SDCC project is hosted on the sdcc sourceforge site at
13772 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
13777 You'll find the complete set of mailing lists
13778 \begin_inset LatexCommand \index{Mailing list}
13782 , forums, bug reporting system, patch submission
13783 \begin_inset LatexCommand \index{Patch submission}
13788 \begin_inset LatexCommand \index{download}
13792 area and cvs code repository
13793 \begin_inset LatexCommand \index{cvs code repository}
13801 \begin_inset LatexCommand \index{Bugs}
13806 \begin_inset LatexCommand \index{Reporting bugs}
13813 The recommended way of reporting bugs is using the infrastructure of the
13815 You can follow the status of bug reports there and have an overview about
13819 Bug reports are automatically forwarded to the developer mailing list and
13820 will be fixed ASAP.
13821 When reporting a bug, it is very useful to include a small test program
13822 (the smaller the better) which reproduces the problem.
13823 If you can isolate the problem by looking at the generated assembly code,
13824 this can be very helpful.
13825 Compiling your program with the -
13836 \begin_inset LatexCommand \index{-\/-dumpall}
13840 option can sometimes be useful in locating optimization problems.
13841 When reporting a bug please maker sure you:
13844 Attach the code you are compiling with SDCC.
13848 Specify the exact command you use to run SDCC, or attach your Makefile.
13852 Specify the SDCC version (type "sdcc -v"), your platform, and operating
13857 Provide an exact copy of any error message or incorrect output.
13861 Put something meaningful in the subject of your message.
13864 Please attempt to include these 5 important parts, as applicable, in all
13865 requests for support or when reporting any problems or bugs with SDCC.
13866 Though this will make your message lengthy, it will greatly improve your
13867 chance that SDCC users and developers will be able to help you.
13868 Some SDCC developers are frustrated by bug reports without code provided
13869 that they can use to reproduce and ultimately fix the problem, so please
13870 be sure to provide sample code if you are reporting a bug!
13873 Please have a short check that you are using a recent version of SDCC and
13874 the bug is not yet known.
13875 This is the link for reporting bugs:
13876 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
13883 Requesting Features
13884 \begin_inset LatexCommand \label{sub:Requesting-Features}
13889 \begin_inset LatexCommand \index{Feature request}
13894 \begin_inset LatexCommand \index{Requesting features}
13901 Like bug reports feature requests are forwarded to the developer mailing
13903 This is the link for requesting features:
13904 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
13914 These links should take you directly to the
13915 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
13925 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
13926 automated messages (mid 2003)
13930 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
13934 , lists and forums are archived so if you are lucky someone already had
13939 \begin_inset LatexCommand \index{Changelog}
13946 You can follow the status of the cvs version
13947 \begin_inset LatexCommand \index{version}
13951 of SDCC by watching the file
13952 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
13956 in the cvs-repository.
13960 \begin_inset LatexCommand \index{Release policy}
13967 Historically there often were long delays between official releases and
13968 the sourceforge download area tends to get not updated at all.
13969 Current excuses might refer to problems with live range analysis, but if
13970 this is fixed, the next problem rising is that another excuse will have
13972 Kidding aside, we have to get better there! On the other hand there are
13973 daily snapshots available at
13974 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
13978 , and you can always built the very last version (hopefully with many bugs
13979 fixed, and features added) from the source code available at
13980 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
13988 \begin_inset LatexCommand \index{Examples}
13995 You'll find some small examples in the directory sdcc/device/examples/
13998 Maybe we should include some links to real world applications.
13999 Preferably pointer to pointers (one for each architecture) so this stays
14004 \begin_inset LatexCommand \index{Quality control}
14011 The compiler is passed through nightly compile and build checks.
14017 \begin_inset LatexCommand \index{Regression test}
14021 check that SDCC itself compiles flawlessly on several platforms and checks
14022 the quality of the code generated by SDCC by running the code through simulator
14024 There is a separate document
14027 \begin_inset LatexCommand \index{Test suite}
14036 You'll find the test code in the directory
14038 sdcc/support/regression
14041 You can run these tests manually by running
14045 in this directory (or f.e.
14050 if you don't want to run the complete tests).
14051 The test code might also be interesting if you want to look for examples
14052 \begin_inset LatexCommand \index{Examples}
14056 checking corner cases of SDCC or if you plan to submit patches
14057 \begin_inset LatexCommand \index{Patch submission}
14064 The pic port uses a different set of regression tests, you'll find them
14067 sdcc/src/regression
14072 SDCC Technical Data
14076 \begin_inset LatexCommand \index{Optimizations}
14083 SDCC performs a host of standard optimizations in addition to some MCU specific
14086 \layout Subsubsection
14088 Sub-expression Elimination
14089 \begin_inset LatexCommand \index{Subexpression elimination}
14096 The compiler does local and global common subexpression elimination, e.g.:
14107 will be translated to
14119 Some subexpressions are not as obvious as the above example, e.g.:
14129 In this case the address arithmetic a->b[i] will be computed only once;
14130 the equivalent code in C would be.
14142 The compiler will try to keep these temporary variables in registers.
14143 \layout Subsubsection
14145 Dead-Code Elimination
14146 \begin_inset LatexCommand \index{Dead-code elimination}
14167 i = 1; \SpecialChar ~
14176 global = 1;\SpecialChar ~
14189 global = 3;\SpecialChar ~
14215 \layout Subsubsection
14218 \begin_inset LatexCommand \index{Copy propagation}
14274 Note: the dead stores created by this copy propagation will be eliminated
14275 by dead-code elimination.
14276 \layout Subsubsection
14279 \begin_inset LatexCommand \index{Loop optimization}
14286 Two types of loop optimizations are done by SDCC loop invariant lifting
14287 and strength reduction of loop induction variables.
14288 In addition to the strength reduction the optimizer marks the induction
14289 variables and the register allocator tries to keep the induction variables
14290 in registers for the duration of the loop.
14291 Because of this preference of the register allocator
14292 \begin_inset LatexCommand \index{Register allocation}
14296 , loop induction optimization causes an increase in register pressure, which
14297 may cause unwanted spilling of other temporary variables into the stack
14298 \begin_inset LatexCommand \index{stack}
14303 The compiler will generate a warning message when it is forced to allocate
14304 extra space either on the stack or data space.
14305 If this extra space allocation is undesirable then induction optimization
14306 can be eliminated either for the entire source file (with -
14316 -noinduction option) or for a given function only using #pragma\SpecialChar ~
14318 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
14331 for (i = 0 ; i < 100 ; i ++)
14347 for (i = 0; i < 100; i++)
14356 As mentioned previously some loop invariants are not as apparent, all static
14357 address computations are also moved out of the loop.
14362 \begin_inset LatexCommand \index{Strength reduction}
14366 , this optimization substitutes an expression by a cheaper expression:
14371 for (i=0;i < 100; i++)
14389 for (i=0;i< 100;i++) {
14395 ar[itemp1] = itemp2;
14412 The more expensive multiplication
14413 \begin_inset LatexCommand \index{Multiplication}
14417 is changed to a less expensive addition.
14418 \layout Subsubsection
14421 \begin_inset LatexCommand \index{Loop reversing}
14428 This optimization is done to reduce the overhead of checking loop boundaries
14429 for every iteration.
14430 Some simple loops can be reversed and implemented using a
14431 \begin_inset Quotes eld
14434 decrement and jump if not zero
14435 \begin_inset Quotes erd
14439 SDCC checks for the following criterion to determine if a loop is reversible
14440 (note: more sophisticated compilers use data-dependency analysis to make
14441 this determination, SDCC uses a more simple minded analysis).
14444 The 'for' loop is of the form
14450 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
14460 The <for body> does not contain
14461 \begin_inset Quotes eld
14465 \begin_inset Quotes erd
14469 \begin_inset Quotes erd
14475 All goto's are contained within the loop.
14478 No function calls within the loop.
14481 The loop control variable <sym> is not assigned any value within the loop
14484 The loop control variable does NOT participate in any arithmetic operation
14488 There are NO switch statements in the loop.
14489 \layout Subsubsection
14491 Algebraic Simplifications
14494 SDCC does numerous algebraic simplifications, the following is a small sub-set
14495 of these optimizations.
14500 i = j + 0 ; /* changed to */ i = j;
14502 i /= 2;\SpecialChar ~
14506 /* changed to */ i >>= 1;
14508 i = j - j ; /* changed to */ i = 0;
14510 i = j / 1 ; /* changed to */ i = j;
14513 Note the subexpressions
14514 \begin_inset LatexCommand \index{Subexpression}
14518 given above are generally introduced by macro expansions or as a result
14519 of copy/constant propagation.
14520 \layout Subsubsection
14522 'switch' Statements
14523 \begin_inset LatexCommand \index{switch statement}
14530 SDCC changes switch statements to jump tables
14531 \begin_inset LatexCommand \index{jump tables}
14535 when the following conditions are true.
14539 The case labels are in numerical sequence, the labels need not be in order,
14540 and the starting number need not be one or zero.
14546 switch(i) {\SpecialChar ~
14577 case 4: ...\SpecialChar ~
14609 case 5: ...\SpecialChar ~
14641 case 3: ...\SpecialChar ~
14673 case 6: ...\SpecialChar ~
14741 Both the above switch statements will be implemented using a jump-table.
14742 The example to the right side is slightly more efficient as the check for
14743 the lower boundary of the jump-table is not needed.
14747 The number of case labels is at least three, since it takes two conditional
14748 statements to handle the boundary conditions.
14751 The number of case labels is less than 84, since each label takes 3 bytes
14752 and a jump-table can be utmost 256 bytes long.
14755 Switch statements which have gaps in the numeric sequence or those that
14756 have more that 84 case labels can be split into more than one switch statement
14757 for efficient code generation, e.g.:
14807 If the above switch statement is broken down into two switch statements
14846 case 9:\SpecialChar ~
14853 case 10:\SpecialChar ~
14859 case 11:\SpecialChar ~
14865 case 12:\SpecialChar ~
14872 then both the switch statements will be implemented using jump-tables whereas
14873 the unmodified switch statement will not be.
14874 You might also consider dummy cases 0 and 5 to 8 in this example.
14875 The pragma NOJTBOUND
14876 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
14880 can be used to turn off checking the
14893 \layout Subsubsection
14895 Bit-shifting Operations
14896 \begin_inset LatexCommand \index{Bit shifting}
14903 Bit shifting is one of the most frequently used operation in embedded programmin
14905 SDCC tries to implement bit-shift operations in the most efficient way
14921 generates the following code:
14938 In general SDCC will never setup a loop if the shift count is known.
14980 Note that SDCC stores numbers in little-endian
14981 \begin_inset LatexCommand \index{little-endian}
14986 \begin_inset LatexCommand \index{Endianness}
14991 lowest order first).
14992 \layout Subsubsection
14995 \begin_inset LatexCommand \index{Bit rotation}
15002 A special case of the bit-shift operation is bit rotation, SDCC recognizes
15003 the following expression to be a left bit-rotation:
15013 i = ((i << 1) | (i >> 7));
15022 will generate the following code:
15041 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
15042 ns of this case will also be recognized as bit-rotation, i.e.:
15047 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
15048 \layout Subsubsection
15051 \begin_inset LatexCommand \index{Highest Order Bit}
15058 It is frequently required to obtain the highest order bit of an integral
15059 type (long, int, short or char types).
15060 SDCC recognizes the following expression to yield the highest order bit
15061 and generates optimized code for it, e.g.:
15083 hob = (gint >> 15) & 1;
15093 will generate the following code:
15126 000A E5*01\SpecialChar ~
15153 000C 23\SpecialChar ~
15184 000D 54 01\SpecialChar ~
15211 000F F5*02\SpecialChar ~
15239 Variations of this case however will
15244 It is a standard C expression, so I heartily recommend this be the only
15245 way to get the highest order bit, (it is portable).
15246 Of course it will be recognized even if it is embedded in other expressions,
15252 xyz = gint + ((gint >> 15) & 1);
15255 will still be recognized.
15256 \layout Subsubsection
15259 \begin_inset LatexCommand \index{Peephole optimizer}
15266 The compiler uses a rule based, pattern matching and re-writing mechanism
15267 for peep-hole optimization.
15272 a peep-hole optimizer by Christopher W.
15273 Fraser (cwfraser@microsoft.com).
15274 A default set of rules are compiled into the compiler, additional rules
15275 may be added with the
15288 \begin_inset LatexCommand \index{-\/-peep-file}
15295 The rule language is best illustrated with examples.
15319 The above rule will change the following assembly
15320 \begin_inset LatexCommand \index{Assembler routines}
15342 Note: All occurrences of a
15346 (pattern variable) must denote the same string.
15347 With the above rule, the assembly sequence:
15357 will remain unmodified.
15361 Other special case optimizations may be added by the user (via
15377 some variants of the 8051 MCU allow only
15386 The following two rules will change all
15405 replace { lcall %1 } by { acall %1 }
15407 replace { ljmp %1 } by { ajmp %1 }
15412 inline-assembler code
15414 is also passed through the peep hole optimizer, thus the peephole optimizer
15415 can also be used as an assembly level macro expander.
15416 The rules themselves are MCU dependent whereas the rule language infra-structur
15417 e is MCU independent.
15418 Peephole optimization rules for other MCU can be easily programmed using
15423 The syntax for a rule is as follows:
15428 rule := replace [ restart ] '{' <assembly sequence> '
15466 <assembly sequence> '
15484 '}' [if <functionName> ] '
15489 <assembly sequence> := assembly instruction (each instruction including
15490 labels must be on a separate line).
15494 The optimizer will apply to the rules one by one from the top in the sequence
15495 of their appearance, it will terminate when all rules are exhausted.
15496 If the 'restart' option is specified, then the optimizer will start matching
15497 the rules again from the top, this option for a rule is expensive (performance)
15498 , it is intended to be used in situations where a transformation will trigger
15499 the same rule again.
15500 An example of this (not a good one, it has side effects) is the following
15523 Note that the replace pattern cannot be a blank, but can be a comment line.
15524 Without the 'restart' option only the inner most 'pop' 'push' pair would
15525 be eliminated, i.e.:
15555 the restart option the rule will be applied again to the resulting code
15556 and then all the pop-push pairs will be eliminated to yield:
15566 A conditional function can be attached to a rule.
15567 Attaching rules are somewhat more involved, let me illustrate this with
15594 The optimizer does a look-up of a function name table defined in function
15599 in the source file SDCCpeeph.c, with the name
15604 If it finds a corresponding entry the function is called.
15605 Note there can be no parameters specified for these functions, in this
15610 is crucial, since the function
15614 expects to find the label in that particular variable (the hash table containin
15615 g the variable bindings is passed as a parameter).
15616 If you want to code more such functions, take a close look at the function
15617 labelInRange and the calling mechanism in source file SDCCpeeph.c.
15618 Currently implemented are
15620 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
15621 24bitMode, portIsDS390, 24bitModeAndPortDS390
15630 I know this whole thing is a little kludgey, but maybe some day we will
15631 have some better means.
15632 If you are looking at this file, you will see the default rules that are
15633 compiled into the compiler, you can add your own rules in the default set
15634 there if you get tired of specifying the -
15654 <pending: this is messy and incomplete>
15659 Compiler support routines (_gptrget, _mulint etc)
15662 Stdclib functions (puts, printf, strcat etc)
15665 Math functions (sin, pow, sqrt etc)
15669 \begin_inset LatexCommand \index{Libraries}
15673 included in SDCC should have a license at least as liberal as the GNU Lesser
15674 General Public License
15675 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15686 license statements for the libraries are missing.
15687 sdcc/device/lib/ser_ir.c
15691 come with a GPL (as opposed to LGPL) License - this will not be liberal
15692 enough for many embedded programmers.
15696 \begin_inset LatexCommand \label{sub:External-Stack}
15701 \begin_inset LatexCommand \index{stack}
15706 \begin_inset LatexCommand \index{External stack}
15713 The external stack (-
15724 \begin_inset LatexCommand \index{-\/-xstack}
15728 ) is located at the start of the external ram segment, and is 256 bytes
15740 -xstack option is used to compile the program, the parameters and local
15741 variables of all reentrant functions are allocated in this area.
15742 This option is provided for programs with large stack space requirements.
15743 When used with the -
15754 \begin_inset LatexCommand \index{-\/-stack-auto}
15758 option, all parameters and local variables are allocated on the external
15759 stack (note support libraries will need to be recompiled with the same
15763 The compiler outputs the higher order address byte of the external ram segment
15764 into PORT P2, therefore when using the External Stack option, this port
15765 MAY NOT be used by the application program.
15769 \begin_inset LatexCommand \index{ANSI-compliance}
15776 Deviations from the compliance:
15779 functions are not always reentrant.
15782 structures cannot be assigned values directly, cannot be passed as function
15783 parameters or assigned to each other and cannot be a return value from
15810 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
15821 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
15843 return rets;/* is invalid in SDCC although allowed in ANSI */
15850 \begin_inset LatexCommand \index{long long (not supported)}
15855 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
15863 \begin_inset LatexCommand \index{double (not supported)}
15867 ' precision floating point
15868 \begin_inset LatexCommand \index{Floating point support}
15875 No support for setjmp and longjmp (for now).
15879 \begin_inset LatexCommand \index{K\&R style}
15883 function declarations are NOT allowed.
15889 foo(i,j) /* this old style of function declarations */
15891 int i,j; /* are valid in ANSI but not valid in SDCC */
15906 functions declared as pointers must be dereferenced during the call.
15917 /* has to be called like this */
15919 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
15923 Cyclomatic Complexity
15924 \begin_inset LatexCommand \index{Cyclomatic complexity}
15931 Cyclomatic complexity of a function is defined as the number of independent
15932 paths the program can take during execution of the function.
15933 This is an important number since it defines the number test cases you
15934 have to generate to validate the function.
15935 The accepted industry standard for complexity number is 10, if the cyclomatic
15936 complexity reported by SDCC exceeds 10 you should think about simplification
15937 of the function logic.
15938 Note that the complexity level is not related to the number of lines of
15939 code in a function.
15940 Large functions can have low complexity, and small functions can have large
15946 SDCC uses the following formula to compute the complexity:
15951 complexity = (number of edges in control flow graph) - (number of nodes
15952 in control flow graph) + 2;
15956 Having said that the industry standard is 10, you should be aware that in
15957 some cases it be may unavoidable to have a complexity level of less than
15959 For example if you have switch statement with more than 10 case labels,
15960 each case label adds one to the complexity level.
15961 The complexity level is by no means an absolute measure of the algorithmic
15962 complexity of the function, it does however provide a good starting point
15963 for which functions you might look at for further optimization.
15967 \layout Subsubsection
15970 \begin_inset LatexCommand \index{MCS51 variants}
15977 MCS51 processors are available from many vendors and come in many different
15979 While they might differ considerably in respect to Special Function Registers
15980 the core MCS51 is usually not modified or is kept compatible.
15982 \layout Subsubsection*
15984 pdata access by SFR
15987 With the upcome of devices with internal xdata and flash memory devices
15988 using port P2 as dedicated I/O port is becoming more popular.
15989 Switching the high byte for pdata
15990 \begin_inset LatexCommand \index{pdata}
15994 access which was formerly done by port P2 is then achieved by a Special
15996 In well-established MCS51 tradition the address of this
16000 is where the chip designers decided to put it.
16001 As pdata addressing is used in the startup code for the initialization
16002 of xdata variables a separate startup code should be used as described
16004 \begin_inset LatexCommand \ref{sub:Startup-Code}
16009 \layout Subsubsection*
16011 Other Features available by SFR
16014 Some MCS51 variants offer features like Double DPTR
16015 \begin_inset LatexCommand \index{DPTR}
16019 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16020 These are currently not used for the MCS51 port.
16021 If you absolutely need them you can fall back to inline assembly or submit
16023 \layout Subsubsection
16025 The Z80 and gbz80 port
16028 SDCC can target both the Zilog
16029 \begin_inset LatexCommand \index{Z80}
16033 and the Nintendo Gameboy's Z80-like gbz80
16034 \begin_inset LatexCommand \index{GameBoy Z80}
16039 The Z80 port is passed through the same
16042 \begin_inset LatexCommand \index{Regression test}
16048 as MCS51 and DS390 ports, so floating point support, support for long variables
16049 and bitfield support is fine.
16052 As always, the code is the authoritative reference - see z80/ralloc.c and
16054 The stack frame is similar to that generated by the IAR Z80 compiler.
16055 IX is used as the base pointer, HL is used as a temporary register, and
16056 BC and DE are available for holding variables.
16057 IY is currently unused.
16058 Return values are stored in HL.
16059 One bad side effect of using IX as the base pointer is that a functions
16060 stack frame is limited to 127 bytes - this will be fixed in a later version.
16063 Retargetting for other MCUs.
16066 The issues for retargetting the compiler are far too numerous to be covered
16068 What follows is a brief description of each of the seven phases of the
16069 compiler and its MCU dependency.
16072 Parsing the source and building the annotated parse tree.
16073 This phase is largely MCU independent (except for the language extensions).
16074 Syntax & semantic checks are also done in this phase, along with some initial
16075 optimizations like back patching labels and the pattern matching optimizations
16076 like bit-rotation etc.
16079 The second phase involves generating an intermediate code which can be easy
16080 manipulated during the later phases.
16081 This phase is entirely MCU independent.
16082 The intermediate code generation assumes the target machine has unlimited
16083 number of registers, and designates them with the name iTemp.
16084 The compiler can be made to dump a human readable form of the code generated
16098 This phase does the bulk of the standard optimizations and is also MCU independe
16100 This phase can be broken down into several sub-phases:
16104 Break down intermediate code (iCode) into basic blocks.
16106 Do control flow & data flow analysis on the basic blocks.
16108 Do local common subexpression elimination, then global subexpression elimination
16110 Dead code elimination
16114 If loop optimizations caused any changes then do 'global subexpression eliminati
16115 on' and 'dead code elimination' again.
16118 This phase determines the live-ranges; by live range I mean those iTemp
16119 variables defined by the compiler that still survive after all the optimization
16121 Live range analysis
16122 \begin_inset LatexCommand \index{Live range analysis}
16126 is essential for register allocation, since these computation determines
16127 which of these iTemps will be assigned to registers, and for how long.
16130 Phase five is register allocation.
16131 There are two parts to this process.
16135 The first part I call 'register packing' (for lack of a better term).
16136 In this case several MCU specific expression folding is done to reduce
16141 The second part is more MCU independent and deals with allocating registers
16142 to the remaining live ranges.
16143 A lot of MCU specific code does creep into this phase because of the limited
16144 number of index registers available in the 8051.
16147 The Code generation phase is (unhappily), entirely MCU dependent and very
16148 little (if any at all) of this code can be reused for other MCU.
16149 However the scheme for allocating a homogenized assembler operand for each
16150 iCode operand may be reused.
16153 As mentioned in the optimization section the peep-hole optimizer is rule
16154 based system, which can reprogrammed for other MCUs.
16158 \begin_inset LatexCommand \index{Compiler internals}
16165 The anatomy of the compiler
16170 This is an excerpt from an article published in Circuit Cellar Magazine
16172 It's a little outdated (the compiler is much more efficient now and user/develo
16173 per friendly), but pretty well exposes the guts of it all.
16179 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
16180 It is fairly easy to retarget for other 8-bit MCU.
16181 Here we take a look at some of the internals of the compiler.
16186 \begin_inset LatexCommand \index{Parsing}
16193 Parsing the input source file and creating an AST (Annotated Syntax Tree
16194 \begin_inset LatexCommand \index{Annotated syntax tree}
16199 This phase also involves propagating types (annotating each node of the
16200 parse tree with type information) and semantic analysis.
16201 There are some MCU specific parsing rules.
16202 For example the storage classes, the extended storage classes are MCU specific
16203 while there may be a xdata storage class for 8051 there is no such storage
16204 class for z80 or Atmel AVR.
16205 SDCC allows MCU specific storage class extensions, i.e.
16206 xdata will be treated as a storage class specifier when parsing 8051 C
16207 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
16212 \begin_inset LatexCommand \index{iCode}
16219 Intermediate code generation.
16220 In this phase the AST is broken down into three-operand form (iCode).
16221 These three operand forms are represented as doubly linked lists.
16222 ICode is the term given to the intermediate form generated by the compiler.
16223 ICode example section shows some examples of iCode generated for some simple
16224 C source functions.
16228 \begin_inset LatexCommand \index{Optimizations}
16235 Bulk of the target independent optimizations is performed in this phase.
16236 The optimizations include constant propagation, common sub-expression eliminati
16237 on, loop invariant code movement, strength reduction of loop induction variables
16238 and dead-code elimination.
16241 Live range analysis
16242 \begin_inset LatexCommand \index{Live range analysis}
16249 During intermediate code generation phase, the compiler assumes the target
16250 machine has infinite number of registers and generates a lot of temporary
16252 The live range computation determines the lifetime of each of these compiler-ge
16253 nerated temporaries.
16254 A picture speaks a thousand words.
16255 ICode example sections show the live range annotations for each of the
16257 It is important to note here, each iCode is assigned a number in the order
16258 of its execution in the function.
16259 The live ranges are computed in terms of these numbers.
16260 The from number is the number of the iCode which first defines the operand
16261 and the to number signifies the iCode which uses this operand last.
16264 Register Allocation
16265 \begin_inset LatexCommand \index{Register allocation}
16272 The register allocation determines the type and number of registers needed
16274 In most MCUs only a few registers can be used for indirect addressing.
16275 In case of 8051 for example the registers R0 & R1 can be used to indirectly
16276 address the internal ram and DPTR to indirectly address the external ram.
16277 The compiler will try to allocate the appropriate register to pointer variables
16279 ICode example section shows the operands annotated with the registers assigned
16281 The compiler will try to keep operands in registers as much as possible;
16282 there are several schemes the compiler uses to do achieve this.
16283 When the compiler runs out of registers the compiler will check to see
16284 if there are any live operands which is not used or defined in the current
16285 basic block being processed, if there are any found then it will push that
16286 operand and use the registers in this block, the operand will then be popped
16287 at the end of the basic block.
16291 There are other MCU specific considerations in this phase.
16292 Some MCUs have an accumulator; very short-lived operands could be assigned
16293 to the accumulator instead of general-purpose register.
16299 Figure II gives a table of iCode operations supported by the compiler.
16300 The code generation involves translating these operations into corresponding
16301 assembly code for the processor.
16302 This sounds overly simple but that is the essence of code generation.
16303 Some of the iCode operations are generated on a MCU specific manner for
16304 example, the z80 port does not use registers to pass parameters so the
16305 SEND and RECV iCode operations will not be generated, and it also does
16306 not support JUMPTABLES.
16313 <Where is Figure II ?>
16317 \begin_inset LatexCommand \index{iCode}
16324 This section shows some details of iCode.
16325 The example C code does not do anything useful; it is used as an example
16326 to illustrate the intermediate code generated by the compiler.
16338 /* This function does nothing useful.
16345 for the purpose of explaining iCode */
16348 short function (data int *x)
16356 short i=10; /* dead initialization eliminated */
16361 short sum=10; /* dead initialization eliminated */
16374 while (*x) *x++ = *p++;
16388 /* compiler detects i,j to be induction variables */
16392 for (i = 0, j = 10 ; i < 10 ; i++, j
16418 mul += i * 3; /* this multiplication remains */
16424 gint += j * 3;/* this multiplication changed to addition */
16438 In addition to the operands each iCode contains information about the filename
16439 and line it corresponds to in the source file.
16440 The first field in the listing should be interpreted as follows:
16445 Filename(linenumber: iCode Execution sequence number : ICode hash table
16446 key : loop depth of the iCode).
16451 Then follows the human readable form of the ICode operation.
16452 Each operand of this triplet form can be of three basic types a) compiler
16453 generated temporary b) user defined variable c) a constant value.
16454 Note that local variables and parameters are replaced by compiler generated
16457 \begin_inset LatexCommand \index{Live range analysis}
16461 are computed only for temporaries (i.e.
16462 live ranges are not computed for global variables).
16464 \begin_inset LatexCommand \index{Register allocation}
16468 are allocated for temporaries only.
16469 Operands are formatted in the following manner:
16474 Operand Name [lr live-from : live-to ] { type information } [ registers
16480 As mentioned earlier the live ranges are computed in terms of the execution
16481 sequence number of the iCodes, for example
16483 the iTemp0 is live from (i.e.
16484 first defined in iCode with execution sequence number 3, and is last used
16485 in the iCode with sequence number 5).
16486 For induction variables such as iTemp21 the live range computation extends
16487 the lifetime from the start to the end of the loop.
16489 The register allocator used the live range information to allocate registers,
16490 the same registers may be used for different temporaries if their live
16491 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
16492 iTemp17 since their live ranges do not overlap.
16493 In addition the allocator also takes into consideration the type and usage
16494 of a temporary, for example itemp6 is a pointer to near space and is used
16495 as to fetch data from (i.e.
16496 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
16497 Some short lived temporaries are allocated to special registers which have
16498 meaning to the code generator e.g.
16499 iTemp13 is allocated to a pseudo register CC which tells the back end that
16500 the temporary is used only for a conditional jump the code generation makes
16501 use of this information to optimize a compare and jump ICode.
16503 There are several loop optimizations
16504 \begin_inset LatexCommand \index{Loop optimization}
16508 performed by the compiler.
16509 It can detect induction variables iTemp21(i) and iTemp23(j).
16510 Also note the compiler does selective strength reduction
16511 \begin_inset LatexCommand \index{Strength reduction}
16516 the multiplication of an induction variable in line 18 (gint = j * 3) is
16517 changed to addition, a new temporary iTemp17 is allocated and assigned
16518 a initial value, a constant 3 is then added for each iteration of the loop.
16519 The compiler does not change the multiplication
16520 \begin_inset LatexCommand \index{Multiplication}
16524 in line 17 however since the processor does support an 8 * 8 bit multiplication.
16526 Note the dead code elimination
16527 \begin_inset LatexCommand \index{Dead-code elimination}
16531 optimization eliminated the dead assignments in line 7 & 8 to I and sum
16539 Sample.c (5:1:0:0) _entry($9) :
16544 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
16549 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
16554 Sample.c(11:4:53:0) preHeaderLbl0($11) :
16559 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
16565 Sample.c(11:6:5:1) _whilecontinue_0($1) :
16570 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
16576 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16581 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
16587 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
16593 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
16599 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
16605 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
16606 * int}[r0] + 0x2 {short}
16611 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
16616 Sample.c(11:17:21:0)_whilebreak_0($3) :
16621 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16626 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16631 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16636 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16641 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16646 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16651 Sample.c(15:24:26:1)_forcond_0($4) :
16656 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16662 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16667 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16668 + ITemp21 [lr21:38]{short}[r4]
16673 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16679 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16680 + iTemp15 [lr29:30]{short}[r1]
16685 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16691 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16697 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16703 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16709 Sample.c(19:38:47:1) goto _forcond_0($4)
16714 Sample.c(19:39:48:0)_forbreak_0($7) :
16719 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16720 + ITemp11 [lr19:40]{short}[r3]
16725 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16730 Sample.c(20:42:51:0)_return($8) :
16735 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16741 Finally the code generated for this function:
16782 ; ----------------------------------------------
16787 ; function function
16792 ; ----------------------------------------------
16802 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16814 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16826 ;_whilecontinue_0($1) :
16836 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16841 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16900 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16919 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16966 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
17006 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
17032 ; iTemp6 [lr5:16]{_near * int}[r0] =
17037 ; iTemp6 [lr5:16]{_near * int}[r0] +
17054 ; goto _whilecontinue_0($1)
17066 ; _whilebreak_0($3) :
17076 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
17088 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
17100 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
17112 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
17131 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
17160 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
17165 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
17210 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
17215 ; iTemp21 [lr21:38]{short}[r4]
17241 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
17274 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
17279 ; iTemp15 [lr29:30]{short}[r1]
17298 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
17345 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
17392 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
17404 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
17418 cjne r5,#0xff,00104$
17430 ; goto _forcond_0($4)
17442 ; _forbreak_0($7) :
17452 ; ret iTemp24 [lr40:41]{short}
17495 A few words about basic block successors, predecessors and dominators
17498 Successors are basic blocks
17499 \begin_inset LatexCommand \index{Basic blocks}
17503 that might execute after this basic block.
17505 Predecessors are basic blocks that might execute before reaching this basic
17508 Dominators are basic blocks that WILL execute before reaching this basic
17542 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
17545 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
17548 c) domVect of [BB4] = BB1 ...
17549 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
17557 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
17567 Thanks to all the other volunteer developers who have helped with coding,
17568 testing, web-page creation, distribution sets, etc.
17569 You know who you are :-)
17576 This document was initially written by Sandeep Dutta
17579 All product names mentioned herein may be trademarks
17580 \begin_inset LatexCommand \index{Trademarks}
17584 of their respective companies.
17591 To avoid confusion, the installation and building options for sdcc itself
17592 (chapter 2) are not part of the index.
17596 \begin_inset LatexCommand \printindex{}