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, HC08, manual, mcs51, PIC, 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
88 The above strings enclosed in $ are automatically updated by cvs
92 \begin_inset LatexCommand \tableofcontents{}
109 is a Freeware, retargettable, optimizing ANSI-C compiler by
113 designed for 8 bit Microprocessors.
114 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
116 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
120 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
121 It can be retargetted for other microprocessors, support for Microchip
122 PIC, Atmel AVR is under development.
123 The entire source code for the compiler is distributed under GPL.
124 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
125 SDCC has extensive language extensions suitable for utilizing various microcont
126 rollers and underlying hardware effectively.
131 In addition to the MCU specific optimizations SDCC also does a host of standard
135 global sub expression elimination,
138 loop optimizations (loop invariant, strength reduction of induction variables
142 constant folding & propagation,
148 dead code elimination
158 For the back-end SDCC uses a global register allocation scheme which should
159 be well suited for other 8 bit MCUs.
164 The peep hole optimizer uses a rule based substitution mechanism which is
170 Supported data-types are:
173 char (8 bits, 1 byte),
176 short and int (16 bits, 2 bytes),
179 long (32 bit, 4 bytes)
186 The compiler also allows
188 inline assembler code
190 to be embedded anywhere in a function.
191 In addition, routines developed in assembly can also be called.
195 SDCC also provides an option (-
205 -cyclomatic) to report the relative complexity of a function.
206 These functions can then be further optimized, or hand coded in assembly
212 SDCC also comes with a companion source level debugger SDCDB, the debugger
213 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
218 The latest version can be downloaded from
219 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
229 Please note: the compiler will probably always be some steps ahead of this
234 \begin_inset LatexCommand \index{Status of documentation}
244 Obviously this has pros and cons
253 All packages used in this compiler system are
261 ; source code for all the sub-packages (pre-processor, assemblers, linkers
262 etc) is distributed with the package.
263 This documentation is maintained using a freeware word processor (LyX).
265 This program is free software; you can redistribute it and/or modify it
266 under the terms of the GNU General Public License
267 \begin_inset LatexCommand \index{GNU General Public License, GPL}
271 as published by the Free Software Foundation; either version 2, or (at
272 your option) any later version.
273 This program is distributed in the hope that it will be useful, but WITHOUT
274 ANY WARRANTY; without even the implied warranty
275 \begin_inset LatexCommand \index{warranty}
279 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
280 See the GNU General Public License for more details.
281 You should have received a copy of the GNU General Public License along
282 with this program; if not, write to the Free Software Foundation, 59 Temple
283 Place - Suite 330, Boston, MA 02111-1307, USA.
284 In other words, you are welcome to use, share and improve this program.
285 You are forbidden to forbid anyone else to use, share and improve what
287 Help stamp out software-hoarding!
290 Typographic conventions
291 \begin_inset LatexCommand \index{Typographic conventions}
298 Throughout this manual, we will use the following convention.
299 Commands you have to type in are printed in
307 Code samples are printed in
312 Interesting items and new terms are printed in
317 Compatibility with previous versions
320 This version has numerous bug fixes compared with the previous version.
321 But we also introduced some incompatibilities with older versions.
322 Not just for the fun of it, but to make the compiler more stable, efficient
324 \begin_inset LatexCommand \index{ANSI-compliance}
329 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
333 for ANSI-Compliance).
339 short is now equivalent to int (16 bits), it used to be equivalent to char
340 (8 bits) which is not ANSI compliant
343 the default directory for gcc-builds where include, library and documentation
344 files are stored is now in /usr/local/share
347 char type parameters to vararg functions are casted to int unless explicitly
364 will push a as an int and as a char resp.
377 -regextend has been removed
390 -noregparms has been removed
403 -stack-after-data has been removed
408 <pending: more incompatibilities?>
414 What do you need before you start installation of SDCC? A computer, and
416 The preferred method of installation is to compile SDCC from source using
418 For Windows some pre-compiled binary distributions are available for your
420 You should have some experience with command line tools and compiler use.
426 The SDCC home page at
427 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
431 is a great place to find distribution sets.
432 You can also find links to the user mailing lists that offer help or discuss
433 SDCC with other SDCC users.
434 Web links to other SDCC related sites can also be found here.
435 This document can be found in the DOC directory of the source package as
437 Some of the other tools (simulator and assembler) included with SDCC contain
438 their own documentation and can be found in the source distribution.
439 If you want the latest unreleased software, the complete source package
440 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
443 Wishes for the future
446 There are (and always will be) some things that could be done.
447 Here are some I can think of:
454 char KernelFunction3(char p) at 0x340;
462 \begin_inset LatexCommand \index{code banking (not supported)}
472 If you can think of some more, please see the chapter
473 \begin_inset LatexCommand \ref{sub:Requesting-Features}
477 about filing feature requests
478 \begin_inset LatexCommand \index{Requesting features}
483 \begin_inset LatexCommand \index{Feature request}
493 \begin_inset LatexCommand \index{Installation}
500 For most users it is sufficient to skip to either section
501 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
506 \begin_inset LatexCommand \ref{sub:Windows-Install}
511 More detailled instructions follow below.
515 \begin_inset LatexCommand \index{Options SDCC configuration}
522 The install paths, search paths and other options are defined when running
524 The defaults can be overridden by:
526 \labelwidthstring 00.00.0000
538 -prefix see table below
540 \labelwidthstring 00.00.0000
552 -exec_prefix see table below
554 \labelwidthstring 00.00.0000
566 -bindir see table below
568 \labelwidthstring 00.00.0000
580 -datadir see table below
582 \labelwidthstring 00.00.0000
584 docdir environment variable, see table below
586 \labelwidthstring 00.00.0000
588 include_dir_suffix environment variable, see table below
590 \labelwidthstring 00.00.0000
592 lib_dir_suffix environment variable, see table below
594 \labelwidthstring 00.00.0000
596 sdccconf_h_dir_separator environment variable, either / or
601 This character will only be used in sdccconf.h; don't forget it's a C-header,
602 therefore a double-backslash is needed there.
604 \labelwidthstring 00.00.0000
616 -disable-mcs51-port Excludes the Intel mcs51 port
618 \labelwidthstring 00.00.0000
630 -disable-gbz80-port Excludes the Gameboy gbz80 port
632 \labelwidthstring 00.00.0000
644 -disable-z80-port Excludes the z80 port
646 \labelwidthstring 00.00.0000
658 -disable-avr-port Excludes the AVR port
660 \labelwidthstring 00.00.0000
672 -disable-ds390-port Excludes the DS390 port
674 \labelwidthstring 00.00.0000
686 -disable-hc08-port Excludes the HC08 port
688 \labelwidthstring 00.00.0000
700 -disable-pic-port Excludes the PIC port
702 \labelwidthstring 00.00.0000
714 -disable-xa51-port Excludes the XA51 port
716 \labelwidthstring 00.00.0000
728 -disable-ucsim Disables configuring and building of ucsim
730 \labelwidthstring 00.00.0000
742 -disable-device-lib-build Disables automatically building device libraries
744 \labelwidthstring 00.00.0000
756 -disable-packihx Disables building packihx
758 \labelwidthstring 00.00.0000
770 -enable-libgc Use the Bohem memory allocator.
771 Lower runtime footprint.
774 Furthermore the environment variables CC, CFLAGS, ...
775 the tools and their arguments can be influenced.
776 Please see `configure -
786 -help` and the man/info pages of `configure` for details.
790 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
791 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
792 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
793 At the moment it's not possible to change the default settings (it was
794 simply never required).
798 These configure options are compiled into the binaries, and can only be
799 changed by rerunning 'configure' and recompiling SDCC.
800 The configure options are written in
804 to distinguish them from run time environment variables (see section search
810 \begin_inset Quotes sld
814 \begin_inset Quotes srd
817 are used by the SDCC team to build the official Win32 binaries.
818 The SDCC team uses Mingw32 to build the official Windows binaries, because
825 a gcc compiler and last but not least
828 the binaries can be built by cross compiling on Sourceforge's compile farm.
831 See the examples, how to pass the Win32 settings to 'configure'.
832 The other Win32 builds using Borland, VC or whatever don't use 'configure',
833 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
845 <lyxtabular version="3" rows="8" columns="3">
847 <column alignment="block" valignment="top" leftline="true" width="0in">
848 <column alignment="block" valignment="top" leftline="true" width="0in">
849 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
850 <row topline="true" bottomline="true">
851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1010 <row topline="true">
1011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1048 <row topline="true">
1049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1076 <row topline="true" bottomline="true">
1077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1113 'configure' also computes relative paths.
1114 This is needed for full relocatability of a binary package and to complete
1115 search paths (see section search paths below):
1121 \begin_inset Tabular
1122 <lyxtabular version="3" rows="4" columns="3">
1124 <column alignment="block" valignment="top" leftline="true" width="0in">
1125 <column alignment="block" valignment="top" leftline="true" width="0in">
1126 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1127 <row topline="true" bottomline="true">
1128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1153 <row topline="true" bottomline="true">
1154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1181 <row bottomline="true">
1182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1209 <row bottomline="true">
1210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1261 \begin_inset Quotes srd
1265 \begin_inset Quotes srd
1279 \begin_inset Quotes srd
1283 \begin_inset Quotes srd
1311 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1320 \begin_inset Quotes srd
1323 i586-mingw32msvc-gcc
1324 \begin_inset Quotes srd
1328 \begin_inset Quotes srd
1331 i586-mingw32msvc-g++
1332 \begin_inset Quotes srd
1340 \begin_inset Quotes srd
1343 i586-mingw32msvc-ranlib
1344 \begin_inset Quotes srd
1352 \begin_inset Quotes srd
1355 i586-mingw32msvc-strip
1356 \begin_inset Quotes srd
1374 \begin_inset Quotes srd
1378 \begin_inset Quotes srd
1396 \begin_inset Quotes srd
1400 \begin_inset Quotes srd
1408 \begin_inset Quotes srd
1412 \begin_inset Quotes srd
1420 \begin_inset Quotes srd
1424 \begin_inset Quotes srd
1432 \begin_inset Quotes srd
1436 \begin_inset Quotes srd
1443 sdccconf_h_dir_separator=
1444 \begin_inset Quotes srd
1456 \begin_inset Quotes srd
1473 -disable-device-lib-build
1501 -host=i586-mingw32msvc -
1511 -build=unknown-unknown-linux-gnu
1515 \begin_inset Quotes sld
1519 \begin_inset Quotes srd
1522 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1531 \begin_inset Quotes srd
1535 \begin_inset Quotes srd
1543 \begin_inset Quotes srd
1547 \begin_inset Quotes srd
1565 \begin_inset Quotes srd
1569 \begin_inset Quotes srd
1587 \begin_inset Quotes srd
1591 \begin_inset Quotes srd
1599 \begin_inset Quotes srd
1603 \begin_inset Quotes srd
1611 \begin_inset Quotes srd
1615 \begin_inset Quotes srd
1623 \begin_inset Quotes srd
1627 \begin_inset Quotes srd
1634 sdccconf_h_dir_separator=
1635 \begin_inset Quotes srd
1647 \begin_inset Quotes srd
1667 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1678 -C' turns on caching, which gives a little bit extra speed.
1679 However if options are changed, it can be necessary to delete the config.cache
1684 \begin_inset LatexCommand \label{sub:Install-paths}
1689 \begin_inset LatexCommand \index{Install paths}
1695 \added_space_top medskip \align center
1697 \begin_inset Tabular
1698 <lyxtabular version="3" rows="5" columns="4">
1700 <column alignment="center" valignment="top" leftline="true" width="0">
1701 <column alignment="center" valignment="top" leftline="true" width="0">
1702 <column alignment="center" valignment="top" leftline="true" width="0">
1703 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1704 <row topline="true" bottomline="true">
1705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1746 <row topline="true">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1786 <row topline="true">
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1802 $DATADIR/ $INCLUDE_DIR_SUFFIX
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1810 /usr/local/share/sdcc/include
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1826 <row topline="true">
1827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1842 $DATADIR/$LIB_DIR_SUFFIX
1845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 /usr/local/share/sdcc/lib
1853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1866 <row topline="true" bottomline="true">
1867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1890 /usr/local/share/sdcc/doc
1893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1915 *compiler, preprocessor, assembler, and linker
1921 is auto-appended by the compiler, e.g.
1922 small, large, z80, ds390 etc
1925 The install paths can still be changed during `make install` with e.g.:
1928 make install prefix=$(HOME)/local/sdcc
1931 Of course this doesn't change the search paths compiled into the binaries.
1935 \begin_inset LatexCommand \label{sub:Search-Paths}
1940 \begin_inset LatexCommand \index{Search path}
1947 Some search paths or parts of them are determined by configure variables
1952 , see section above).
1953 Further search paths are determined by environment variables during runtime.
1956 The paths searched when running the compiler are as follows (the first catch
1962 Binary files (preprocessor, assembler and linker)
1968 \begin_inset Tabular
1969 <lyxtabular version="3" rows="4" columns="3">
1971 <column alignment="block" valignment="top" leftline="true" width="0in">
1972 <column alignment="block" valignment="top" leftline="true" width="0in">
1973 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1974 <row topline="true" bottomline="true">
1975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2000 <row topline="true">
2001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2030 <row topline="true">
2031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 Path of argv[0] (if available)
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2056 <row topline="true" bottomline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2098 \begin_inset Tabular
2099 <lyxtabular version="3" rows="6" columns="3">
2101 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2102 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2103 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2104 <row topline="true" bottomline="true">
2105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2130 <row topline="true">
2131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2186 <row topline="true">
2187 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2212 <row topline="true">
2213 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2227 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2250 <row topline="true">
2251 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2332 <row topline="true" bottomline="true">
2333 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2349 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2354 /usr/local/share/sdcc/
2359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2387 -nostdinc disables the last two search paths.
2397 With the exception of
2398 \begin_inset Quotes sld
2412 \begin_inset Quotes srd
2419 is auto-appended by the compiler (e.g.
2420 small, large, z80, ds390 etc.).
2427 \begin_inset Tabular
2428 <lyxtabular version="3" rows="6" columns="3">
2430 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2431 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2432 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2433 <row topline="true" bottomline="true">
2434 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2442 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2459 <row topline="true">
2460 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2515 <row topline="true">
2516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2528 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2555 <row topline="true">
2556 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2567 $LIB_DIR_SUFFIX/<model>
2570 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2584 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2601 <row topline="true">
2602 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2617 $LIB_DIR_SUFFIX/<model>
2620 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2729 <row topline="true" bottomline="true">
2730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2739 $LIB_DIR_SUFFIX/<model>
2742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 /usr/local/share/sdcc/
2754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2772 Don't delete any of the stray spaces in the table above without checking
2773 the HTML output (last line)!
2789 -nostdlib disables the last two search paths.
2793 \begin_inset LatexCommand \index{Building SDCC}
2800 Building SDCC on Linux
2801 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2810 Download the source package
2812 either from the SDCC CVS repository or from the
2813 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2819 , it will be named something like sdcc
2832 Bring up a command line terminal, such as xterm.
2837 Unpack the file using a command like:
2840 "tar -xvzf sdcc.src.tar.gz
2845 , this will create a sub-directory called sdcc with all of the sources.
2848 Change directory into the main SDCC directory, for example type:
2865 This configures the package for compilation on your system.
2881 All of the source packages will compile, this can take a while.
2897 This copies the binary executables, the include files, the libraries and
2898 the documentation to the install directories.
2901 Building SDCC on OSX 2.x
2904 Follow the instruction for Linux.
2908 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2909 )) fails to compile SDCC.
2910 Fortunately there's also gcc 2.9.x installed, which works fine.
2911 This compiler can be selected by running 'configure' with:
2914 ./configure CC=gcc2 CXX=g++2
2917 Cross compiling SDCC on Linux for Windows
2920 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2921 See section 'Configure Options'.
2924 Building SDCC on Windows
2927 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2929 They use Unix-sockets, which are not available on Win32.
2932 Building SDCC using Cygwin and Mingw32
2935 For building and installing a Cygwin executable follow the instructions
2941 \begin_inset Quotes sld
2945 \begin_inset Quotes srd
2948 Win32-binary can be built, which will not need the Cygwin-DLL.
2949 For the necessary 'configure' options see section 'configure options' or
2950 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2954 In order to install Cygwin on Windows download setup.exe from
2955 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2961 \begin_inset Quotes sld
2964 default text file type
2965 \begin_inset Quotes srd
2969 \begin_inset Quotes sld
2973 \begin_inset Quotes srd
2976 and download/install at least the following packages.
2977 Some packages are selected by default, others will be automatically selected
2978 because of dependencies with the manually selected packages.
2979 Never deselect these packages!
2988 gcc ; version 3.x is fine, no need to use the old 2.9x
2991 binutils ; selected with gcc
2997 rxvt ; a nice console, which makes life much easier under windoze (see below)
3000 man ; not really needed for building SDCC, but you'll miss it sooner or
3004 less ; not really needed for building SDCC, but you'll miss it sooner or
3008 cvs ; only if you use CVS access
3011 If you want to develop something you'll need:
3014 python ; for the regression tests
3017 gdb ; the gnu debugger, together with the nice GUI
3018 \begin_inset Quotes sld
3022 \begin_inset Quotes srd
3028 openssh ; to access the CF or commit changes
3031 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3032 use autoconf-stable!
3035 rxvt is a nice console with history.
3036 Replace in your cygwin.bat the line
3055 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3058 -bg black -fg white -geometry 100x65 -e bash -
3071 Text selected with the mouse is automatically copied to the clipboard, pasting
3072 works with shift-insert.
3076 The other good tip is to make sure you have no //c/-style paths anywhere,
3077 use /cygdrive/c/ instead.
3078 Using // invokes a network lookup which is very slow.
3080 \begin_inset Quotes sld
3084 \begin_inset Quotes srd
3087 is too long, you can change it with e.g.
3093 SDCC sources use the unix line ending LF.
3094 Life is much easier, if you store the source tree on a drive which is mounted
3096 And use an editor which can handle LF-only line endings.
3097 Make sure not to commit files with windows line endings.
3098 The tabulator spacing used in the project is 8.
3101 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3106 Download the source package
3108 either from the SDCC CVS repository or from the
3109 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3115 , it will be named something like sdcc
3122 SDCC is distributed with all the projects, workspaces, and files you need
3123 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3124 doesn't build under MSVC).
3125 The workspace name is 'sdcc.dsw'.
3126 Please note that as it is now, all the executables are created in a folder
3130 Once built you need to copy the executables from sdcc
3134 bin before running SDCC.
3139 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3140 flex.exe, and gawk.exe.
3141 One good place to get them is
3142 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3150 Download the file UnxUtils
3151 \begin_inset LatexCommand \index{UnxUtils}
3156 Now you have to install the utilities and setup MSVC so it can locate the
3158 Here there are two alternatives (choose one!):
3165 a) Extract UnxUtils.zip to your C:
3167 hard disk PRESERVING the original paths, otherwise bison won't work.
3168 (If you are using WinZip make certain that 'Use folder names' is selected)
3172 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3173 in 'Show directories for:' select 'Executable files', and in the directories
3174 window add a new path: 'C:
3184 (As a side effect, you get a bunch of Unix utilities that could be useful,
3185 such as diff and patch.)
3192 This one avoids extracting a bunch of files you may not use, but requires
3197 a) Create a directory were to put the tools needed, or use a directory already
3205 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3206 to such directory WITHOUT preserving the original paths.
3207 (If you are using WinZip make certain that 'Use folder names' is not selected)
3211 c) Rename bison.exe to '_bison.exe'.
3215 d) Create a batch file 'bison.bat' in 'C:
3219 ' and add these lines:
3239 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3243 Steps 'c' and 'd' are needed because bison requires by default that the
3244 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3245 '/usr/local/share/' I think.
3246 So it is necessary to tell bison where those files are located if they
3247 are not in such directory.
3248 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3252 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3253 in 'Show directories for:' select 'Executable files', and in the directories
3254 window add a new path: 'c:
3257 Note that you can use any other path instead of 'c:
3259 util', even the path where the Visual C++ tools are, probably: 'C:
3263 Microsoft Visual Studio
3268 So you don't have to execute step 'e' :)
3272 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3273 the executables from sdcc
3277 bin, and you can compile using SDCC.
3280 Building SDCC Using Borland
3283 From the sdcc directory, run the command "make -f Makefile.bcc".
3284 This should regenerate all the .exe files in the bin directory except for
3285 sdcdb.exe (which currently doesn't build under Borland C++).
3288 If you modify any source files and need to rebuild, be aware that the dependenci
3289 es may not be correctly calculated.
3290 The safest option is to delete all .obj files and run the build again.
3291 From a Cygwin BASH prompt, this can easily be done with the command (be
3292 sure you are in the sdcc directory):
3302 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3304 ) -print -exec rm {}
3313 or on Windows NT/2000/XP from the command prompt with the command:
3320 del /s *.obj *.lib *.rul
3323 from the sdcc directory.
3326 Windows Install Using a Binary Package
3327 \begin_inset LatexCommand \label{sub:Windows-Install}
3334 Download the binary package from
3335 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3339 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3340 This should unpack to a group of sub-directories.
3341 An example directory structure after unpacking the mingw32 package is:
3346 bin for the executables, c:
3354 lib for the include and libraries.
3357 Adjust your environment variable PATH to include the location of the bin
3358 directory or start sdcc using the full path.
3361 Building the Documentation
3364 If the necessary tools (LyX, LaTeX, latex2html) are installed it is as easy
3365 as changing into the doc directory and typing
3369 \begin_inset Quotes srd
3373 \begin_inset Quotes srd
3380 If you want to avoid installing the tools you will have some success with
3381 a bootable Knoppix CD
3382 \begin_inset LatexCommand \url{http://www.knoppix.net}
3387 Prebuilt documentation in html and pdf format is available from
3388 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3395 Reading the Documentation
3398 Currently reading the document in pdf format is recommended, as for unknown
3399 reason the hyperlinks are working there whereas in the html version they
3402 This documentation is in some aspects different from a commercial documentation:
3406 It tries to document SDCC for several processor architectures in one document
3407 (commercially these probably would be separate documents/products).
3409 \begin_inset LatexCommand \index{Status of documentation}
3413 currently matches SDCC for mcs51 and DS390 best and does give too few informati
3418 There are many references pointing away from this documentation.
3419 Don't let this distract you.
3421 was a reference like
3422 \begin_inset LatexCommand \url{www.opencores.org}
3426 together with a statement
3427 \begin_inset Quotes sld
3430 some processors which are targetted by SDCC can be implemented in a
3447 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3452 \begin_inset Quotes srd
3455 we expect you to have a quick look there and come back.
3456 If you read this you are on the right track.
3459 Some sections attribute more space to problems, restrictions and warnings
3460 than to the solution.
3463 The installation section and the section about the debugger is intimidating.
3466 There are still lots of typos and there are more different writing styles
3470 Testing the SDCC Compiler
3473 The first thing you should do after installing your SDCC compiler is to
3489 \begin_inset LatexCommand \index{version}
3496 at the prompt, and the program should run and tell you the version.
3497 If it doesn't run, or gives a message about not finding sdcc program, then
3498 you need to check over your installation.
3499 Make sure that the sdcc bin directory is in your executable search path
3500 defined by the PATH environment setting (
3505 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3512 Install trouble-shooting for suggestions
3515 Make sure that the sdcc program is in the bin folder, if not perhaps something
3516 did not install correctly.
3524 is commonly installed as described in section
3525 \begin_inset Quotes sld
3528 Install and search paths
3529 \begin_inset Quotes srd
3538 Make sure the compiler works on a very simple example.
3539 Type in the following test.c program using your favorite
3565 Compile this using the following command:
3574 If all goes well, the compiler will generate a test.asm and test.rel file.
3575 Congratulations, you've just compiled your first program with SDCC.
3576 We used the -c option to tell SDCC not to link the generated code, just
3577 to keep things simple for this step.
3585 The next step is to try it with the linker.
3595 If all goes well the compiler will link with the libraries and produce
3596 a test.ihx output file.
3601 (no test.ihx, and the linker generates warnings), then the problem is most
3610 usr/local/share/sdcc/lib directory
3617 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3624 Install trouble-shooting for suggestions).
3632 The final test is to ensure
3640 header files and libraries.
3641 Edit test.c and change it to the following:
3658 strcpy(str1, "testing");
3665 Compile this by typing
3672 This should generate a test.ihx output file, and it should give no warnings
3673 such as not finding the string.h file.
3674 If it cannot find the string.h file, then the problem is that
3678 cannot find the /usr/local/share/sdcc/include directory
3685 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3692 Install trouble-shooting section for suggestions).
3710 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3714 to find exactly where SDCC is looking for the include and lib files.
3717 Install Trouble-shooting
3718 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3723 \begin_inset LatexCommand \index{Install trouble-shooting}
3730 SDCC does not build correctly.
3733 A thing to try is starting from scratch by unpacking the .tgz source package
3734 again in an empty directory.
3742 ./configure 2>&1 | tee configure.log
3756 make 2>&1 | tee make.log
3763 If anything goes wrong, you can review the log files to locate the problem.
3764 Or a relevant part of this can be attached to an email that could be helpful
3765 when requesting help from the mailing list.
3769 \begin_inset Quotes sld
3773 \begin_inset Quotes srd
3780 \begin_inset Quotes sld
3784 \begin_inset Quotes srd
3787 command is a script that analyzes your system and performs some configuration
3788 to ensure the source package compiles on your system.
3789 It will take a few minutes to run, and will compile a few tests to determine
3790 what compiler features are installed.
3794 \begin_inset Quotes sld
3798 \begin_inset Quotes srd
3804 This runs the GNU make tool, which automatically compiles all the source
3805 packages into the final installed binary executables.
3809 \begin_inset Quotes sld
3813 \begin_inset Quotes erd
3819 This will install the compiler, other executables libraries and include
3820 files into the appropriate directories.
3822 \begin_inset LatexCommand \ref{sub:Install-paths}
3828 \begin_inset LatexCommand \ref{sub:Search-Paths}
3833 about install and search paths.
3835 On most systems you will need super-user privileges to do this.
3841 SDCC is not just a compiler, but a collection of tools by various developers.
3842 These include linkers, assemblers, simulators and other components.
3843 Here is a summary of some of the components.
3844 Note that the included simulator and assembler have separate documentation
3845 which you can find in the source package in their respective directories.
3846 As SDCC grows to include support for other processors, other packages from
3847 various developers are included and may have their own sets of documentation.
3851 You might want to look at the files which are installed in <installdir>.
3852 At the time of this writing, we find the following programs for gcc-builds:
3856 In <installdir>/bin:
3859 sdcc - The compiler.
3862 sdcpp - The C preprocessor.
3865 asx8051 - The assembler for 8051 type processors.
3872 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3875 aslink -The linker for 8051 type processors.
3882 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3885 s51 - The ucSim 8051 simulator.
3888 sdcdb - The source debugger.
3891 packihx - A tool to pack (compress) Intel hex files.
3894 In <installdir>/share/sdcc/include
3900 In <installdir>/share/sdcc/lib
3903 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3907 In <installdir>/share/sdcc/doc
3913 As development for other processors proceeds, this list will expand to include
3914 executables to support processors like AVR, PIC, etc.
3920 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3921 the assembler and linkage editor.
3925 \begin_inset LatexCommand \index{sdcpp}
3929 - The C-Preprocessor
3932 The preprocessor is a modified version of the GNU preprocessor.
3933 The C preprocessor is used to pull in #include sources, process #ifdef
3934 statements, #defines and so on.
3937 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3941 This is retargettable assembler & linkage editor, it was developed by Alan
3943 John Hartman created the version for 8051, and I (Sandeep) have made some
3944 enhancements and bug fixes for it to work properly with SDCC.
3948 \begin_inset LatexCommand \index{s51}
3955 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3956 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3961 The simulator is built as part of the build process.
3962 For more information visit Daniel's web site at:
3963 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3968 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3973 \begin_inset LatexCommand \index{sdcdb}
3977 - Source Level Debugger
3980 Sdcdb is the companion source level debugger.
3981 The current version of the debugger uses Daniel's Simulator S51
3982 \begin_inset LatexCommand \index{s51}
3986 , but can be easily changed to use other simulators.
3995 Single Source File Projects
3998 For single source file 8051 projects the process is very simple.
3999 Compile your programs with the following command
4002 "sdcc sourcefile.c".
4006 This will compile, assemble and link your source file.
4007 Output files are as follows
4011 \begin_inset LatexCommand \index{<file>.asm}
4016 \begin_inset LatexCommand \index{Assembler source}
4020 file created by the compiler
4024 \begin_inset LatexCommand \index{<file>.lst}
4029 \begin_inset LatexCommand \index{Assembler listing}
4033 file created by the Assembler
4037 \begin_inset LatexCommand \index{<file>.rst}
4042 \begin_inset LatexCommand \index{Assembler listing}
4046 file updated with linkedit information, created by linkage editor
4050 \begin_inset LatexCommand \index{<file>.sym}
4055 \begin_inset LatexCommand \index{Symbol listing}
4059 for the sourcefile, created by the assembler
4063 \begin_inset LatexCommand \index{<file>.rel}
4068 \begin_inset LatexCommand \index{Object file}
4072 created by the assembler, input to Linkage editor
4076 \begin_inset LatexCommand \index{<file>.map}
4081 \begin_inset LatexCommand \index{Memory map}
4085 for the load module, created by the Linker
4089 \begin_inset LatexCommand \index{<file>.mem}
4093 - A file with a summary of the memory usage
4097 \begin_inset LatexCommand \index{<file>.ihx}
4101 - The load module in Intel hex format
4102 \begin_inset LatexCommand \index{Intel hex format}
4106 (you can select the Motorola S19 format
4107 \begin_inset LatexCommand \index{Motorola S19 format}
4122 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4127 If you need another format you might want to use
4134 \begin_inset LatexCommand \index{objdump}
4145 \begin_inset LatexCommand \index{srecord}
4153 \begin_inset LatexCommand \index{.adb}
4157 - An intermediate file containing debug information needed to create the
4169 \begin_inset LatexCommand \index{-\/-debug}
4177 \begin_inset LatexCommand \index{<file>.cdb}
4181 - An optional file (with -
4191 -debug) containing debug information
4196 \begin_inset LatexCommand \index{<file> (no extension)}
4201 \begin_inset LatexCommand \index{AOMF51}
4205 file containing debug information (with -
4216 This format is commonly used by third party tools (debuggers
4217 \begin_inset LatexCommand \index{Debugger}
4221 , simulators, emulators)
4225 \begin_inset LatexCommand \index{<file>.dump*}
4229 - Dump file to debug the compiler it self (with -
4239 -dumpall) (see section
4240 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4246 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4252 \begin_inset Quotes sld
4255 Anatomy of the compiler
4256 \begin_inset Quotes srd
4262 Projects with Multiple Source Files
4265 SDCC can compile only ONE file at a time.
4266 Let us for example assume that you have a project containing the following
4271 foo1.c (contains some functions)
4273 foo2.c (contains some more functions)
4275 foomain.c (contains more functions and the function main)
4283 The first two files will need to be compiled separately with the commands:
4315 Then compile the source file containing the
4320 \begin_inset LatexCommand \index{Linker}
4324 the files together with the following command:
4332 foomain.c\SpecialChar ~
4333 foo1.rel\SpecialChar ~
4338 \begin_inset LatexCommand \index{.rel}
4350 can be separately compiled as well:
4361 sdcc foomain.rel foo1.rel foo2.rel
4368 The file containing the
4383 file specified in the command line, since the linkage editor processes
4384 file in the order they are presented to it.
4385 The linker is invoked from SDCC using a script file with extension .lnk
4386 \begin_inset LatexCommand \index{.lnk}
4391 You can view this file to troubleshoot linking problems such as those arising
4392 from missing libraries.
4395 Projects with Additional Libraries
4396 \begin_inset LatexCommand \index{Libraries}
4403 Some reusable routines may be compiled into a library, see the documentation
4404 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4408 \begin_inset LatexCommand \index{.lib}
4415 Libraries created in this manner can be included in the command line.
4416 Make sure you include the -L <library-path> option to tell the linker where
4417 to look for these files if they are not in the current directory.
4418 Here is an example, assuming you have the source file
4430 (if that is not the same as your current project):
4437 sdcc foomain.c foolib.lib -L mylib
4448 must be an absolute path name.
4452 The most efficient way to use libraries is to keep separate modules in separate
4454 The lib file now should name all the modules.rel
4455 \begin_inset LatexCommand \index{rel}
4460 For an example see the standard library file
4464 in the directory <installdir>/share/lib/small.
4467 Command Line Options
4468 \begin_inset LatexCommand \index{Command Line Options}
4475 Processor Selection Options
4476 \begin_inset LatexCommand \index{Options processor selection}
4481 \begin_inset LatexCommand \index{Processor selection options}
4487 \labelwidthstring 00.00.0000
4492 \begin_inset LatexCommand \index{-mmcs51}
4498 Generate code for the Intel MCS51
4499 \begin_inset LatexCommand \index{MCS51}
4503 family of processors.
4504 This is the default processor target.
4506 \labelwidthstring 00.00.0000
4511 \begin_inset LatexCommand \index{-mds390}
4517 Generate code for the Dallas DS80C390
4518 \begin_inset LatexCommand \index{DS80C390}
4524 \labelwidthstring 00.00.0000
4529 \begin_inset LatexCommand \index{-mds400}
4535 Generate code for the Dallas DS80C400
4536 \begin_inset LatexCommand \index{DS80C400}
4542 \labelwidthstring 00.00.0000
4547 \begin_inset LatexCommand \index{-mhc08}
4553 Generate code for the Motorola HC08
4554 \begin_inset LatexCommand \index{HC08}
4558 family of processors (added Oct 2003).
4560 \labelwidthstring 00.00.0000
4565 \begin_inset LatexCommand \index{-mz80}
4571 Generate code for the Zilog Z80
4572 \begin_inset LatexCommand \index{Z80}
4576 family of processors.
4578 \labelwidthstring 00.00.0000
4583 \begin_inset LatexCommand \index{-mgbz80}
4589 Generate code for the GameBoy Z80
4590 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
4596 \labelwidthstring 00.00.0000
4601 \begin_inset LatexCommand \index{-mavr}
4607 Generate code for the Atmel AVR
4608 \begin_inset LatexCommand \index{AVR}
4612 processor (In development, not complete).
4613 AVR users should probably have a look at avr-gcc
4614 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4621 I think it is fair to direct users there for now.
4622 Open source is also about avoiding unnecessary work .
4623 But I didn't find the 'official' link.
4625 \labelwidthstring 00.00.0000
4630 \begin_inset LatexCommand \index{-mpic14}
4636 Generate code for the Microchip PIC 14
4637 \begin_inset LatexCommand \index{PIC14}
4641 -bit processors (p16f84 and variants).
4644 p16f627 p16f628 p16f84 p16f873 p16f877?
4646 \labelwidthstring 00.00.0000
4651 \begin_inset LatexCommand \index{-mpic16}
4657 Generate code for the Microchip PIC 16
4658 \begin_inset LatexCommand \index{PIC16}
4662 -bit processors (p18f452 and variants).
4664 \labelwidthstring 00.00.0000
4670 Generate code for the Toshiba TLCS-900H
4671 \begin_inset LatexCommand \index{TLCS-900H}
4675 processor (In development, not complete).
4677 \labelwidthstring 00.00.0000
4682 \begin_inset LatexCommand \index{-mxa51}
4688 Generate code for the Phillips XA51
4689 \begin_inset LatexCommand \index{XA51}
4693 processor (In development, not complete).
4696 Preprocessor Options
4697 \begin_inset LatexCommand \index{Options preprocessor}
4702 \begin_inset LatexCommand \index{Preprocessor options}
4708 \labelwidthstring 00.00.0000
4713 \begin_inset LatexCommand \index{-I<path>}
4719 The additional location where the pre processor will look for <..h> or
4720 \begin_inset Quotes eld
4724 \begin_inset Quotes erd
4729 \labelwidthstring 00.00.0000
4734 \begin_inset LatexCommand \index{-D<macro[=value]>}
4740 Command line definition of macros.
4741 Passed to the preprocessor.
4743 \labelwidthstring 00.00.0000
4748 \begin_inset LatexCommand \index{-M}
4754 Tell the preprocessor to output a rule suitable for make describing the
4755 dependencies of each object file.
4756 For each source file, the preprocessor outputs one make-rule whose target
4757 is the object file name for that source file and whose dependencies are
4758 all the files `#include'd in it.
4759 This rule may be a single line or may be continued with `
4761 '-newline if it is long.
4762 The list of rules is printed on standard output instead of the preprocessed
4765 \begin_inset LatexCommand \index{-E}
4771 \labelwidthstring 00.00.0000
4776 \begin_inset LatexCommand \index{-C}
4782 Tell the preprocessor not to discard comments.
4783 Used with the `-E' option.
4785 \labelwidthstring 00.00.0000
4790 \begin_inset LatexCommand \index{-MM}
4801 Like `-M' but the output mentions only the user header files included with
4803 \begin_inset Quotes eld
4807 System header files included with `#include <file>' are omitted.
4809 \labelwidthstring 00.00.0000
4814 \begin_inset LatexCommand \index{-Aquestion(answer)}
4820 Assert the answer answer for question, in case it is tested with a preprocessor
4821 conditional such as `#if #question(answer)'.
4822 `-A-' disables the standard assertions that normally describe the target
4825 \labelwidthstring 00.00.0000
4830 \begin_inset LatexCommand \index{-Umacro}
4836 Undefine macro macro.
4837 `-U' options are evaluated after all `-D' options, but before any `-include'
4838 and `-imacros' options.
4840 \labelwidthstring 00.00.0000
4845 \begin_inset LatexCommand \index{-dM}
4851 Tell the preprocessor to output only a list of the macro definitions that
4852 are in effect at the end of preprocessing.
4853 Used with the `-E' option.
4855 \labelwidthstring 00.00.0000
4860 \begin_inset LatexCommand \index{-dD}
4866 Tell the preprocessor to pass all macro definitions into the output, in
4867 their proper sequence in the rest of the output.
4869 \labelwidthstring 00.00.0000
4874 \begin_inset LatexCommand \index{-dN}
4885 Like `-dD' except that the macro arguments and contents are omitted.
4886 Only `#define name' is included in the output.
4888 \labelwidthstring 00.00.0000
4893 preprocessorOption[,preprocessorOption]
4896 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
4901 Pass the preprocessorOption to the preprocessor.
4905 \begin_inset LatexCommand \index{Options linker}
4910 \begin_inset LatexCommand \index{Linker options}
4916 \labelwidthstring 00.00.0000
4936 \begin_inset LatexCommand \index{-\/-lib-path <path>}
4941 \begin_inset LatexCommand \index{-L -\/-lib-path}
4948 <absolute path to additional libraries> This option is passed to the linkage
4949 editor's additional libraries
4950 \begin_inset LatexCommand \index{Libraries}
4955 The path name must be absolute.
4956 Additional library files may be specified in the command line.
4957 See section Compiling programs for more details.
4959 \labelwidthstring 00.00.0000
4976 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
4981 <Value> The start location of the external ram
4982 \begin_inset LatexCommand \index{xdata}
4986 , default value is 0.
4987 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4997 -xram-loc 0x8000 or -
5009 \labelwidthstring 00.00.0000
5026 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5031 <Value> The start location of the code
5032 \begin_inset LatexCommand \index{code}
5036 segment, default value 0.
5037 Note when this option is used the interrupt vector table is also relocated
5038 to the given address.
5039 The value entered can be in Hexadecimal or Decimal format, e.g.: -
5049 -code-loc 0x8000 or -
5061 \labelwidthstring 00.00.0000
5078 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5083 <Value> By default the stack
5084 \begin_inset LatexCommand \index{stack}
5088 is placed after the data segment.
5089 Using this option the stack can be placed anywhere in the internal memory
5091 The value entered can be in Hexadecimal or Decimal format, e.g.
5102 -stack-loc 0x20 or -
5113 Since the sp register is incremented before a push or call, the initial
5114 sp will be set to one byte prior the provided value.
5115 The provided value should not overlap any other memory areas such as used
5116 register banks or the data segment and with enough space for the current
5119 \labelwidthstring 00.00.0000
5136 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5141 <Value> The start location of the internal ram data
5142 \begin_inset LatexCommand \index{data}
5147 The value entered can be in Hexadecimal or Decimal format, eg.
5169 (By default, the start location of the internal ram data segment is set
5170 as low as possible in memory, taking into account the used register banks
5171 and the bit segment at address 0x20.
5172 For example if register banks 0 and 1 are used without bit variables, the
5173 data segment will be set, if -
5183 -data-loc is not used, to location 0x10.)
5185 \labelwidthstring 00.00.0000
5202 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5207 <Value> The start location of the indirectly addressable internal ram
5208 \begin_inset LatexCommand \index{idata}
5212 of the 8051, default value is 0x80.
5213 The value entered can be in Hexadecimal or Decimal format, eg.
5224 -idata-loc 0x88 or -
5236 \labelwidthstring 00.00.0000
5253 <Value> The start location of the bit
5254 \begin_inset LatexCommand \index{bit}
5258 addressable internal ram of the 8051.
5264 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5267 \labelwidthstring 00.00.0000
5282 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5291 The linker output (final object code) is in Intel Hex format.
5292 \begin_inset LatexCommand \index{Intel hex format}
5296 (This is the default option).
5298 \labelwidthstring 00.00.0000
5313 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5322 The linker output (final object code) is in Motorola S19 format
5323 \begin_inset LatexCommand \index{Motorola S19 format}
5329 \labelwidthstring 00.00.0000
5334 linkOption[,linkOption]
5337 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5342 Pass the linkOption to the linker.
5346 \begin_inset LatexCommand \index{Options MCS51}
5351 \begin_inset LatexCommand \index{MCS51 options}
5357 \labelwidthstring 00.00.0000
5372 \begin_inset LatexCommand \index{-\/-model-small}
5383 Generate code for Small Model programs see section Memory Models for more
5385 This is the default model.
5387 \labelwidthstring 00.00.0000
5402 \begin_inset LatexCommand \index{-\/-model-large}
5408 Generate code for Large model programs see section Memory Models for more
5410 If this option is used all source files in the project have to be compiled
5413 \labelwidthstring 00.00.0000
5428 \begin_inset LatexCommand \index{-\/-xstack}
5434 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5435 variables and passing parameters.
5437 \begin_inset LatexCommand \ref{sub:External-Stack}
5442 External Stack for more details.
5444 \labelwidthstring 00.00.0000
5462 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5466 Causes the linker to check if the internal ram usage is within limits of
5469 \labelwidthstring 00.00.0000
5487 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5491 Causes the linker to check if the external ram usage is within limits of
5494 \labelwidthstring 00.00.0000
5512 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5516 Causes the linker to check if the code memory usage is within limits of
5521 \begin_inset LatexCommand \index{Options DS390}
5526 \begin_inset LatexCommand \index{DS390 options}
5532 \labelwidthstring 00.00.0000
5549 \begin_inset LatexCommand \index{-\/-model-flat24}
5559 Generate 24-bit flat mode code.
5560 This is the one and only that the ds390 code generator supports right now
5561 and is default when using
5566 See section Memory Models for more details.
5568 \labelwidthstring 00.00.0000
5583 \begin_inset LatexCommand \index{-\/-protect-sp-update}
5589 disable interrupts during ESP:SP updates
5591 \labelwidthstring 00.00.0000
5608 \begin_inset LatexCommand \index{-\/-stack-10bit}
5612 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5613 This is the one and only that the ds390 code generator supports right now
5614 and is default when using
5619 In this mode, the stack is located in the lower 1K of the internal RAM,
5620 which is mapped to 0x400000.
5621 Note that the support is incomplete, since it still uses a single byte
5622 as the stack pointer.
5623 This means that only the lower 256 bytes of the potential 1K stack space
5624 will actually be used.
5625 However, this does allow you to reclaim the precious 256 bytes of low RAM
5626 for use for the DATA and IDATA segments.
5627 The compiler will not generate any code to put the processor into 10 bit
5629 It is important to ensure that the processor is in this mode before calling
5630 any re-entrant functions compiled with this option.
5631 In principle, this should work with the
5644 \begin_inset LatexCommand \index{-\/-stack-auto}
5650 option, but that has not been tested.
5651 It is incompatible with the
5664 \begin_inset LatexCommand \index{-\/-xstack}
5671 It also only makes sense if the processor is in 24 bit contiguous addressing
5684 -model-flat24 option
5688 \labelwidthstring 00.00.0000
5703 \begin_inset LatexCommand \index{-\/-stack-probe}
5709 insert call to function __stack_probe at each function prologue
5711 \labelwidthstring 00.00.0000
5726 \begin_inset LatexCommand \index{-\/-tini-libid}
5732 <nnnn> LibraryID used in -mTININative
5734 \labelwidthstring 00.00.0000
5749 \begin_inset LatexCommand \index{-\/-use-accelerator}
5755 generate code for DS390 Arithmetic Accelerator
5759 \begin_inset LatexCommand \index{Options Z80}
5764 \begin_inset LatexCommand \index{Z80 options}
5770 \labelwidthstring 00.00.0000
5787 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5797 Force a called function to always save BC.
5799 \labelwidthstring 00.00.0000
5816 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5820 When linking, skip the standard crt0.o object file.
5821 You must provide your own crt0.o for your system when linking.
5825 Optimization Options
5826 \begin_inset LatexCommand \index{Options optimization}
5831 \begin_inset LatexCommand \index{Optimization options}
5837 \labelwidthstring 00.00.0000
5852 \begin_inset LatexCommand \index{-\/-nogcse}
5858 Will not do global subexpression elimination, this option may be used when
5859 the compiler creates undesirably large stack/data spaces to store compiler
5861 A warning message will be generated when this happens and the compiler
5862 will indicate the number of extra bytes it allocated.
5863 It recommended that this option NOT be used, #pragma\SpecialChar ~
5865 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5869 can be used to turn off global subexpression elimination
5870 \begin_inset LatexCommand \index{Subexpression elimination}
5874 for a given function only.
5876 \labelwidthstring 00.00.0000
5891 \begin_inset LatexCommand \index{-\/-noinvariant}
5897 Will not do loop invariant optimizations, this may be turned off for reasons
5898 explained for the previous option.
5899 For more details of loop optimizations performed see section Loop Invariants.It
5900 recommended that this option NOT be used, #pragma\SpecialChar ~
5902 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5906 can be used to turn off invariant optimizations for a given function only.
5908 \labelwidthstring 00.00.0000
5923 \begin_inset LatexCommand \index{-\/-noinduction}
5929 Will not do loop induction optimizations, see section strength reduction
5930 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5933 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5937 can be used to turn off induction optimizations for a given function only.
5939 \labelwidthstring 00.00.0000
5954 \begin_inset LatexCommand \index{-\/-nojtbound}
5965 Will not generate boundary condition check when switch statements
5966 \begin_inset LatexCommand \index{switch statement}
5970 are implemented using jump-tables.
5972 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
5977 Switch Statements for more details.
5978 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5980 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5984 can be used to turn off boundary checking for jump tables for a given function
5987 \labelwidthstring 00.00.0000
6002 \begin_inset LatexCommand \index{-\/-noloopreverse}
6011 Will not do loop reversal
6012 \begin_inset LatexCommand \index{Loop reversing}
6018 \labelwidthstring 00.00.0000
6035 \begin_inset LatexCommand \index{-\/-nolabelopt }
6039 Will not optimize labels (makes the dumpfiles more readable).
6041 \labelwidthstring 00.00.0000
6056 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6062 Will not memcpy initialized data from code space into xdata space.
6063 This saves a few bytes in code space if you don't have initialized data.
6067 \begin_inset LatexCommand \index{Options other}
6073 \labelwidthstring 00.00.0000
6089 \begin_inset LatexCommand \index{-\/-compile-only}
6094 \begin_inset LatexCommand \index{-c -\/-compile-only}
6100 will compile and assemble the source, but will not call the linkage editor.
6102 \labelwidthstring 00.00.0000
6121 \begin_inset LatexCommand \index{-\/-c1mode}
6127 reads the preprocessed source from standard input and compiles it.
6128 The file name for the assembler output must be specified using the -o option.
6130 \labelwidthstring 00.00.0000
6135 \begin_inset LatexCommand \index{-E}
6141 Run only the C preprocessor.
6142 Preprocess all the C source files specified and output the results to standard
6145 \labelwidthstring 00.00.0000
6151 \begin_inset LatexCommand \index{-o <path/file>}
6157 The output path resp.
6158 file where everything will be placed.
6159 If the parameter is a path, it must have a trailing slash (or backslash
6160 for the Windows binaries) to be recognized as a path.
6163 \labelwidthstring 00.00.0000
6178 \begin_inset LatexCommand \index{-\/-stack-auto}
6189 All functions in the source file will be compiled as
6194 \begin_inset LatexCommand \index{reentrant}
6199 the parameters and local variables will be allocated on the stack
6200 \begin_inset LatexCommand \index{stack}
6205 see section Parameters and Local Variables for more details.
6206 If this option is used all source files in the project should be compiled
6210 \labelwidthstring 00.00.0000
6225 \begin_inset LatexCommand \index{-\/-callee-saves}
6229 function1[,function2][,function3]....
6232 The compiler by default uses a caller saves convention for register saving
6233 across function calls, however this can cause unnecessary register pushing
6234 & popping when calling small functions from larger functions.
6235 This option can be used to switch the register saving convention for the
6236 function names specified.
6237 The compiler will not save registers when calling these functions, no extra
6238 code will be generated at the entry & exit (function prologue
6241 \begin_inset LatexCommand \index{function prologue}
6250 \begin_inset LatexCommand \index{function epilogue}
6256 ) for these functions to save & restore the registers used by these functions,
6257 this can SUBSTANTIALLY reduce code & improve run time performance of the
6259 In the future the compiler (with inter procedural analysis) will be able
6260 to determine the appropriate scheme to use for each function call.
6261 DO NOT use this option for built-in functions such as _mulint..., if this
6262 option is used for a library function the appropriate library function
6263 needs to be recompiled with the same option.
6264 If the project consists of multiple source files then all the source file
6265 should be compiled with the same -
6275 -callee-saves option string.
6276 Also see #pragma\SpecialChar ~
6278 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
6284 \labelwidthstring 00.00.0000
6299 \begin_inset LatexCommand \index{-\/-debug}
6308 When this option is used the compiler will generate debug information, that
6309 can be used with the SDCDB.
6310 The debug information is collected in a file with .cdb extension.
6311 For more information see documentation for SDCDB.
6313 \labelwidthstring 00.00.0000
6318 \begin_inset LatexCommand \index{-S}
6329 Stop after the stage of compilation proper; do not assemble.
6330 The output is an assembler code file for the input file specified.
6332 \labelwidthstring 00.00.0000
6347 \begin_inset LatexCommand \index{-\/-int-long-reent}
6353 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6354 Note by default these libraries are compiled as non-reentrant.
6355 See section Installation for more details.
6357 \labelwidthstring 00.00.0000
6372 \begin_inset LatexCommand \index{-\/-cyclomatic}
6381 This option will cause the compiler to generate an information message for
6382 each function in the source file.
6383 The message contains some
6387 information about the function.
6388 The number of edges and nodes the compiler detected in the control flow
6389 graph of the function, and most importantly the
6391 cyclomatic complexity
6392 \begin_inset LatexCommand \index{Cyclomatic complexity}
6398 see section on Cyclomatic Complexity for more details.
6400 \labelwidthstring 00.00.0000
6415 \begin_inset LatexCommand \index{-\/-float-reent}
6424 Floating point library is compiled as reentrant
6425 \begin_inset LatexCommand \index{reentrant}
6430 See section Installation for more details.
6432 \labelwidthstring 00.00.0000
6447 \begin_inset LatexCommand \index{-\/-nooverlay}
6453 The compiler will not overlay parameters and local variables of any function,
6454 see section Parameters and local variables for more details.
6456 \labelwidthstring 00.00.0000
6471 \begin_inset LatexCommand \index{-\/-main-return}
6477 This option can be used when the code generated is called by a monitor
6479 The compiler will generate a 'ret' upon return from the 'main'
6480 \begin_inset LatexCommand \index{main return}
6485 The default setting is to lock up i.e.
6492 \labelwidthstring 00.00.0000
6509 \begin_inset LatexCommand \index{-\/-peep-file}
6514 <filename> This option can be used to use additional rules to be used by
6515 the peep hole optimizer.
6517 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6522 Peep Hole optimizations for details on how to write these rules.
6524 \labelwidthstring 00.00.0000
6539 \begin_inset LatexCommand \index{-\/-no-peep}
6545 Disable peep-hole optimization.
6547 \labelwidthstring 00.00.0000
6562 \begin_inset LatexCommand \index{-\/-peep-asm}
6568 Pass the inline assembler code through the peep hole optimizer.
6569 This can cause unexpected changes to inline assembler code, please go through
6570 the peephole optimizer
6571 \begin_inset LatexCommand \index{Peephole optimizer}
6575 rules defined in the source file tree '<target>/peeph.def' before using
6578 \labelwidthstring 00.00.0000
6593 \begin_inset LatexCommand \index{-\/-nostdincl}
6599 This will prevent the compiler from passing on the default include path
6600 to the preprocessor.
6602 \labelwidthstring 00.00.0000
6617 \begin_inset LatexCommand \index{-\/-nostdlib}
6623 This will prevent the compiler from passing on the default library
6624 \begin_inset LatexCommand \index{Libraries}
6630 \labelwidthstring 00.00.0000
6645 \begin_inset LatexCommand \index{-\/-verbose}
6651 Shows the various actions the compiler is performing.
6653 \labelwidthstring 00.00.0000
6658 \begin_inset LatexCommand \index{-V}
6664 Shows the actual commands the compiler is executing.
6666 \labelwidthstring 00.00.0000
6681 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6687 Hides your ugly and inefficient c-code from the asm file, so you can always
6688 blame the compiler :).
6690 \labelwidthstring 00.00.0000
6705 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6711 Include i-codes in the asm file.
6712 Sounds like noise but is most helpful for debugging the compiler itself.
6714 \labelwidthstring 00.00.0000
6729 \begin_inset LatexCommand \index{-\/-less-pedantic}
6735 Disable some of the more pedantic warnings
6736 \begin_inset LatexCommand \index{Warnings}
6740 (jwk burps: please be more specific here, please!).
6741 If you want rather more than less warnings you should consider using a
6742 separate tool dedicated to syntax checking like
6743 \begin_inset LatexCommand \url{www.splint.org}
6749 \labelwidthstring 00.00.0000
6764 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6770 Display the directories in the compiler's search path
6772 \labelwidthstring 00.00.0000
6787 \begin_inset LatexCommand \index{-\/-vc}
6793 Display errors and warnings using MSVC style, so you can use SDCC with
6796 \labelwidthstring 00.00.0000
6811 \begin_inset LatexCommand \index{-\/-use-stdout}
6817 Send errors and warnings to stdout instead of stderr.
6819 \labelwidthstring 00.00.0000
6824 asmOption[,asmOption]
6827 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
6832 Pass the asmOption to the assembler.
6835 Intermediate Dump Options
6836 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
6841 \begin_inset LatexCommand \index{Options intermediate dump}
6846 \begin_inset LatexCommand \index{Intermediate dump options}
6853 The following options are provided for the purpose of retargetting and debugging
6855 These provided a means to dump the intermediate code (iCode
6856 \begin_inset LatexCommand \index{iCode}
6860 ) generated by the compiler in human readable form at various stages of
6861 the compilation process.
6864 \labelwidthstring 00.00.0000
6879 \begin_inset LatexCommand \index{-\/-dumpraw}
6885 This option will cause the compiler to dump the intermediate code into
6888 <source filename>.dumpraw
6890 just after the intermediate code has been generated for a function, i.e.
6891 before any optimizations are done.
6893 \begin_inset LatexCommand \index{Basic blocks}
6897 at this stage ordered in the depth first number, so they may not be in
6898 sequence of execution.
6900 \labelwidthstring 00.00.0000
6915 \begin_inset LatexCommand \index{-\/-dumpgcse}
6921 Will create a dump of iCode's, after global subexpression elimination
6922 \begin_inset LatexCommand \index{Global subexpression elimination}
6928 <source filename>.dumpgcse.
6930 \labelwidthstring 00.00.0000
6945 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6951 Will create a dump of iCode's, after deadcode elimination
6952 \begin_inset LatexCommand \index{Dead-code elimination}
6958 <source filename>.dumpdeadcode.
6960 \labelwidthstring 00.00.0000
6975 \begin_inset LatexCommand \index{-\/-dumploop}
6984 Will create a dump of iCode's, after loop optimizations
6985 \begin_inset LatexCommand \index{Loop optimization}
6991 <source filename>.dumploop.
6993 \labelwidthstring 00.00.0000
7008 \begin_inset LatexCommand \index{-\/-dumprange}
7017 Will create a dump of iCode's, after live range analysis
7018 \begin_inset LatexCommand \index{Live range analysis}
7024 <source filename>.dumprange.
7026 \labelwidthstring 00.00.0000
7041 \begin_inset LatexCommand \index{-\/-dumlrange}
7047 Will dump the life ranges
7048 \begin_inset LatexCommand \index{Live range analysis}
7054 \labelwidthstring 00.00.0000
7069 \begin_inset LatexCommand \index{-\/-dumpregassign}
7078 Will create a dump of iCode's, after register assignment
7079 \begin_inset LatexCommand \index{Register assignment}
7085 <source filename>.dumprassgn.
7087 \labelwidthstring 00.00.0000
7102 \begin_inset LatexCommand \index{-\/-dumplrange}
7108 Will create a dump of the live ranges of iTemp's
7110 \labelwidthstring 00.00.0000
7125 \begin_inset LatexCommand \index{-\/-dumpall}
7136 Will cause all the above mentioned dumps to be created.
7139 Redirecting output on Windows Shells
7142 By default SDCC writes it's error messages to
7143 \begin_inset Quotes sld
7147 \begin_inset Quotes srd
7151 To force all messages to
7152 \begin_inset Quotes sld
7156 \begin_inset Quotes srd
7180 \begin_inset LatexCommand \index{-\/-use-stdout}
7185 Aditionaly, if you happen to have visual studio installed in your windows
7186 machine, you can use it to compile your sources using a custom build and
7202 \begin_inset LatexCommand \index{-\/-vc}
7207 Something like this should work:
7251 -model-large -c $(InputPath)
7254 Environment variables
7255 \begin_inset LatexCommand \index{Environment variables}
7262 SDCC recognizes the following environment variables:
7264 \labelwidthstring 00.00.0000
7269 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7275 SDCC installs a signal handler
7276 \begin_inset LatexCommand \index{signal handler}
7280 to be able to delete temporary files after an user break (^C) or an exception.
7281 If this environment variable is set, SDCC won't install the signal handler
7282 in order to be able to debug SDCC.
7284 \labelwidthstring 00.00.0000
7291 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7297 Path, where temporary files will be created.
7298 The order of the variables is the search order.
7299 In a standard *nix environment these variables are not set, and there's
7300 no need to set them.
7301 On Windows it's recommended to set one of them.
7303 \labelwidthstring 00.00.0000
7308 \begin_inset LatexCommand \index{SDCC\_HOME}
7315 \begin_inset LatexCommand \ref{sub:Install-paths}
7321 \begin_inset Quotes sld
7325 \begin_inset Quotes srd
7330 \labelwidthstring 00.00.0000
7335 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7342 \begin_inset LatexCommand \ref{sub:Search-Paths}
7348 \begin_inset Quotes sld
7352 \begin_inset Quotes srd
7357 \labelwidthstring 00.00.0000
7362 \begin_inset LatexCommand \index{SDCC\_LIB}
7369 \begin_inset LatexCommand \ref{sub:Search-Paths}
7375 \begin_inset Quotes sld
7379 \begin_inset Quotes srd
7385 There are some more environment variables recognized by SDCC, but these
7386 are solely used for debugging purposes.
7387 They can change or disappear very quickly, and will never be documented.
7390 Storage Class Language Extensions
7393 MCS51/DS390 Storage Class
7394 \begin_inset LatexCommand \index{Storage class}
7401 In addition to the ANSI storage classes SDCC allows the following MCS51
7402 specific storage classes:
7403 \layout Subsubsection
7406 \begin_inset LatexCommand \index{data}
7417 storage class for the Small Memory model.
7418 Variables declared with this storage class will be allocated in the directly
7419 addressable portion of the internal RAM of a 8051, e.g.:
7424 data unsigned char test_data;
7427 Writing 0x01 to this variable generates the assembly code:
7432 75*00 01\SpecialChar ~
7438 \layout Subsubsection
7441 \begin_inset LatexCommand \index{xdata}
7448 Variables declared with this storage class will be placed in the external
7454 storage class for the Large Memory model, e.g.:
7459 xdata unsigned char test_xdata;
7462 Writing 0x01 to this variable generates the assembly code:
7467 90s00r00\SpecialChar ~
7496 \layout Subsubsection
7499 \begin_inset LatexCommand \index{idata}
7506 Variables declared with this storage class will be allocated into the indirectly
7507 addressable portion of the internal ram of a 8051, e.g.:
7512 idata unsigned char test_idata;
7515 Writing 0x01 to this variable generates the assembly code:
7544 Please note, the first 128 byte of idata physically access the same RAM
7546 The original 8051 had 128 byte idata memory, nowadays most devices have
7547 256 byte idata memory.
7549 \begin_inset LatexCommand \index{stack}
7553 is located in idata memory.
7554 \layout Subsubsection
7557 \begin_inset LatexCommand \index{pdata}
7564 Paged xdata access is currently not as straightforward as using the other
7565 addressing modes of a 8051.
7566 The following example writes 0x01 to the address pointed to.
7567 Please note, pdata access physically accesses xdata memory.
7568 The high byte of the address is determined by port P2 (or in case of some
7569 8051 variants by a separate Special Function Register, see section
7570 \begin_inset LatexCommand \ref{sub:MCS51-variants}
7579 pdata unsigned char *test_pdata_ptr;
7591 test_pdata_ptr = (pdata *)0xfe;
7597 *test_pdata_ptr = 1;
7602 Generates the assembly code:
7607 75*01 FE\SpecialChar ~
7611 _test_pdata_ptr,#0xFE
7643 Be extremely carefull if you use pdata together with the -
7654 \begin_inset LatexCommand \index{-\/-xstack}
7659 \layout Subsubsection
7662 \begin_inset LatexCommand \index{code}
7669 'Variables' declared with this storage class will be placed in the code
7675 code unsigned char test_code;
7678 Read access to this variable generates the assembly code:
7683 90s00r6F\SpecialChar ~
7686 mov dptr,#_test_code
7715 indexed arrays of characters in code memory can be accessed efficiently:
7720 code char test_array[] = {'c','h','e','a','p'};
7723 Read access to this array using an 8-bit index generates the assembly code:
7739 90s00r41\SpecialChar ~
7742 mov dptr,#_test_array
7757 \layout Subsubsection
7760 \begin_inset LatexCommand \index{bit}
7767 This is a data-type and a storage class specifier.
7768 When a variable is declared as a bit, it is allocated into the bit addressable
7769 memory of 8051, e.g.:
7777 Writing 1 to this variable generates the assembly code:
7793 The bit addressable memory consists of 128 bits which are located from 0x20
7794 to 0x2f in data memory.
7798 Apart from this 8051 specific storage class most architectures support ANSI-C
7800 \begin_inset LatexCommand \index{bitfields}
7810 Not really meant as examples, but nevertheless showing what bitfields are
7811 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
7815 \layout Subsubsection
7818 \begin_inset LatexCommand \index{sfr}
7823 \begin_inset LatexCommand \index{sbit}
7830 Like the bit keyword,
7834 signifies both a data-type and storage class, they are used to describe
7855 variables of a 8051, eg:
7861 \begin_inset LatexCommand \index{at}
7865 0x80 P0;\SpecialChar ~
7866 /* special function register P0 at location 0x80 */
7868 sbit at 0xd7 CY; /* CY (Carry Flag
7869 \begin_inset LatexCommand \index{Flags}
7874 \begin_inset LatexCommand \index{Carry flag}
7881 Special function registers which are located on an address dividable by
7882 8 are bit-addressable, an
7886 addresses a specific bit within these sfr.
7887 \layout Subsubsection
7890 \begin_inset LatexCommand \index{Pointers}
7894 to MCS51/DS390 specific memory spaces
7897 SDCC allows (via language extensions) pointers to explicitly point to any
7898 of the memory spaces
7899 \begin_inset LatexCommand \index{Memory model}
7904 In addition to the explicit pointers, the compiler uses (by default) generic
7905 pointers which can be used to point to any of the memory spaces.
7909 Pointer declaration examples:
7914 /* pointer physically in internal ram pointing to object in external ram
7917 xdata unsigned char * data p;
7921 /* pointer physically in external ram pointing to object in internal ram
7924 data unsigned char * xdata p;
7928 /* pointer physically in code rom pointing to data in xdata space */
7930 xdata unsigned char * code p;
7934 /* pointer physically in code space pointing to data in code space */
7936 code unsigned char * code p;
7940 /* the following is a generic pointer physically located in xdata space
7946 Well you get the idea.
7951 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7964 The highest order byte of the
7968 pointers contains the data space information.
7969 Assembler support routines are called whenever data is stored or retrieved
7975 These are useful for developing reusable library
7976 \begin_inset LatexCommand \index{Libraries}
7981 Explicitly specifying the pointer type will generate the most efficient
7985 Z80/Z180 Storage Class
7986 \begin_inset LatexCommand \index{Storage class}
7991 \layout Subsubsection
7994 \begin_inset LatexCommand \index{sfr}
7998 (in/out to 8-bit addresses)
8002 \begin_inset LatexCommand \index{Z80}
8006 family has separate address spaces for memory and
8016 \begin_inset LatexCommand \index{I/O memory (Z80/Z180)}
8020 is accessed with special instructions, e.g.:
8025 sfr at 0x78 IoPort;\SpecialChar ~
8027 /* define a var in I/O space at 78h called IoPort */
8031 Writing 0x01 to this variable generates the assembly code:
8051 \layout Subsubsection
8054 \begin_inset LatexCommand \index{sfr}
8058 (in/out to 16-bit addresses)
8065 is used to support 16 bit addresses in I/O memory e.g.:
8070 sfr banked at 0x123 IoPort;
8073 Writing 0x01 to this variable generates the assembly code:
8078 01 23 01\SpecialChar ~
8098 \layout Subsubsection
8101 \begin_inset LatexCommand \index{sfr}
8105 (in0/out0 to 8 bit addresses on Z180
8106 \begin_inset LatexCommand \index{Z180}
8111 \begin_inset LatexCommand \index{HD64180}
8118 The compiler option -
8128 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8130 \begin_inset LatexCommand \index{\#pragma portmode}
8134 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8144 If you include the file z180.h this will be set automatically.
8148 \begin_inset LatexCommand \index{Absolute addressing}
8155 Data items can be assigned an absolute address with the
8158 \begin_inset LatexCommand \index{at}
8164 keyword, in addition to a storage class, e.g.:
8170 \begin_inset LatexCommand \index{xdata}
8175 \begin_inset LatexCommand \index{at}
8179 0x7ffe unsigned int chksum;
8182 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8183 of the external ram.
8188 reserve any space for variables declared in this way (they are implemented
8189 with an equate in the assembler).
8190 Thus it is left to the programmer to make sure there are no overlaps with
8191 other variables that are declared without the absolute address.
8192 The assembler listing file (.lst
8193 \begin_inset LatexCommand \index{<file>.lst}
8197 ) and the linker output files (.rst
8198 \begin_inset LatexCommand \index{<file>.rst}
8203 \begin_inset LatexCommand \index{<file>.map}
8207 ) are good places to look for such overlaps.
8208 Variables with an absolute address are
8215 In case of memory mapped I/O devices the keyword
8219 should be used to tell the compiler that accesses might not be optimized
8226 \begin_inset LatexCommand \index{volatile}
8231 \begin_inset LatexCommand \index{xdata}
8236 \begin_inset LatexCommand \index{at}
8240 0x8000 unsigned char PORTA_8255;
8243 Absolute address can be specified for variables in all storage classes,
8250 \begin_inset LatexCommand \index{bit}
8255 \begin_inset LatexCommand \index{at}
8262 The above example will allocate the variable at offset 0x02 in the bit-addressab
8264 There is no real advantage to assigning absolute addresses to variables
8265 in this manner, unless you want strict control over all the variables allocated.
8266 One possible use would be to write hardware portable code.
8267 For example, if you have a routine that uses one or more of the microcontroller
8268 I/O pins, and such pins are different for two different hardwares, you
8269 can declare the I/O pins in your routine using:
8274 extern volatile bit SDI;
8276 extern volatile bit SCLK;
8278 extern volatile bit CPOL;
8282 void DS1306_put(unsigned char value)
8290 unsigned char mask=0x80;
8314 SDI=(value & mask)?1:0;
8355 Then, someplace in the code for the first hardware you would use
8360 bit at 0x80 SDI;\SpecialChar ~
8364 /* I/O port 0, bit 0 */
8366 bit at 0x81 SCLK;\SpecialChar ~
8369 /* I/O port 0, bit 1 */
8371 bit CPOL;\SpecialChar ~
8382 /* This is a variable, let the linker allocate this one */
8385 Similarly, for the second hardware you would use
8390 bit at 0x83 SDI;\SpecialChar ~
8394 /* I/O port 0, bit 3 */
8396 bit at 0x91 SCLK;\SpecialChar ~
8399 /* I/O port 1, bit 1 */
8402 \begin_inset LatexCommand \index{bit}
8417 /* This is a variable, let the linker allocate this one */
8420 and you can use the same hardware dependent routine without changes, as
8421 for example in a library.
8422 This is somehow similar to sbit, but only one absolute address has to be
8423 specified in the whole project.
8427 \begin_inset LatexCommand \index{Parameters}
8432 \begin_inset LatexCommand \index{function parameter}
8437 \begin_inset LatexCommand \index{Local variable}
8444 Automatic (local) variables and parameters to functions can either be placed
8445 on the stack or in data-space.
8446 The default action of the compiler is to place these variables in the internal
8447 RAM (for small model) or external RAM (for large model).
8448 This in fact makes them similar to
8451 \begin_inset LatexCommand \index{static}
8457 so by default functions are non-reentrant
8458 \begin_inset LatexCommand \index{reentrant}
8467 They can be placed on the stack
8468 \begin_inset LatexCommand \index{stack}
8485 \begin_inset LatexCommand \index{-\/-stack-auto}
8491 option or by using the
8494 \begin_inset LatexCommand \index{reentrant}
8500 keyword in the function declaration, e.g.:
8505 unsigned char foo(char i) reentrant
8519 Since stack space on 8051 is limited, the
8537 option should be used sparingly.
8538 Note that the reentrant keyword just means that the parameters & local
8539 variables will be allocated to the stack, it
8543 mean that the function is register bank independent.
8547 Local variables can be assigned storage classes and absolute
8548 \begin_inset LatexCommand \index{Absolute addressing}
8565 xdata unsigned char i;
8577 data at 0x31 unsigned char j;
8589 In the above example the variable
8593 will be allocated in the external ram,
8597 in bit addressable space and
8616 or when a function is declared as
8620 this should only be done for static variables.
8624 \begin_inset LatexCommand \index{function parameter}
8628 however are not allowed any storage class
8629 \begin_inset LatexCommand \index{storage class}
8633 , (storage classes for parameters will be ignored), their allocation is
8634 governed by the memory model in use, and the reentrancy options.
8638 \begin_inset LatexCommand \label{sub:Overlaying}
8643 \begin_inset LatexCommand \index{Overlaying}
8651 \begin_inset LatexCommand \index{reentrant}
8655 functions SDCC will try to reduce internal ram space usage by overlaying
8656 parameters and local variables of a function (if possible).
8657 Parameters and local variables of a function will be allocated to an overlayabl
8658 e segment if the function has
8660 no other function calls and the function is non-reentrant and the memory
8662 \begin_inset LatexCommand \index{Memory model}
8669 If an explicit storage class
8670 \begin_inset LatexCommand \index{Storage class}
8674 is specified for a local variable, it will NOT be overlayed.
8677 Note that the compiler (not the linkage editor) makes the decision for overlayin
8679 Functions that are called from an interrupt service routine should be preceded
8680 by a #pragma\SpecialChar ~
8682 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8686 if they are not reentrant.
8689 Also note that the compiler does not do any processing of inline assembler
8690 code, so the compiler might incorrectly assign local variables and parameters
8691 of a function into the overlay segment if the inline assembler code calls
8692 other c-functions that might use the overlay.
8693 In that case the #pragma\SpecialChar ~
8694 NOOVERLAY should be used.
8697 Parameters and local variables of functions that contain 16 or 32 bit multiplica
8699 \begin_inset LatexCommand \index{Multiplication}
8704 \begin_inset LatexCommand \index{Division}
8708 will NOT be overlayed since these are implemented using external functions,
8717 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8723 void set_error(unsigned char errcd)
8739 void some_isr () interrupt
8740 \begin_inset LatexCommand \index{interrupt}
8770 In the above example the parameter
8778 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8780 not present, this could cause unpredictable runtime behavior when called
8782 The #pragma\SpecialChar ~
8783 NOOVERLAY ensures that the parameters and local variables for
8784 the function are NOT overlayed.
8787 Interrupt Service Routines
8788 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
8795 SDCC allows interrupt service routines to be coded in C, with some extended
8801 void timer_isr (void) interrupt 1 using 1
8815 The optional number following the
8818 \begin_inset LatexCommand \index{interrupt}
8824 keyword is the interrupt number this routine will service.
8825 When present, the compiler will insert a call to this routine in the interrupt
8826 vector table for the interrupt number specified.
8831 keyword can be used to tell the compiler to use the specified register
8832 bank (8051 specific) when generating code for this function.
8838 If you have multiple source files in your project, interrupt service routines
8839 can be present in any of them, but a prototype of the isr MUST be present
8840 or included in the file that contains the function
8847 Interrupt numbers and the corresponding address & descriptions for the Standard
8848 8051/8052 are listed below.
8849 SDCC will automatically adjust the interrupt vector table to the maximum
8850 interrupt number specified.
8856 \begin_inset Tabular
8857 <lyxtabular version="3" rows="7" columns="3">
8859 <column alignment="center" valignment="top" leftline="true" width="0in">
8860 <column alignment="center" valignment="top" leftline="true" width="0in">
8861 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
8862 <row topline="true" bottomline="true">
8863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8888 <row topline="true">
8889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8914 <row topline="true">
8915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8940 <row topline="true">
8941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8966 <row topline="true">
8967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8992 <row topline="true">
8993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9018 <row topline="true" bottomline="true">
9019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9053 If the interrupt service routine is defined without
9056 \begin_inset LatexCommand \index{using}
9062 a register bank or with register bank 0 (using 0), the compiler will save
9063 the registers used by itself on the stack upon entry and restore them at
9064 exit, however if such an interrupt service routine calls another function
9065 then the entire register bank will be saved on the stack.
9066 This scheme may be advantageous for small interrupt service routines which
9067 have low register usage.
9070 If the interrupt service routine is defined to be using a specific register
9075 are save and restored, if such an interrupt service routine calls another
9076 function (using another register bank) then the entire register bank of
9077 the called function will be saved on the stack.
9078 This scheme is recommended for larger interrupt service routines.
9081 Using interrupts opens the door for some very interesting bugs:
9084 If the interrupt service routines changes variables which are accessed by
9085 other functions these variables should be declared
9090 \begin_inset LatexCommand \index{volatile}
9095 If the access to these variables is not
9098 \begin_inset LatexCommand \index{atomic access}
9105 the processor needs more than one instruction for the access and could
9106 be interrupted while accessing the variable) the interrupt must disabled
9107 during the access to avoid inconsistent data.
9108 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9109 and should be protected by disabling interrupts.
9110 You're not automatically on the safe side if you use 8 bit variables though.
9111 We need an example here: f.e.
9112 on the 8051 the harmless looking
9113 \begin_inset Quotes srd
9123 \begin_inset Quotes sld
9132 \begin_inset Quotes srd
9142 \begin_inset Quotes sld
9145 from within an interrupt routine might get lost if the interrupt occurs
9148 \begin_inset Quotes sld
9153 counter\SpecialChar ~
9158 \begin_inset Quotes srd
9161 is not atomic on the 8051 even if
9165 is located in data memory.
9166 Bugs like these are hard to reproduce and can cause a lot of trouble.
9170 A special note here, int (16 bit) and long (32 bit) integer division
9171 \begin_inset LatexCommand \index{Division}
9176 \begin_inset LatexCommand \index{Multiplication}
9181 \begin_inset LatexCommand \index{Modulus}
9186 \begin_inset LatexCommand \index{Floating point support}
9190 operations are implemented using external support routines developed in
9192 If an interrupt service routine needs to do any of these operations then
9193 the support routines (as mentioned in a following section) will have to
9194 be recompiled using the
9207 \begin_inset LatexCommand \index{-\/-stack-auto}
9213 option and the source file will need to be compiled using the
9228 \begin_inset LatexCommand \index{-\/-int-long-reent}
9235 Calling other functions from an interrupt service routine is not recommended,
9236 avoid it if possible.
9237 Note that when some function is called from an interrupt service routine
9238 it should be preceded by a #pragma\SpecialChar ~
9240 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
9244 if it is not reentrant.
9245 Furthermore nonreentrant functions should not be called from the main program
9246 while the interrupt service routine might be active.
9252 \begin_inset LatexCommand \ref{sub:Overlaying}
9257 about Overlaying and section
9258 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
9263 about Functions using private banks.
9266 Enabling and Disabling Interrupts
9269 Critical Functions and Critical Statements
9272 A special keyword may be associated with a function declaring it as
9277 SDCC will generate code to disable all interrupts
9278 \begin_inset LatexCommand \index{interrupt}
9282 upon entry to a critical function and restore the interrupt enable to the
9283 previous state before returning.
9284 Nesting critical functions will need one additional byte on the stack
9285 \begin_inset LatexCommand \index{stack}
9295 \begin_inset LatexCommand \index{critical}
9320 The critical attribute maybe used with other attributes like
9330 may also be used to disable interrupts more locally:
9338 More than one statement could have been included in the block.
9341 Enabling and Disabling Interrupts directly
9345 \begin_inset LatexCommand \index{interrupt}
9349 can also be disabled and enabled directly (8051):
9367 On other architectures which have seperate opcodes for enabling and disabling
9368 interrupts you might want to make use of defines with inline assembly
9369 \begin_inset LatexCommand \index{Assembler routines}
9379 \begin_inset LatexCommand \index{\_asm}
9388 \begin_inset LatexCommand \index{\_endasm}
9397 #define SEI _asm\SpecialChar ~
9409 Note: it is sometimes sufficient to disable only a specific interrupt source
9411 a timer or serial interrupt by manipulating an
9414 \begin_inset LatexCommand \index{interrupt mask}
9421 Usually the time during which interrupts are disabled should be kept as
9428 \begin_inset LatexCommand \index{interrupt latency}
9432 (the time between the occurrence of the interrupt and the execution of
9433 the first code in the interrupt routine) and
9438 \begin_inset LatexCommand \index{interrupt jitter}
9442 (the difference between the shortest and the longest interrupt latency).
9443 These really are something different, f.e.
9444 a serial interrupt has to be served before its buffer overruns so it cares
9445 for the maximum interrupt latency, whereas it does not care about jitter.
9446 On a loudspeaker driven via a digital to analog converter which is fed
9447 by an interrupt a latency of a few milliseconds might be tolerable, whereas
9448 a much smaller jitter will be very audible.
9451 You can reenable interrupts within an interrupt routine and on some architecture
9452 s you can make use of two (or more) levels of
9454 interrupt priorities
9457 \begin_inset LatexCommand \index{interrupt priority}
9462 On architectures which don't support interrupt priorities these can be
9463 implemented by manipulating the interrupt mask and reenabling interrupts
9464 within the interrupt routine.
9465 Don't add complexity unless you have to.
9469 Functions using private banks
9470 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
9475 \begin_inset LatexCommand \index{bank}
9485 \begin_inset LatexCommand \index{using}
9491 attribute (which tells the compiler to use a register bank other than the
9492 default bank zero) should only be applied to
9495 \begin_inset LatexCommand \index{interrupt}
9501 functions (see note 1 below).
9502 This will in most circumstances make the generated ISR code more efficient
9503 since it will not have to save registers on the stack.
9510 attribute will have no effect on the generated code for a
9514 function (but may occasionally be useful anyway
9520 possible exception: if a function is called ONLY from 'interrupt' functions
9521 using a particular bank, it can be declared with the same 'using' attribute
9522 as the calling 'interrupt' functions.
9523 For instance, if you have several ISRs using bank one, and all of them
9524 call memcpy(), it might make sense to create a specialized version of memcpy()
9525 'using 1', since this would prevent the ISR from having to save bank zero
9526 to the stack on entry and switch to bank zero before calling the function
9533 (pending: I don't think this has been done yet)
9540 function using a non-zero bank will assume that it can trash that register
9541 bank, and will not save it.
9542 Since high-priority interrupts
9543 \begin_inset LatexCommand \index{interrupt priority}
9547 can interrupt low-priority ones on the 8051 and friends, this means that
9548 if a high-priority ISR
9552 a particular bank occurs while processing a low-priority ISR
9556 the same bank, terrible and bad things can happen.
9557 To prevent this, no single register bank should be
9561 by both a high priority and a low priority ISR.
9562 This is probably most easily done by having all high priority ISRs use
9563 one bank and all low priority ISRs use another.
9564 If you have an ISR which can change priority at runtime, you're on your
9565 own: I suggest using the default bank zero and taking the small performance
9569 It is most efficient if your ISR calls no other functions.
9570 If your ISR must call other functions, it is most efficient if those functions
9571 use the same bank as the ISR (see note 1 below); the next best is if the
9572 called functions use bank zero.
9573 It is very inefficient to call a function using a different, non-zero bank
9579 \begin_inset LatexCommand \label{sub:Startup-Code}
9584 \begin_inset LatexCommand \index{Startup code}
9591 MCS51/DS390 Startup Code
9594 The compiler inserts a call to the C routine
9596 _sdcc_external_startup()
9597 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
9606 at the start of the CODE area.
9607 This routine is in the runtime library
9608 \begin_inset LatexCommand \index{Runtime library}
9613 By default this routine returns 0, if this routine returns a non-zero value,
9614 the static & global variable initialization will be skipped and the function
9615 main will be invoked.
9616 Otherwise static & global variables will be initialized before the function
9620 _sdcc_external_startup()
9622 routine to your program to override the default if you need to setup hardware
9623 or perform some other critical operation prior to static & global variable
9625 On some mcs51 variants xdata has to be explicitly enabled before it can
9626 be accessed, this is the place to do it.
9627 See also the compiler option
9646 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9651 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9656 about MCS51-variants.
9662 The HC08 startup code follows the same scheme as the MCS51 startup code.
9668 On the Z80 the startup code is inserted by linking with crt0.o which is generated
9669 from sdcc/device/lib/z80/crt0.s.
9670 If you need a different startup code you can use the compiler option
9691 \begin_inset LatexCommand \index{-\/-no-std-crt0}
9695 and provide your own crt0.o.
9699 Inline Assembler Code
9700 \begin_inset LatexCommand \index{Assembler routines}
9707 A Step by Step Introduction
9710 Starting from a small snippet of c-code this example shows for the MCS51
9711 how to use inline assembly, access variables, a function parameter and
9712 an array in xdata memory.
9713 This is a buffer routine which should be optimized:
9719 unsigned char xdata at 0x7f00 buf[0x100];
9721 unsigned char head,tail;
9725 void to_buffer( unsigned char c )
9733 if( head != tail-1 )
9748 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
9749 then a corresponding buffer.asm file is generated.
9750 We define a new function
9754 in file buffer.c in which we cut and paste the generated code, removing
9755 unwanted comments and some ':'.
9757 \begin_inset Quotes sld
9761 \begin_inset Quotes srd
9765 \begin_inset Quotes sld
9769 \begin_inset Quotes srd
9772 to the beginning and the end of the function body:
9778 /* With a cut and paste from the .asm file, we have something to start with.
9783 The function is not yet OK! (registers aren't saved) */
9785 void to_buffer_asm( unsigned char c )
9794 \begin_inset LatexCommand \index{\_asm}
9808 ;buffer.c if( head != tail-1 )
9850 ;buffer.c buf[ head++ ] = c;
9946 The new file buffer.c should compile with only one warning about the unreferenced
9947 function argument 'c'.
9948 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
9955 unsigned char xdata at 0x7f00 buf[0x100];
9957 unsigned char head,tail;
9959 #define USE_ASSEMBLY
9963 #ifndef USE_ASSEMBLY
9965 void to_buffer( unsigned char c )
9973 if( head != tail-1 )
9993 void to_buffer( unsigned char c )
10001 c; // to avoid warning: unreferenced function argument
10008 \begin_inset LatexCommand \index{\_asm}
10022 ; save used registers here.
10033 ; If we were still using r2,r3 we would have to push them here.
10036 ; if( head != tail-1 )
10079 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
10103 ; buf[ head++ ] = c;
10114 a,dpl \SpecialChar ~
10121 ; dpl holds lower byte of function argument
10132 dpl,_head \SpecialChar ~
10135 ; buf is 0x100 byte aligned so head can be used directly
10177 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
10189 ; restore used registers here
10202 The inline assembler code can contain any valid code understood by the assembler
10203 , this includes any assembler directives and comment lines
10209 The assembler does not like some characters like ':' or ''' in comments.
10213 The compiler does not do any validation of the code within the
10216 \begin_inset LatexCommand \index{\_asm}
10224 Specifically it will not know which registers are used and thus register
10226 \begin_inset LatexCommand \index{push/pop}
10230 has to be done manually.
10234 It is strongly recommended that each assembly instruction (including labels)
10235 be placed in a separate line (as the example shows).
10249 \begin_inset LatexCommand \index{-\/-peep-asm}
10255 command line option is used, the inline assembler code will be passed through
10256 the peephole optimizer
10257 \begin_inset LatexCommand \index{Peephole optimizer}
10262 There are only a few (if any) cases where this option makes sense, it might
10263 cause some unexpected changes in the inline assembler code.
10264 Please go through the peephole optimizer rules defined in file
10268 carefully before using this option.
10272 \begin_inset LatexCommand \label{sub:Naked-Functions}
10277 \begin_inset LatexCommand \index{Naked functions}
10284 A special keyword may be associated with a function declaring it as
10287 \begin_inset LatexCommand \index{\_naked}
10298 function modifier attribute prevents the compiler from generating prologue
10299 \begin_inset LatexCommand \index{function prologue}
10304 \begin_inset LatexCommand \index{function epilogue}
10308 code for that function.
10309 This means that the user is entirely responsible for such things as saving
10310 any registers that may need to be preserved, selecting the proper register
10311 bank, generating the
10315 instruction at the end, etc.
10316 Practically, this means that the contents of the function must be written
10317 in inline assembler.
10318 This is particularly useful for interrupt functions, which can have a large
10319 (and often unnecessary) prologue/epilogue.
10320 For example, compare the code generated by these two functions:
10326 \begin_inset LatexCommand \index{volatile}
10330 data unsigned char counter;
10334 void simpleInterrupt(void) interrupt
10335 \begin_inset LatexCommand \index{interrupt}
10353 void nakedInterrupt(void) interrupt 2 _naked
10362 \begin_inset LatexCommand \index{\_asm}
10391 ; MUST explicitly include ret or reti in _naked function.
10398 \begin_inset LatexCommand \index{\_endasm}
10407 For an 8051 target, the generated simpleInterrupt looks like:
10548 whereas nakedInterrupt looks like:
10572 ; MUST explicitly include ret or reti in _naked function.
10575 The #pragma directive EXCLUDE
10576 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10580 allows a more fine grained control over pushing & popping
10581 \begin_inset LatexCommand \index{push/pop}
10588 While there is nothing preventing you from writing C code inside a _naked
10589 function, there are many ways to shoot yourself in the foot doing this,
10590 and it is recommended that you stick to inline assembler.
10593 Use of Labels within Inline Assembler
10596 SDCC allows the use of in-line assembler with a few restriction as regards
10598 In older versions of the compiler all labels defined within inline assembler
10607 where nnnn is a number less than 100 (which implies a limit of utmost 100
10608 inline assembler labels
10622 \begin_inset LatexCommand \index{\_asm}
10652 \begin_inset LatexCommand \index{\_endasm}
10659 Inline assembler code cannot reference any C-Labels, however it can reference
10661 \begin_inset LatexCommand \index{Labels}
10665 defined by the inline assembler, e.g.:
10690 ; some assembler code
10710 /* some more c code */
10712 clabel:\SpecialChar ~
10714 /* inline assembler cannot reference this label */
10726 $0003: ;label (can be reference by inline assembler only)
10738 /* some more c code */
10743 In other words inline assembly code can access labels defined in inline
10744 assembly within the scope of the function.
10745 The same goes the other way, ie.
10746 labels defines in inline assembly can not be accessed by C statements.
10749 Interfacing with Assembler Code
10750 \begin_inset LatexCommand \index{Assembler routines}
10757 Global Registers used for Parameter Passing
10758 \begin_inset LatexCommand \index{Parameter passing}
10765 The compiler always uses the global registers
10768 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
10773 \begin_inset LatexCommand \index{DPTR}
10778 \begin_inset LatexCommand \index{B (register)}
10787 \begin_inset LatexCommand \index{ACC}
10793 to pass the first parameter to a routine.
10794 The second parameter onwards is either allocated on the stack (for reentrant
10805 -stack-auto is used) or in data / xdata memory (depending on the memory
10810 Assembler Routine(non-reentrant
10811 \begin_inset LatexCommand \index{reentrant}
10816 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
10823 In the following example the function c_func calls an assembler routine
10824 asm_func, which takes two parameters
10825 \begin_inset LatexCommand \index{function parameter}
10834 extern int asm_func(unsigned char, unsigned char);
10838 int c_func (unsigned char i, unsigned char j)
10846 return asm_func(i,j);
10860 return c_func(10,9);
10865 The corresponding assembler function is:
10870 .globl _asm_func_PARM_2
10934 add a,_asm_func_PARM_2
10959 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
10976 Note here that the return values
10977 \begin_inset LatexCommand \index{return value}
10981 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
10983 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
10984 b' & 'acc' for four byte values.
10987 The parameter naming convention is _<function_name>_PARM_<n>, where n is
10988 the parameter number starting from 1, and counting from the left.
10989 The first parameter is passed in
10990 \begin_inset Quotes eld
10994 \begin_inset Quotes erd
10997 for One bye parameter,
10998 \begin_inset Quotes eld
11002 \begin_inset Quotes erd
11006 \begin_inset Quotes eld
11010 \begin_inset Quotes erd
11013 for three bytes and
11014 \begin_inset Quotes eld
11018 \begin_inset Quotes erd
11021 for four bytes, the variable name for the second parameter will be _<function_n
11026 Assemble the assembler routine with the following command:
11033 asx8051 -losg asmfunc.asm
11040 Then compile and link the assembler routine to the C source file with the
11048 sdcc cfunc.c asmfunc.rel
11051 Assembler Routine(reentrant
11052 \begin_inset LatexCommand \index{reentrant}
11057 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
11064 In this case the second parameter
11065 \begin_inset LatexCommand \index{function parameter}
11069 onwards will be passed on the stack, the parameters are pushed from right
11071 after the call the left most parameter will be on the top of the stack.
11072 Here is an example:
11077 extern int asm_func(unsigned char, unsigned char);
11081 int c_func (unsigned char i, unsigned char j) reentrant
11089 return asm_func(i,j);
11103 return c_func(10,9);
11108 The corresponding assembler routine is:
11214 The compiling and linking procedure remains the same, however note the extra
11215 entry & exit linkage required for the assembler code, _bp is the stack
11216 frame pointer and is used to compute the offset into the stack for parameters
11217 and local variables.
11221 \begin_inset LatexCommand \index{int (16 bit)}
11226 \begin_inset LatexCommand \index{long (32 bit)}
11233 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
11234 multiplication and modulus operations are implemented by support routines.
11235 These support routines are all developed in ANSI-C to facilitate porting
11236 to other MCUs, although some model specific assembler optimizations are
11238 The following files contain the described routines, all of them can be
11239 found in <installdir>/share/sdcc/lib.
11245 \begin_inset Tabular
11246 <lyxtabular version="3" rows="11" columns="2">
11248 <column alignment="center" valignment="top" leftline="true" width="0">
11249 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
11250 <row topline="true" bottomline="true">
11251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11272 <row topline="true">
11273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11286 16 bit multiplication
11290 <row topline="true">
11291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11304 signed 16 bit division (calls _divuint)
11308 <row topline="true">
11309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11322 unsigned 16 bit division
11326 <row topline="true">
11327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11340 signed 16 bit modulus (calls _moduint)
11344 <row topline="true">
11345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11358 unsigned 16 bit modulus
11362 <row topline="true">
11363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11376 32 bit multiplication
11380 <row topline="true">
11381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11394 signed 32 division (calls _divulong)
11398 <row topline="true">
11399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11412 unsigned 32 division
11416 <row topline="true">
11417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11430 signed 32 bit modulus (calls _modulong)
11434 <row topline="true" bottomline="true">
11435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11448 unsigned 32 bit modulus
11461 Since they are compiled as
11466 \begin_inset LatexCommand \index{reentrant}
11471 \begin_inset LatexCommand \index{interrupt}
11475 service routines should not do any of the above operations.
11476 If this is unavoidable then the above routines will need to be compiled
11490 \begin_inset LatexCommand \index{-\/-stack-auto}
11496 option, after which the source program will have to be compiled with
11509 \begin_inset LatexCommand \index{-\/-int-long-reent}
11516 Notice that you don't have to call this routines directly.
11517 The compiler will use them automatically every time an integer operation
11521 Floating Point Support
11522 \begin_inset LatexCommand \index{Floating point support}
11529 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
11530 floating point support routines are derived from gcc's floatlib.c and consist
11531 of the following routines:
11539 \begin_inset Tabular
11540 <lyxtabular version="3" rows="17" columns="2">
11542 <column alignment="center" valignment="top" leftline="true" width="0">
11543 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
11544 <row topline="true" bottomline="true">
11545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11571 <row topline="true">
11572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11603 add floating point numbers
11607 <row topline="true">
11608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11639 subtract floating point numbers
11643 <row topline="true">
11644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11675 divide floating point numbers
11679 <row topline="true">
11680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11711 multiply floating point numbers
11715 <row topline="true">
11716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11747 convert floating point to unsigned char
11751 <row topline="true">
11752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11783 convert floating point to signed char
11787 <row topline="true">
11788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11819 convert floating point to unsigned int
11823 <row topline="true">
11824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11855 convert floating point to signed int
11859 <row topline="true">
11860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11900 convert floating point to unsigned long
11904 <row topline="true">
11905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11936 convert floating point to signed long
11940 <row topline="true">
11941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11972 convert unsigned char to floating point
11976 <row topline="true">
11977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12008 convert char to floating point number
12012 <row topline="true">
12013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12044 convert unsigned int to floating point
12048 <row topline="true">
12049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12080 convert int to floating point numbers
12084 <row topline="true">
12085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12116 convert unsigned long to floating point number
12120 <row topline="true" bottomline="true">
12121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12152 convert long to floating point number
12165 Note if all these routines are used simultaneously the data space might
12167 For serious floating point usage it is strongly recommended that the large
12169 Also notice that you don't have to call this routines directly.
12170 The compiler will use them automatically every time a floating point operation
12174 MCS51 Memory Models
12175 \begin_inset LatexCommand \index{Memory model}
12180 \begin_inset LatexCommand \index{MCS51 memory}
12187 SDCC allows two memory models for MCS51 code,
12196 Modules compiled with different memory models should
12200 be combined together or the results would be unpredictable.
12201 The library routines supplied with the compiler are compiled as both small
12203 The compiled library modules are contained in separate directories as small
12204 and large so that you can link to either set.
12208 When the large model is used all variables declared without a storage class
12209 will be allocated into the external ram, this includes all parameters and
12210 local variables (for non-reentrant
12211 \begin_inset LatexCommand \index{reentrant}
12216 When the small model is used variables without storage class are allocated
12217 in the internal ram.
12220 Judicious usage of the processor specific storage classes
12221 \begin_inset LatexCommand \index{Storage class}
12225 and the 'reentrant' function type will yield much more efficient code,
12226 than using the large model.
12227 Several optimizations are disabled when the program is compiled using the
12228 large model, it is therefore strongly recommended that the small model
12229 be used unless absolutely required.
12232 DS390 Memory Models
12233 \begin_inset LatexCommand \index{Memory model}
12238 \begin_inset LatexCommand \index{DS390 memory model}
12245 The only model supported is Flat 24
12246 \begin_inset LatexCommand \index{Flat 24 (memory model)}
12251 This generates code for the 24 bit contiguous addressing mode of the Dallas
12253 In this mode, up to four meg of external RAM or code space can be directly
12255 See the data sheets at www.dalsemi.com for further information on this part.
12259 Note that the compiler does not generate any code to place the processor
12260 into 24 bitmode (although
12264 in the ds390 libraries will do that for you).
12270 \begin_inset LatexCommand \index{Tinibios (DS390)}
12274 , the boot loader or similar code must ensure that the processor is in 24
12275 bit contiguous addressing mode before calling the SDCC startup code.
12293 option, variables will by default be placed into the XDATA segment.
12298 Segments may be placed anywhere in the 4 meg address space using the usual
12310 Note that if any segments are located above 64K, the -r flag must be passed
12311 to the linker to generate the proper segment relocations, and the Intel
12312 HEX output format must be used.
12313 The -r flag can be passed to the linker by using the option
12317 on the SDCC command line.
12318 However, currently the linker can not handle code segments > 64k.
12322 \begin_inset LatexCommand \index{Pragmas}
12329 SDCC supports the following #pragma directives.
12333 \begin_inset LatexCommand \index{\#pragma SAVE}
12337 - this will save all current options to the SAVE/RESTORE stack.
12342 \begin_inset LatexCommand \index{\#pragma RESTORE}
12346 - will restore saved options from the last save.
12347 SAVEs & RESTOREs can be nested.
12348 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
12349 RESTORE pulls current options from the stack.
12354 \begin_inset LatexCommand \index{\#pragma NOGCSE}
12358 - will stop global common subexpression elimination.
12362 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
12366 - will stop loop induction optimizations.
12370 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
12374 - will not generate code for boundary value checking, when switch statements
12375 are turned into jump-tables (dangerous).
12376 For more details see section
12377 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
12385 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
12389 - the compiler will not overlay the parameters and local variables of a
12394 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
12398 - the compiler will not warn you anymore for obvious mistakes, you'r on
12403 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
12407 - Will not do loop reversal optimization
12411 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
12415 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
12417 \begin_inset LatexCommand \index{push/pop}
12421 instruction in ISR function (using interrupt
12422 \begin_inset LatexCommand \index{interrupt}
12427 The directive should be placed immediately before the ISR function definition
12428 and it affects ALL ISR functions following it.
12429 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
12430 EXCLUDE\SpecialChar ~
12432 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
12440 \begin_inset LatexCommand \index{\#pragma NOIV}
12444 - Do not generate interrupt vector table entries for all ISR functions
12445 defined after the pragma.
12446 This is useful in cases where the interrupt vector table must be defined
12447 manually, or when there is a secondary, manually defined interrupt vector
12449 for the autovector feature of the Cypress EZ-USB FX2).
12450 More elegantly this can be achieved by obmitting the optional interrupt
12451 number after the interrupt keyword, see section
12452 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
12461 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
12466 \begin_inset LatexCommand \index{function prologue}
12470 function1[,function2[,function3...]] - The compiler by default uses a caller
12471 saves convention for register saving across function calls, however this
12472 can cause unnecessary register pushing & popping when calling small functions
12473 from larger functions.
12474 This option can be used to switch off the register saving convention for
12475 the function names specified.
12476 The compiler will not save registers when calling these functions, extra
12477 code need to be manually inserted at the entry & exit for these functions
12478 to save & restore the registers used by these functions, this can SUBSTANTIALLY
12479 reduce code & improve run time performance of the generated code.
12480 In the future the compiler (with inter procedural analysis) may be able
12481 to determine the appropriate scheme to use for each function call.
12492 -callee-saves command line option is used, the function names specified
12493 in #pragma\SpecialChar ~
12495 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
12499 is appended to the list of functions specified in the command line.
12503 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
12507 (+ | -) - switch _asm _endasm block preprocessing on / off.
12511 The pragma's are intended to be used to turn-on or off certain optimizations
12512 which might cause the compiler to generate extra stack / data space to
12513 store compiler generated temporary variables.
12514 This usually happens in large functions.
12515 Pragma directives should be used as shown in the following example, they
12516 are used to control options & optimizations for a given function; pragmas
12517 should be placed before and/or after a function, placing pragma's inside
12518 a function body could have unpredictable results.
12524 \begin_inset LatexCommand \index{\#pragma SAVE}
12535 /* save the current settings */
12538 \begin_inset LatexCommand \index{\#pragma NOGCSE}
12547 /* turnoff global subexpression elimination */
12549 #pragma NOINDUCTION
12550 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
12554 /* turn off induction optimizations */
12577 \begin_inset LatexCommand \index{\#pragma RESTORE}
12581 /* turn the optimizations back on */
12584 The compiler will generate a warning message when extra space is allocated.
12585 It is strongly recommended that the SAVE and RESTORE pragma's be used when
12586 changing options for a function.
12589 Defines Created by the Compiler
12590 \begin_inset LatexCommand \index{Defines created by the compiler}
12597 The compiler creates the following #defines
12598 \begin_inset LatexCommand \index{\#defines}
12608 \begin_inset Tabular
12609 <lyxtabular version="3" rows="10" columns="2">
12611 <column alignment="center" valignment="top" leftline="true" width="0">
12612 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12613 <row topline="true" bottomline="true">
12614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12635 <row topline="true">
12636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12642 \begin_inset LatexCommand \index{SDCC}
12649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12654 this Symbol is always defined
12658 <row topline="true">
12659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12665 \begin_inset LatexCommand \index{SDCC\_mcs51}
12670 \begin_inset LatexCommand \index{SDCC\_ds390}
12675 \begin_inset LatexCommand \index{SDCC\_z80}
12682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12687 depending on the model used (e.g.: -mds390
12691 <row topline="true">
12692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12698 \begin_inset LatexCommand \index{\_\_mcs51}
12703 \begin_inset LatexCommand \index{\_\_ds390}
12708 \begin_inset LatexCommand \index{\_\_hc08}
12713 \begin_inset LatexCommand \index{\_\_z80}
12720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12725 depending on the model used (e.g.
12730 <row topline="true">
12731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12737 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
12744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12767 <row topline="true">
12768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12774 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
12781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12804 <row topline="true">
12805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12811 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
12818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12841 <row topline="true">
12842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12848 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
12855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12878 <row topline="true">
12879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12885 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
12892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12905 <row topline="true" bottomline="true">
12906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12912 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
12919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12941 Debugging with SDCDB
12942 \begin_inset LatexCommand \index{sdcdb}
12949 SDCC is distributed with a source level debugger
12950 \begin_inset LatexCommand \index{Debugger}
12955 The debugger uses a command line interface, the command repertoire of the
12956 debugger has been kept as close to gdb
12957 \begin_inset LatexCommand \index{gdb}
12961 (the GNU debugger) as possible.
12962 The configuration and build process is part of the standard compiler installati
12963 on, which also builds and installs the debugger in the target directory
12964 specified during configuration.
12965 The debugger allows you debug BOTH at the C source and at the ASM source
12967 Sdcdb is available on Unix platforms only.
12970 Compiling for Debugging
12973 The \SpecialChar \-
12975 debug option must be specified for all files for which debug information
12976 is to be generated.
12977 The complier generates a .adb file for each of these files.
12978 The linker creates the .cdb file from the .adb files and the address information.
12979 This .cdb is used by the debugger.
12982 How the Debugger Works
12995 -debug option is specified the compiler generates extra symbol information
12996 some of which are put into the assembler source and some are put into the
12998 Then the linker creates the .cdb file from the individual .adb files with
12999 the address information for the symbols.
13000 The debugger reads the symbolic information generated by the compiler &
13001 the address information generated by the linker.
13002 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13003 execution is controlled by the debugger.
13004 When a command is issued for the debugger, it translates it into appropriate
13005 commands for the simulator.
13008 Starting the Debugger
13011 The debugger can be started using the following command line.
13012 (Assume the file you are debugging has the file name foo).
13026 The debugger will look for the following files.
13029 foo.c - the source file.
13032 foo.cdb - the debugger symbol information file.
13035 foo.ihx - the Intel hex format
13036 \begin_inset LatexCommand \index{Intel hex format}
13043 Command Line Options.
13056 -directory=<source file directory> this option can used to specify the directory
13058 The debugger will look into the directory list specified for source, cdb
13060 The items in the directory list must be separated by ':', e.g.
13061 if the source files can be in the directories /home/src1 and /home/src2,
13072 -directory option should be -
13082 -directory=/home/src1:/home/src2.
13083 Note there can be no spaces in the option.
13087 -cd <directory> - change to the <directory>.
13090 -fullname - used by GUI front ends.
13093 -cpu <cpu-type> - this argument is passed to the simulator please see the
13094 simulator docs for details.
13097 -X <Clock frequency > this options is passed to the simulator please see
13098 the simulator docs for details.
13101 -s <serial port file> passed to simulator see the simulator docs for details.
13104 -S <serial in,out> passed to simulator see the simulator docs for details.
13110 As mentioned earlier the command interface for the debugger has been deliberatel
13111 y kept as close the GNU debugger gdb, as possible.
13112 This will help the integration with existing graphical user interfaces
13113 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
13114 If you use a graphical user interface for the debugger you can skip the
13116 \layout Subsubsection*
13118 break [line | file:line | function | file:function]
13121 Set breakpoint at specified line or function:
13130 sdcdb>break foo.c:100
13132 sdcdb>break funcfoo
13134 sdcdb>break foo.c:funcfoo
13135 \layout Subsubsection*
13137 clear [line | file:line | function | file:function ]
13140 Clear breakpoint at specified line or function:
13149 sdcdb>clear foo.c:100
13151 sdcdb>clear funcfoo
13153 sdcdb>clear foo.c:funcfoo
13154 \layout Subsubsection*
13159 Continue program being debugged, after breakpoint.
13160 \layout Subsubsection*
13165 Execute till the end of the current function.
13166 \layout Subsubsection*
13171 Delete breakpoint number 'n'.
13172 If used without any option clear ALL user defined break points.
13173 \layout Subsubsection*
13175 info [break | stack | frame | registers ]
13178 info break - list all breakpoints
13181 info stack - show the function call stack.
13184 info frame - show information about the current execution frame.
13187 info registers - show content of all registers.
13188 \layout Subsubsection*
13193 Step program until it reaches a different source line.
13194 \layout Subsubsection*
13199 Step program, proceeding through subroutine calls.
13200 \layout Subsubsection*
13205 Start debugged program.
13206 \layout Subsubsection*
13211 Print type information of the variable.
13212 \layout Subsubsection*
13217 print value of variable.
13218 \layout Subsubsection*
13223 load the given file name.
13224 Note this is an alternate method of loading file for debugging.
13225 \layout Subsubsection*
13230 print information about current frame.
13231 \layout Subsubsection*
13236 Toggle between C source & assembly source.
13237 \layout Subsubsection*
13239 ! simulator command
13242 Send the string following '!' to the simulator, the simulator response is
13244 Note the debugger does not interpret the command being sent to the simulator,
13245 so if a command like 'go' is sent the debugger can loose its execution
13246 context and may display incorrect values.
13247 \layout Subsubsection*
13254 My name is Bobby Brown"
13257 Interfacing with XEmacs
13258 \begin_inset LatexCommand \index{XEmacs}
13263 \begin_inset LatexCommand \index{Emacs}
13270 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
13271 sdcdb.el and sdcdbsrc.el.
13272 These two files can be found in the $(prefix)/bin directory after the installat
13274 These files need to be loaded into XEmacs for the interface to work.
13275 This can be done at XEmacs startup time by inserting the following into
13276 your '.xemacs' file (which can be found in your HOME directory):
13282 (load-file sdcdbsrc.el)
13288 .xemacs is a lisp file so the () around the command is REQUIRED.
13289 The files can also be loaded dynamically while XEmacs is running, set the
13290 environment variable 'EMACSLOADPATH' to the installation bin directory
13291 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
13292 To start the interface enter the following command:
13306 You will prompted to enter the file name to be debugged.
13311 The command line options that are passed to the simulator directly are bound
13312 to default values in the file sdcdbsrc.el.
13313 The variables are listed below, these values maybe changed as required.
13316 sdcdbsrc-cpu-type '51
13319 sdcdbsrc-frequency '11059200
13322 sdcdbsrc-serial nil
13325 The following is a list of key mapping for the debugger interface.
13333 ;; Current Listing ::
13335 ;;key\SpecialChar ~
13350 binding\SpecialChar ~
13374 ;;---\SpecialChar ~
13389 ------\SpecialChar ~
13429 sdcdb-next-from-src\SpecialChar ~
13455 sdcdb-back-from-src\SpecialChar ~
13481 sdcdb-cont-from-src\SpecialChar ~
13491 SDCDB continue command
13507 sdcdb-step-from-src\SpecialChar ~
13533 sdcdb-whatis-c-sexp\SpecialChar ~
13543 SDCDB ptypecommand for data at
13607 sdcdbsrc-delete\SpecialChar ~
13621 SDCDB Delete all breakpoints if no arg
13669 given or delete arg (C-u arg x)
13685 sdcdbsrc-frame\SpecialChar ~
13700 SDCDB Display current frame if no arg,
13749 given or display frame arg
13814 sdcdbsrc-goto-sdcdb\SpecialChar ~
13824 Goto the SDCDB output buffer
13840 sdcdb-print-c-sexp\SpecialChar ~
13851 SDCDB print command for data at
13915 sdcdbsrc-goto-sdcdb\SpecialChar ~
13925 Goto the SDCDB output buffer
13941 sdcdbsrc-mode\SpecialChar ~
13957 Toggles Sdcdbsrc mode (turns it off)
13961 ;; C-c C-f\SpecialChar ~
13969 sdcdb-finish-from-src\SpecialChar ~
13977 SDCDB finish command
13981 ;; C-x SPC\SpecialChar ~
13989 sdcdb-break\SpecialChar ~
14007 Set break for line with point
14009 ;; ESC t\SpecialChar ~
14019 sdcdbsrc-mode\SpecialChar ~
14035 Toggle Sdcdbsrc mode
14037 ;; ESC m\SpecialChar ~
14047 sdcdbsrc-srcmode\SpecialChar ~
14069 Here are a few guidelines that will help the compiler generate more efficient
14070 code, some of the tips are specific to this compiler others are generally
14071 good programming practice.
14074 Use the smallest data type to represent your data-value.
14075 If it is known in advance that the value is going to be less than 256 then
14076 use an 'unsigned char' instead of a 'short' or 'int'.
14079 Use unsigned when it is known in advance that the value is not going to
14081 This helps especially if you are doing division or multiplication.
14084 NEVER jump into a LOOP.
14087 Declare the variables to be local whenever possible, especially loop control
14088 variables (induction).
14091 Since the compiler does not always do implicit integral promotion, the programme
14092 r should do an explicit cast when integral promotion is required.
14095 Reducing the size of division, multiplication & modulus operations can reduce
14096 code size substantially.
14097 Take the following code for example.
14103 foobar(unsigned int p1, unsigned char ch)
14111 unsigned char ch1 = p1 % ch ;
14122 For the modulus operation the variable ch will be promoted to unsigned int
14123 first then the modulus operation will be performed (this will lead to a
14124 call to support routine _moduint()), and the result will be casted to a
14126 If the code is changed to
14131 foobar(unsigned int p1, unsigned char ch)
14139 unsigned char ch1 = (unsigned char)p1 % ch ;
14150 It would substantially reduce the code generated (future versions of the
14151 compiler will be smart enough to detect such optimization opportunities).
14155 Have a look at the assembly listing to get a
14156 \begin_inset Quotes sld
14160 \begin_inset Quotes srd
14163 for the code generation.
14166 Notes on MCS51 memory
14167 \begin_inset LatexCommand \index{MCS51 memory}
14174 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
14175 RAM memory which is structured as follows
14179 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
14182 - Bytes 20-2F - 16 bytes to hold 128 bit
14183 \begin_inset LatexCommand \index{bit}
14189 - Bytes 30-7F - 80 bytes for general purpose use.
14194 Additionally some members of the MCS51 family may have up to 128 bytes of
14195 additional, indirectly addressable, internal RAM memory (
14200 \begin_inset LatexCommand \index{idata}
14205 Furthermore, some chips may have some built in external memory (
14210 \begin_inset LatexCommand \index{xdata}
14214 ) which should not be confused with the internal, directly addressable RAM
14220 \begin_inset LatexCommand \index{data}
14225 Sometimes this built in
14229 memory has to be activated before using it (you can probably find this
14230 information on the datasheet of the microcontroller your are using, see
14232 \begin_inset LatexCommand \ref{sub:Startup-Code}
14240 Normally SDCC will only use the first bank
14241 \begin_inset LatexCommand \index{bank}
14245 of registers (register bank 0), but it is possible to specify that other
14246 banks of registers should be used in interrupt
14247 \begin_inset LatexCommand \index{interrupt}
14252 By default, the compiler will place the stack after the last byte of allocated
14253 memory for variables.
14254 For example, if the first 2 banks of registers are used, and only four
14259 variables, it will position the base of the internal stack at address 20
14261 This implies that as the stack
14262 \begin_inset LatexCommand \index{stack}
14266 grows, it will use up the remaining register banks, and the 16 bytes used
14267 by the 128 bit variables, and 80 bytes for general purpose use.
14268 If any bit variables are used, the data variables will be placed after
14269 the byte holding the last bit variable.
14270 For example, if register banks 0 and 1 are used, and there are 9 bit variables
14275 variables will be placed starting at address 0x22.
14287 \begin_inset LatexCommand \index{-\/-data-loc}
14291 to specify the start address of the
14305 -iram-size to specify the size of the total internal RAM (
14317 By default the 8051 linker will place the stack after the last byte of data
14330 \begin_inset LatexCommand \index{-\/-stack-loc}
14334 allows you to specify the start of the stack, i.e.
14335 you could start it after any data in the general purpose area.
14336 If your microcontroller has additional indirectly addressable internal
14341 ) you can place the stack on it.
14342 You may also need to use -
14353 \begin_inset LatexCommand \index{-\/-data-loc}
14357 to set the start address of the external RAM (
14372 \begin_inset LatexCommand \index{-\/-data-loc}
14376 to specify its size.
14377 Same goes for the code memory, using -
14388 \begin_inset LatexCommand \index{-\/-data-loc}
14403 \begin_inset LatexCommand \index{-\/-data-loc}
14408 If in doubt, don't specify any options and see if the resulting memory
14409 layout is appropriate, then you can adjust it.
14412 The 8051 linker generates two files with memory allocation information.
14413 The first, with extension .map shows all the variables and segments.
14414 The second with extension .mem shows the final memory layout.
14415 The linker will complaint either if memory segments overlap, there is not
14416 enough memory, or there is not enough space for stack.
14417 If you get any linking warnings and/or errors related to stack or segments
14418 allocation, take a look at either the .map or .mem files to find out what
14420 The .mem file may even suggest a solution to the problem.
14424 \begin_inset LatexCommand \index{Tools}
14428 included in the distribution
14432 \begin_inset Tabular
14433 <lyxtabular version="3" rows="12" columns="3">
14435 <column alignment="center" valignment="top" leftline="true" width="0pt">
14436 <column alignment="center" valignment="top" leftline="true" width="0pt">
14437 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
14438 <row topline="true" bottomline="true">
14439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14464 <row topline="true">
14465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14478 Simulator for various architectures
14481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14490 <row topline="true">
14491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14504 header file conversion
14507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14512 sdcc/support/scripts
14516 <row topline="true">
14517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14530 header file conversion
14533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14538 sdcc/support/scripts
14542 <row topline="true">
14543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14577 <row topline="true">
14578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14612 <row topline="true">
14613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14647 <row topline="true">
14648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14682 <row topline="true">
14683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14717 <row topline="true">
14718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14752 <row topline="true">
14753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14787 <row topline="true" bottomline="true">
14788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14831 Related open source tools
14832 \begin_inset LatexCommand \index{Related tools}
14840 \begin_inset Tabular
14841 <lyxtabular version="3" rows="9" columns="3">
14843 <column alignment="center" valignment="top" leftline="true" width="0pt">
14844 <column alignment="block" valignment="top" leftline="true" width="30line%">
14845 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
14846 <row topline="true" bottomline="true">
14847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14872 <row topline="true">
14873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14879 \begin_inset LatexCommand \index{gpsim}
14886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14900 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
14908 <row topline="true">
14909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14931 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
14939 <row topline="true">
14940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14946 \begin_inset LatexCommand \index{indent}
14953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14958 Formats C source - Master of the white spaces
14961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14967 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
14975 <row topline="true">
14976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14982 \begin_inset LatexCommand \index{srecord}
14989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14994 Object file conversion, checksumming, ...
14997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15003 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
15011 <row topline="true">
15012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15018 \begin_inset LatexCommand \index{objdump}
15025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15030 Object file conversion, ...
15033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15038 Part of binutils (should be there anyway)
15042 <row topline="true">
15043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15049 \begin_inset LatexCommand \index{doxygen}
15056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15061 Source code documentation system
15064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15070 \begin_inset LatexCommand \url{http://www.doxygen.org}
15078 <row topline="true">
15079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15085 \begin_inset LatexCommand \index{splint}
15092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15097 Statically checks c sources
15100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15106 \begin_inset LatexCommand \url{http://www.splint.org}
15114 <row topline="true" bottomline="true">
15115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15121 \begin_inset LatexCommand \index{ddd}
15128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15133 Debugger, serves nicely as GUI to sdcdb
15134 \begin_inset LatexCommand \index{sdcdb}
15141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15147 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
15164 Related documentation / recommended reading
15168 \begin_inset Tabular
15169 <lyxtabular version="3" rows="5" columns="3">
15171 <column alignment="center" valignment="top" leftline="true" width="0pt">
15172 <column alignment="block" valignment="top" leftline="true" width="30line%">
15173 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
15174 <row topline="true" bottomline="true">
15175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15200 <row topline="true">
15201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15224 \begin_inset LatexCommand \index{C Reference card}
15231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15237 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
15245 <row topline="true">
15246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15261 Advanced Compiler Design and Implementation
15264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15273 <row topline="true">
15274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15279 test_suite_spec.pdf
15282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15287 sdcc regression test
15288 \begin_inset LatexCommand \index{Regression test}
15295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15304 <row topline="true" bottomline="true">
15305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15336 sdcc internal documentation
15339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15358 \begin_inset LatexCommand \index{Support}
15365 SDCC has grown to be a large project.
15366 The compiler alone (without the preprocessor, assembler and linker) is
15367 well over 100,000 lines of code (blank stripped).
15368 The open source nature of this project is a key to its continued growth
15370 You gain the benefit and support of many active software developers and
15372 Is SDCC perfect? No, that's why we need your help.
15373 The developers take pride in fixing reported bugs.
15374 You can help by reporting the bugs and helping other SDCC users.
15375 There are lots of ways to contribute, and we encourage you to take part
15376 in making SDCC a great software package.
15380 The SDCC project is hosted on the SDCC sourceforge site at
15381 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
15386 You'll find the complete set of mailing lists
15387 \begin_inset LatexCommand \index{Mailing list}
15391 , forums, bug reporting system, patch submission
15392 \begin_inset LatexCommand \index{Patch submission}
15397 \begin_inset LatexCommand \index{download}
15401 area and cvs code repository
15402 \begin_inset LatexCommand \index{cvs code repository}
15410 \begin_inset LatexCommand \index{Bug reporting}
15415 \begin_inset LatexCommand \index{Reporting bugs}
15422 The recommended way of reporting bugs is using the infrastructure of the
15424 You can follow the status of bug reports there and have an overview about
15428 Bug reports are automatically forwarded to the developer mailing list and
15429 will be fixed ASAP.
15430 When reporting a bug, it is very useful to include a small test program
15431 (the smaller the better) which reproduces the problem.
15432 If you can isolate the problem by looking at the generated assembly code,
15433 this can be very helpful.
15434 Compiling your program with the -
15445 \begin_inset LatexCommand \index{-\/-dumpall}
15449 option can sometimes be useful in locating optimization problems.
15450 When reporting a bug please maker sure you:
15453 Attach the code you are compiling with SDCC.
15457 Specify the exact command you use to run SDCC, or attach your Makefile.
15461 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15466 Provide an exact copy of any error message or incorrect output.
15470 Put something meaningful in the subject of your message.
15473 Please attempt to include these 5 important parts, as applicable, in all
15474 requests for support or when reporting any problems or bugs with SDCC.
15475 Though this will make your message lengthy, it will greatly improve your
15476 chance that SDCC users and developers will be able to help you.
15477 Some SDCC developers are frustrated by bug reports without code provided
15478 that they can use to reproduce and ultimately fix the problem, so please
15479 be sure to provide sample code if you are reporting a bug!
15482 Please have a short check that you are using a recent version of SDCC and
15483 the bug is not yet known.
15484 This is the link for reporting bugs:
15485 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15492 Requesting Features
15493 \begin_inset LatexCommand \label{sub:Requesting-Features}
15498 \begin_inset LatexCommand \index{Feature request}
15503 \begin_inset LatexCommand \index{Requesting features}
15510 Like bug reports feature requests are forwarded to the developer mailing
15512 This is the link for requesting features:
15513 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15523 These links should take you directly to the
15524 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15534 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15535 automated messages (mid 2003)
15539 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15543 , lists and forums are archived so if you are lucky someone already had
15548 \begin_inset LatexCommand \index{Changelog}
15555 You can follow the status of the cvs version
15556 \begin_inset LatexCommand \index{version}
15560 of SDCC by watching the file
15561 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15565 in the cvs-repository.
15569 \begin_inset LatexCommand \index{Release policy}
15576 Historically there often were long delays between official releases and
15577 the sourceforge download area tends to get not updated at all.
15578 Current excuses might refer to problems with live range analysis, but if
15579 this is fixed, the next problem rising is that another excuse will have
15581 Kidding aside, we have to get better there! On the other hand there are
15582 daily snapshots available at
15583 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15587 , and you can always built the very last version (hopefully with many bugs
15588 fixed, and features added) from the source code available at
15589 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15597 \begin_inset LatexCommand \index{Examples}
15604 You'll find some small examples in the directory
15606 sdcc/device/examples/.
15609 More examples and libraries are available at
15611 The SDCC Open Knowledge Resource
15612 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
15619 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
15626 I did insert a reference to Paul's web site here although it seems rather
15627 dedicated to a specific 8032 board (I think it's okay because it f.e.
15628 shows LCD/Harddisc interface and has a free 8051 monitor.
15629 Independent 8032 board vendors face hard competition of heavily subsidized
15630 development boards anyway).
15633 Maybe we should include some links to real world applications.
15634 Preferably pointer to pointers (one for each architecture) so this stays
15639 \begin_inset LatexCommand \index{Quality control}
15646 The compiler is passed through nightly compile and build checks.
15652 \begin_inset LatexCommand \index{Regression test}
15656 check that SDCC itself compiles flawlessly on several platforms and checks
15657 the quality of the code generated by SDCC by running the code through simulator
15659 There is a separate document
15662 \begin_inset LatexCommand \index{Test suite}
15671 You'll find the test code in the directory
15673 sdcc/support/regression
15676 You can run these tests manually by running
15680 in this directory (or f.e.
15685 if you don't want to run the complete tests).
15686 The test code might also be interesting if you want to look for examples
15687 \begin_inset LatexCommand \index{Examples}
15691 checking corner cases of SDCC or if you plan to submit patches
15692 \begin_inset LatexCommand \index{Patch submission}
15699 The pic port uses a different set of regression tests, you'll find them
15702 sdcc/src/regression
15707 SDCC Technical Data
15711 \begin_inset LatexCommand \index{Optimizations}
15718 SDCC performs a host of standard optimizations in addition to some MCU specific
15723 Sub-expression Elimination
15724 \begin_inset LatexCommand \index{Subexpression elimination}
15731 The compiler does local and global common subexpression elimination, e.g.:
15742 will be translated to
15754 Some subexpressions are not as obvious as the above example, e.g.:
15764 In this case the address arithmetic a->b[i] will be computed only once;
15765 the equivalent code in C would be.
15777 The compiler will try to keep these temporary variables in registers.
15780 Dead-Code Elimination
15781 \begin_inset LatexCommand \index{Dead-code elimination}
15802 i = 1; \SpecialChar ~
15811 global = 1;\SpecialChar ~
15824 global = 3;\SpecialChar ~
15853 \begin_inset LatexCommand \index{Copy propagation}
15909 Note: the dead stores created by this copy propagation will be eliminated
15910 by dead-code elimination.
15914 \begin_inset LatexCommand \index{Loop optimization}
15921 Two types of loop optimizations are done by SDCC loop invariant lifting
15922 and strength reduction of loop induction variables.
15923 In addition to the strength reduction the optimizer marks the induction
15924 variables and the register allocator tries to keep the induction variables
15925 in registers for the duration of the loop.
15926 Because of this preference of the register allocator
15927 \begin_inset LatexCommand \index{Register allocation}
15931 , loop induction optimization causes an increase in register pressure, which
15932 may cause unwanted spilling of other temporary variables into the stack
15933 \begin_inset LatexCommand \index{stack}
15938 The compiler will generate a warning message when it is forced to allocate
15939 extra space either on the stack or data space.
15940 If this extra space allocation is undesirable then induction optimization
15941 can be eliminated either for the entire source file (with -
15951 -noinduction option) or for a given function only using #pragma\SpecialChar ~
15953 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
15966 for (i = 0 ; i < 100 ; i ++)
15982 for (i = 0; i < 100; i++)
15991 As mentioned previously some loop invariants are not as apparent, all static
15992 address computations are also moved out of the loop.
15997 \begin_inset LatexCommand \index{Strength reduction}
16001 , this optimization substitutes an expression by a cheaper expression:
16006 for (i=0;i < 100; i++)
16024 for (i=0;i< 100;i++) {
16030 ar[itemp1] = itemp2;
16047 The more expensive multiplication
16048 \begin_inset LatexCommand \index{Multiplication}
16052 is changed to a less expensive addition.
16056 \begin_inset LatexCommand \index{Loop reversing}
16063 This optimization is done to reduce the overhead of checking loop boundaries
16064 for every iteration.
16065 Some simple loops can be reversed and implemented using a
16066 \begin_inset Quotes eld
16069 decrement and jump if not zero
16070 \begin_inset Quotes erd
16074 SDCC checks for the following criterion to determine if a loop is reversible
16075 (note: more sophisticated compilers use data-dependency analysis to make
16076 this determination, SDCC uses a more simple minded analysis).
16079 The 'for' loop is of the form
16085 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
16095 The <for body> does not contain
16096 \begin_inset Quotes eld
16100 \begin_inset Quotes erd
16104 \begin_inset Quotes erd
16110 All goto's are contained within the loop.
16113 No function calls within the loop.
16116 The loop control variable <sym> is not assigned any value within the loop
16119 The loop control variable does NOT participate in any arithmetic operation
16123 There are NO switch statements in the loop.
16126 Algebraic Simplifications
16129 SDCC does numerous algebraic simplifications, the following is a small sub-set
16130 of these optimizations.
16135 i = j + 0 ; /* changed to */ i = j;
16137 i /= 2;\SpecialChar ~
16141 /* changed to */ i >>= 1;
16143 i = j - j ; /* changed to */ i = 0;
16145 i = j / 1 ; /* changed to */ i = j;
16148 Note the subexpressions
16149 \begin_inset LatexCommand \index{Subexpression}
16153 given above are generally introduced by macro expansions or as a result
16154 of copy/constant propagation.
16157 'switch' Statements
16158 \begin_inset LatexCommand \label{sub:'switch'-Statements}
16163 \begin_inset LatexCommand \index{switch statement}
16170 SDCC changes switch statements to jump tables
16171 \begin_inset LatexCommand \index{jump tables}
16175 when the following conditions are true.
16179 The case labels are in numerical sequence, the labels need not be in order,
16180 and the starting number need not be one or zero.
16186 switch(i) {\SpecialChar ~
16217 case 4: ...\SpecialChar ~
16249 case 5: ...\SpecialChar ~
16281 case 3: ...\SpecialChar ~
16313 case 6: ...\SpecialChar ~
16381 Both the above switch statements will be implemented using a jump-table.
16382 The example to the right side is slightly more efficient as the check for
16383 the lower boundary of the jump-table is not needed.
16387 The number of case labels is at least three, since it takes two conditional
16388 statements to handle the boundary conditions.
16391 The number of case labels is less than 84, since each label takes 3 bytes
16392 and a jump-table can be utmost 256 bytes long.
16395 Switch statements which have gaps in the numeric sequence or those that
16396 have more that 84 case labels can be split into more than one switch statement
16397 for efficient code generation, e.g.:
16447 If the above switch statement is broken down into two switch statements
16486 case 9:\SpecialChar ~
16493 case 10:\SpecialChar ~
16499 case 11:\SpecialChar ~
16505 case 12:\SpecialChar ~
16512 then both the switch statements will be implemented using jump-tables whereas
16513 the unmodified switch statement will not be.
16514 You might also consider dummy cases 0 and 5 to 8 in this example.
16517 The pragma NOJTBOUND
16518 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
16522 can be used to turn off checking the
16535 It has no effect if a default label is supplied.
16536 Use of this pragma is dangerous: if the switch argument is not matched
16537 by a case statement the processor will happily jump into Nirvana.
16540 Bit-shifting Operations
16541 \begin_inset LatexCommand \index{Bit shifting}
16548 Bit shifting is one of the most frequently used operation in embedded programmin
16550 SDCC tries to implement bit-shift operations in the most efficient way
16566 generates the following code:
16583 In general SDCC will never setup a loop if the shift count is known.
16626 \begin_inset LatexCommand \index{Bit rotation}
16633 A special case of the bit-shift operation is bit rotation
16634 \begin_inset LatexCommand \index{rotating bits}
16638 , SDCC recognizes the following expression to be a left bit-rotation:
16648 char i;\SpecialChar ~
16659 /* unsigned is needed for rotation */
16664 i = ((i << 1) | (i >> 7));
16673 will generate the following code:
16692 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
16693 ns of this case will also be recognized as bit-rotation, i.e.:
16698 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
16701 Nibble and Byte Swapping
16704 Other special cases of the bit-shift operations are nibble or byte swapping
16705 \begin_inset LatexCommand \index{swapping nibbles/bytes}
16709 , SDCC recognizes the following expressions:
16732 i = ((i << 4) | (i >> 4));
16738 j = ((j << 8) | (j >> 8));
16741 and generates a swap instruction for the nibble swapping
16742 \begin_inset LatexCommand \index{Nibble swapping}
16746 or move instructions for the byte swapping
16747 \begin_inset LatexCommand \index{Byte swapping}
16753 \begin_inset Quotes sld
16757 \begin_inset Quotes srd
16760 example can be used to convert from little to big-endian or vice versa.
16761 If you want to change the endianness of a
16765 integer you have to cast to
16772 Note that SDCC stores numbers in little-endian
16778 Usually 8-bit processors don't care much about endianness.
16779 This is not the case for the standard 8051 which only has an instruction
16785 \begin_inset LatexCommand \index{DPTR}
16793 so little-endian is the more efficient byte order.
16797 \begin_inset LatexCommand \index{little-endian}
16802 \begin_inset LatexCommand \index{Endianness}
16807 lowest order first).
16811 \begin_inset LatexCommand \index{Highest Order Bit}
16818 It is frequently required to obtain the highest order bit of an integral
16819 type (long, int, short or char types).
16820 SDCC recognizes the following expression to yield the highest order bit
16821 and generates optimized code for it, e.g.:
16843 hob = (gint >> 15) & 1;
16853 will generate the following code:
16886 000A E5*01\SpecialChar ~
16913 000C 23\SpecialChar ~
16944 000D 54 01\SpecialChar ~
16971 000F F5*02\SpecialChar ~
16999 Variations of this case however will
17004 It is a standard C expression, so I heartily recommend this be the only
17005 way to get the highest order bit, (it is portable).
17006 Of course it will be recognized even if it is embedded in other expressions,
17012 xyz = gint + ((gint >> 15) & 1);
17015 will still be recognized.
17019 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
17024 \begin_inset LatexCommand \index{Peephole optimizer}
17031 The compiler uses a rule based, pattern matching and re-writing mechanism
17032 for peep-hole optimization.
17037 a peep-hole optimizer by Christopher W.
17038 Fraser (cwfraser@microsoft.com).
17039 A default set of rules are compiled into the compiler, additional rules
17040 may be added with the
17053 \begin_inset LatexCommand \index{-\/-peep-file}
17060 The rule language is best illustrated with examples.
17084 The above rule will change the following assembly
17085 \begin_inset LatexCommand \index{Assembler routines}
17107 Note: All occurrences of a
17111 (pattern variable) must denote the same string.
17112 With the above rule, the assembly sequence:
17122 will remain unmodified.
17126 Other special case optimizations may be added by the user (via
17142 some variants of the 8051 MCU allow only
17151 The following two rules will change all
17170 replace { lcall %1 } by { acall %1 }
17172 replace { ljmp %1 } by { ajmp %1 }
17177 inline-assembler code
17179 is also passed through the peep hole optimizer, thus the peephole optimizer
17180 can also be used as an assembly level macro expander.
17181 The rules themselves are MCU dependent whereas the rule language infra-structur
17182 e is MCU independent.
17183 Peephole optimization rules for other MCU can be easily programmed using
17188 The syntax for a rule is as follows:
17193 rule := replace [ restart ] '{' <assembly sequence> '
17231 <assembly sequence> '
17249 '}' [if <functionName> ] '
17254 <assembly sequence> := assembly instruction (each instruction including
17255 labels must be on a separate line).
17259 The optimizer will apply to the rules one by one from the top in the sequence
17260 of their appearance, it will terminate when all rules are exhausted.
17261 If the 'restart' option is specified, then the optimizer will start matching
17262 the rules again from the top, this option for a rule is expensive (performance)
17263 , it is intended to be used in situations where a transformation will trigger
17264 the same rule again.
17265 An example of this (not a good one, it has side effects) is the following
17288 Note that the replace pattern cannot be a blank, but can be a comment line.
17289 Without the 'restart' option only the inner most 'pop' 'push' pair would
17290 be eliminated, i.e.:
17320 the restart option the rule will be applied again to the resulting code
17321 and then all the pop-push pairs will be eliminated to yield:
17331 A conditional function can be attached to a rule.
17332 Attaching rules are somewhat more involved, let me illustrate this with
17359 The optimizer does a look-up of a function name table defined in function
17364 in the source file SDCCpeeph.c, with the name
17369 If it finds a corresponding entry the function is called.
17370 Note there can be no parameters specified for these functions, in this
17375 is crucial, since the function
17379 expects to find the label in that particular variable (the hash table containin
17380 g the variable bindings is passed as a parameter).
17381 If you want to code more such functions, take a close look at the function
17382 labelInRange and the calling mechanism in source file SDCCpeeph.c.
17383 Currently implemented are
17385 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
17386 24bitMode, portIsDS390, 24bitModeAndPortDS390
17395 I know this whole thing is a little kludgey, but maybe some day we will
17396 have some better means.
17397 If you are looking at this file, you will see the default rules that are
17398 compiled into the compiler, you can add your own rules in the default set
17399 there if you get tired of specifying the -
17419 <pending: this is messy and incomplete>
17424 Compiler support routines (_gptrget, _mulint etc)
17427 Stdclib functions (puts, printf, strcat etc)
17430 Math functions (sin, pow, sqrt etc)
17434 \begin_inset LatexCommand \index{Libraries}
17438 included in SDCC should have a license at least as liberal as the GNU Lesser
17439 General Public License
17440 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
17451 license statements for the libraries are missing.
17452 sdcc/device/lib/ser_ir.c
17456 come with a GPL (as opposed to LGPL) License - this will not be liberal
17457 enough for many embedded programmers.
17460 If you have ported some library or want to share experience about some code
17462 falls into any of these categories Busses (I
17463 \begin_inset Formula $^{\textrm{2}}$
17466 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
17467 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
17468 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
17469 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
17474 would certainly like to hear about it.
17475 Programmers coding for embedded systems are not especially famous for being
17476 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
17477 e these references are very valuable.
17481 \begin_inset LatexCommand \label{sub:External-Stack}
17486 \begin_inset LatexCommand \index{stack}
17491 \begin_inset LatexCommand \index{External stack}
17498 The external stack (-
17509 \begin_inset LatexCommand \index{-\/-xstack}
17513 ) is located at the start of the external ram segment, and is 256 bytes
17525 -xstack option is used to compile the program, the parameters and local
17526 variables of all reentrant functions are allocated in this area.
17527 This option is provided for programs with large stack space requirements.
17528 When used with the -
17539 \begin_inset LatexCommand \index{-\/-stack-auto}
17543 option, all parameters and local variables are allocated on the external
17544 stack (note support libraries will need to be recompiled with the same
17548 The compiler outputs the higher order address byte of the external ram segment
17549 into PORT P2, therefore when using the External Stack option, this port
17550 MAY NOT be used by the application program.
17554 \begin_inset LatexCommand \index{ANSI-compliance}
17559 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
17566 Deviations from the compliance:
17569 functions are not always reentrant
17570 \begin_inset LatexCommand \index{reentrant}
17577 structures cannot be assigned values directly, cannot be passed as function
17578 parameters or assigned to each other and cannot be a return value from
17605 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
17616 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
17638 return rets;/* is invalid in SDCC although allowed in ANSI */
17645 \begin_inset LatexCommand \index{long long (not supported)}
17650 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
17658 \begin_inset LatexCommand \index{double (not supported)}
17662 ' precision floating point
17663 \begin_inset LatexCommand \index{Floating point support}
17670 No support for setjmp
17671 \begin_inset LatexCommand \index{setjmp (not supported)}
17676 \begin_inset LatexCommand \index{longjmp (not supported)}
17684 \begin_inset LatexCommand \index{K\&R style}
17688 function declarations are NOT allowed.
17694 foo(i,j) /* this old style of function declarations */
17696 int i,j; /* are valid in ANSI but not valid in SDCC */
17711 functions declared as pointers
17712 \begin_inset LatexCommand \index{Pointers}
17717 \begin_inset LatexCommand \index{function pointers}
17721 must be dereferenced during the call.
17732 /* has to be called like this */
17734 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
17738 Cyclomatic Complexity
17739 \begin_inset LatexCommand \index{Cyclomatic complexity}
17746 Cyclomatic complexity of a function is defined as the number of independent
17747 paths the program can take during execution of the function.
17748 This is an important number since it defines the number test cases you
17749 have to generate to validate the function.
17750 The accepted industry standard for complexity number is 10, if the cyclomatic
17751 complexity reported by SDCC exceeds 10 you should think about simplification
17752 of the function logic.
17753 Note that the complexity level is not related to the number of lines of
17754 code in a function.
17755 Large functions can have low complexity, and small functions can have large
17761 SDCC uses the following formula to compute the complexity:
17766 complexity = (number of edges in control flow graph) - (number of nodes
17767 in control flow graph) + 2;
17771 Having said that the industry standard is 10, you should be aware that in
17772 some cases it be may unavoidable to have a complexity level of less than
17774 For example if you have switch statement with more than 10 case labels,
17775 each case label adds one to the complexity level.
17776 The complexity level is by no means an absolute measure of the algorithmic
17777 complexity of the function, it does however provide a good starting point
17778 for which functions you might look at for further optimization.
17785 \begin_inset LatexCommand \label{sub:MCS51-variants}
17790 \begin_inset LatexCommand \index{MCS51 variants}
17797 MCS51 processors are available from many vendors and come in many different
17799 While they might differ considerably in respect to Special Function Registers
17800 the core MCS51 is usually not modified or is kept compatible.
17802 \layout Subsubsection*
17804 pdata access by SFR
17805 \begin_inset LatexCommand \index{sfr}
17812 With the upcome of devices with internal xdata and flash memory devices
17813 using port P2 as dedicated I/O port is becoming more popular.
17814 Switching the high byte for pdata
17815 \begin_inset LatexCommand \index{pdata}
17819 access which was formerly done by port P2 is then achieved by a Special
17821 In well-established MCS51 tradition the address of this
17825 is where the chip designers decided to put it.
17826 As pdata addressing is used in the startup code for the initialization
17827 of xdata variables a separate startup code should be used as described
17829 \begin_inset LatexCommand \ref{sub:Startup-Code}
17834 \layout Subsubsection*
17836 Other Features available by SFR
17839 Some MCS51 variants offer features like Double DPTR
17840 \begin_inset LatexCommand \index{DPTR}
17844 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17845 These are currently not used for the MCS51 port.
17846 If you absolutely need them you can fall back to inline assembly or submit
17850 The Z80 and gbz80 port
17853 SDCC can target both the Zilog
17854 \begin_inset LatexCommand \index{Z80}
17858 and the Nintendo Gameboy's Z80-like gbz80
17859 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17864 The Z80 port is passed through the same
17867 \begin_inset LatexCommand \index{Regression test}
17873 as MCS51 and DS390 ports, so floating point support, support for long variables
17874 and bitfield support is fine.
17875 See mailing lists and forums about interrupt routines and access to I/O
17879 As always, the code is the authoritative reference - see z80/ralloc.c and
17882 \begin_inset LatexCommand \index{stack}
17886 frame is similar to that generated by the IAR Z80 compiler.
17887 IX is used as the base pointer, HL is used as a temporary register, and
17888 BC and DE are available for holding variables.
17889 IY is currently unused.
17891 \begin_inset LatexCommand \index{return value}
17896 One bad side effect of using IX as the base pointer is that a functions
17897 stack frame is limited to 127 bytes - this will be fixed in a later version.
17903 The port to the Motorola HC08
17904 \begin_inset LatexCommand \index{HC08}
17908 family has been added in October 2003, thank you Erik!
17911 Retargetting for other MCUs.
17914 The issues for retargetting the compiler are far too numerous to be covered
17916 What follows is a brief description of each of the seven phases of the
17917 compiler and its MCU dependency.
17920 Parsing the source and building the annotated parse tree.
17921 This phase is largely MCU independent (except for the language extensions).
17922 Syntax & semantic checks are also done in this phase, along with some initial
17923 optimizations like back patching labels and the pattern matching optimizations
17924 like bit-rotation etc.
17927 The second phase involves generating an intermediate code which can be easy
17928 manipulated during the later phases.
17929 This phase is entirely MCU independent.
17930 The intermediate code generation assumes the target machine has unlimited
17931 number of registers, and designates them with the name iTemp.
17932 The compiler can be made to dump a human readable form of the code generated
17946 This phase does the bulk of the standard optimizations and is also MCU independe
17948 This phase can be broken down into several sub-phases:
17952 Break down intermediate code (iCode) into basic blocks.
17954 Do control flow & data flow analysis on the basic blocks.
17956 Do local common subexpression elimination, then global subexpression elimination
17958 Dead code elimination
17962 If loop optimizations caused any changes then do 'global subexpression eliminati
17963 on' and 'dead code elimination' again.
17966 This phase determines the live-ranges; by live range I mean those iTemp
17967 variables defined by the compiler that still survive after all the optimization
17969 Live range analysis
17970 \begin_inset LatexCommand \index{Live range analysis}
17974 is essential for register allocation, since these computation determines
17975 which of these iTemps will be assigned to registers, and for how long.
17978 Phase five is register allocation.
17979 There are two parts to this process.
17983 The first part I call 'register packing' (for lack of a better term).
17984 In this case several MCU specific expression folding is done to reduce
17989 The second part is more MCU independent and deals with allocating registers
17990 to the remaining live ranges.
17991 A lot of MCU specific code does creep into this phase because of the limited
17992 number of index registers available in the 8051.
17995 The Code generation phase is (unhappily), entirely MCU dependent and very
17996 little (if any at all) of this code can be reused for other MCU.
17997 However the scheme for allocating a homogenized assembler operand for each
17998 iCode operand may be reused.
18001 As mentioned in the optimization section the peep-hole optimizer is rule
18002 based system, which can reprogrammed for other MCUs.
18006 \begin_inset LatexCommand \index{Compiler internals}
18013 The anatomy of the compiler
18014 \begin_inset LatexCommand \label{sub:The-anatomy-of}
18023 This is an excerpt from an article published in Circuit Cellar Magazine
18025 It's a little outdated (the compiler is much more efficient now and user/develo
18026 per friendly), but pretty well exposes the guts of it all.
18032 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
18033 It is fairly easy to retarget for other 8-bit MCU.
18034 Here we take a look at some of the internals of the compiler.
18039 \begin_inset LatexCommand \index{Parsing}
18046 Parsing the input source file and creating an AST (Annotated Syntax Tree
18047 \begin_inset LatexCommand \index{Annotated syntax tree}
18052 This phase also involves propagating types (annotating each node of the
18053 parse tree with type information) and semantic analysis.
18054 There are some MCU specific parsing rules.
18055 For example the storage classes, the extended storage classes are MCU specific
18056 while there may be a xdata storage class for 8051 there is no such storage
18057 class for z80 or Atmel AVR.
18058 SDCC allows MCU specific storage class extensions, i.e.
18059 xdata will be treated as a storage class specifier when parsing 8051 C
18060 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
18065 \begin_inset LatexCommand \index{iCode}
18072 Intermediate code generation.
18073 In this phase the AST is broken down into three-operand form (iCode).
18074 These three operand forms are represented as doubly linked lists.
18075 ICode is the term given to the intermediate form generated by the compiler.
18076 ICode example section shows some examples of iCode generated for some simple
18077 C source functions.
18081 \begin_inset LatexCommand \index{Optimizations}
18088 Bulk of the target independent optimizations is performed in this phase.
18089 The optimizations include constant propagation, common sub-expression eliminati
18090 on, loop invariant code movement, strength reduction of loop induction variables
18091 and dead-code elimination.
18094 Live range analysis
18095 \begin_inset LatexCommand \index{Live range analysis}
18102 During intermediate code generation phase, the compiler assumes the target
18103 machine has infinite number of registers and generates a lot of temporary
18105 The live range computation determines the lifetime of each of these compiler-ge
18106 nerated temporaries.
18107 A picture speaks a thousand words.
18108 ICode example sections show the live range annotations for each of the
18110 It is important to note here, each iCode is assigned a number in the order
18111 of its execution in the function.
18112 The live ranges are computed in terms of these numbers.
18113 The from number is the number of the iCode which first defines the operand
18114 and the to number signifies the iCode which uses this operand last.
18117 Register Allocation
18118 \begin_inset LatexCommand \index{Register allocation}
18125 The register allocation determines the type and number of registers needed
18127 In most MCUs only a few registers can be used for indirect addressing.
18128 In case of 8051 for example the registers R0 & R1 can be used to indirectly
18129 address the internal ram and DPTR to indirectly address the external ram.
18130 The compiler will try to allocate the appropriate register to pointer variables
18132 ICode example section shows the operands annotated with the registers assigned
18134 The compiler will try to keep operands in registers as much as possible;
18135 there are several schemes the compiler uses to do achieve this.
18136 When the compiler runs out of registers the compiler will check to see
18137 if there are any live operands which is not used or defined in the current
18138 basic block being processed, if there are any found then it will push that
18139 operand and use the registers in this block, the operand will then be popped
18140 at the end of the basic block.
18144 There are other MCU specific considerations in this phase.
18145 Some MCUs have an accumulator; very short-lived operands could be assigned
18146 to the accumulator instead of general-purpose register.
18152 Figure II gives a table of iCode operations supported by the compiler.
18153 The code generation involves translating these operations into corresponding
18154 assembly code for the processor.
18155 This sounds overly simple but that is the essence of code generation.
18156 Some of the iCode operations are generated on a MCU specific manner for
18157 example, the z80 port does not use registers to pass parameters so the
18158 SEND and RECV iCode operations will not be generated, and it also does
18159 not support JUMPTABLES.
18166 <Where is Figure II ?>
18170 \begin_inset LatexCommand \index{iCode}
18177 This section shows some details of iCode.
18178 The example C code does not do anything useful; it is used as an example
18179 to illustrate the intermediate code generated by the compiler.
18191 /* This function does nothing useful.
18198 for the purpose of explaining iCode */
18201 short function (data int *x)
18209 short i=10; /* dead initialization eliminated */
18214 short sum=10; /* dead initialization eliminated */
18227 while (*x) *x++ = *p++;
18241 /* compiler detects i,j to be induction variables */
18245 for (i = 0, j = 10 ; i < 10 ; i++, j
18271 mul += i * 3; /* this multiplication remains */
18277 gint += j * 3;/* this multiplication changed to addition */
18291 In addition to the operands each iCode contains information about the filename
18292 and line it corresponds to in the source file.
18293 The first field in the listing should be interpreted as follows:
18298 Filename(linenumber: iCode Execution sequence number : ICode hash table
18299 key : loop depth of the iCode).
18304 Then follows the human readable form of the ICode operation.
18305 Each operand of this triplet form can be of three basic types a) compiler
18306 generated temporary b) user defined variable c) a constant value.
18307 Note that local variables and parameters are replaced by compiler generated
18310 \begin_inset LatexCommand \index{Live range analysis}
18314 are computed only for temporaries (i.e.
18315 live ranges are not computed for global variables).
18317 \begin_inset LatexCommand \index{Register allocation}
18321 are allocated for temporaries only.
18322 Operands are formatted in the following manner:
18327 Operand Name [lr live-from : live-to ] { type information } [ registers
18333 As mentioned earlier the live ranges are computed in terms of the execution
18334 sequence number of the iCodes, for example
18336 the iTemp0 is live from (i.e.
18337 first defined in iCode with execution sequence number 3, and is last used
18338 in the iCode with sequence number 5).
18339 For induction variables such as iTemp21 the live range computation extends
18340 the lifetime from the start to the end of the loop.
18342 The register allocator used the live range information to allocate registers,
18343 the same registers may be used for different temporaries if their live
18344 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
18345 iTemp17 since their live ranges do not overlap.
18346 In addition the allocator also takes into consideration the type and usage
18347 of a temporary, for example itemp6 is a pointer to near space and is used
18348 as to fetch data from (i.e.
18349 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
18350 Some short lived temporaries are allocated to special registers which have
18351 meaning to the code generator e.g.
18352 iTemp13 is allocated to a pseudo register CC which tells the back end that
18353 the temporary is used only for a conditional jump the code generation makes
18354 use of this information to optimize a compare and jump ICode.
18356 There are several loop optimizations
18357 \begin_inset LatexCommand \index{Loop optimization}
18361 performed by the compiler.
18362 It can detect induction variables iTemp21(i) and iTemp23(j).
18363 Also note the compiler does selective strength reduction
18364 \begin_inset LatexCommand \index{Strength reduction}
18369 the multiplication of an induction variable in line 18 (gint = j * 3) is
18370 changed to addition, a new temporary iTemp17 is allocated and assigned
18371 a initial value, a constant 3 is then added for each iteration of the loop.
18372 The compiler does not change the multiplication
18373 \begin_inset LatexCommand \index{Multiplication}
18377 in line 17 however since the processor does support an 8 * 8 bit multiplication.
18379 Note the dead code elimination
18380 \begin_inset LatexCommand \index{Dead-code elimination}
18384 optimization eliminated the dead assignments in line 7 & 8 to I and sum
18392 Sample.c (5:1:0:0) _entry($9) :
18397 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
18402 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
18407 Sample.c(11:4:53:0) preHeaderLbl0($11) :
18412 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
18418 Sample.c(11:6:5:1) _whilecontinue_0($1) :
18423 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
18429 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
18434 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
18440 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
18446 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
18452 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
18458 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
18459 * int}[r0] + 0x2 {short}
18464 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
18469 Sample.c(11:17:21:0)_whilebreak_0($3) :
18474 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
18479 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
18484 Sample.c(15:20:54:0)preHeaderLbl1($13) :
18489 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
18494 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
18499 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
18504 Sample.c(15:24:26:1)_forcond_0($4) :
18509 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
18515 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
18520 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
18521 + ITemp21 [lr21:38]{short}[r4]
18526 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
18532 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
18533 + iTemp15 [lr29:30]{short}[r1]
18538 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
18544 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
18550 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
18556 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
18562 Sample.c(19:38:47:1) goto _forcond_0($4)
18567 Sample.c(19:39:48:0)_forbreak_0($7) :
18572 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
18573 + ITemp11 [lr19:40]{short}[r3]
18578 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
18583 Sample.c(20:42:51:0)_return($8) :
18588 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
18594 Finally the code generated for this function:
18635 ; ----------------------------------------------
18640 ; function function
18645 ; ----------------------------------------------
18655 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
18667 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
18679 ;_whilecontinue_0($1) :
18689 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
18694 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
18753 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
18772 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
18819 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
18859 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
18885 ; iTemp6 [lr5:16]{_near * int}[r0] =
18890 ; iTemp6 [lr5:16]{_near * int}[r0] +
18907 ; goto _whilecontinue_0($1)
18919 ; _whilebreak_0($3) :
18929 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
18941 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
18953 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
18965 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
18984 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
19013 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
19018 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
19063 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
19068 ; iTemp21 [lr21:38]{short}[r4]
19094 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
19127 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
19132 ; iTemp15 [lr29:30]{short}[r1]
19151 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
19198 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
19245 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
19257 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
19271 cjne r5,#0xff,00104$
19283 ; goto _forcond_0($4)
19295 ; _forbreak_0($7) :
19305 ; ret iTemp24 [lr40:41]{short}
19348 A few words about basic block successors, predecessors and dominators
19351 Successors are basic blocks
19352 \begin_inset LatexCommand \index{Basic blocks}
19356 that might execute after this basic block.
19358 Predecessors are basic blocks that might execute before reaching this basic
19361 Dominators are basic blocks that WILL execute before reaching this basic
19395 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
19398 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
19401 c) domVect of [BB4] = BB1 ...
19402 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
19410 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
19420 Thanks to all the other volunteer developers who have helped with coding,
19421 testing, web-page creation, distribution sets, etc.
19422 You know who you are :-)
19429 This document was initially written by Sandeep Dutta
19432 All product names mentioned herein may be trademarks
19433 \begin_inset LatexCommand \index{Trademarks}
19437 of their respective companies.
19444 To avoid confusion, the installation and building options for SDCC itself
19445 (chapter 2) are not part of the index.
19449 \begin_inset LatexCommand \printindex{}