1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
6 pdftitle={SDCC Compiler User Guide},
7 pdfauthor={SDCC development team},
8 pdfsubject={installation, user manual},
9 pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
10 embedded, GPL, manual, mcs51, PIC, small, Z80},
12 linkcolor=blue] {hyperref}
16 \inputencoding default
19 \paperfontsize default
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 This document would need some rework: The Installation section is much to
67 intimidating (as is the section about sdcdb).
70 Architecture specific stuff (like memory models, code examples) should maybe
74 into seperate sections/chapters/appendices (it is hard to document PIC or
78 a 8051 centered document)
81 SDCC Compiler User Guide
84 The strings enclosed in $ are automatically updated by cvs:
98 \begin_inset LatexCommand \tableofcontents{}
115 is a Freeware, retargettable, optimizing ANSI-C compiler by
119 designed for 8 bit Microprocessors.
120 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
122 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052 CPU}
126 , etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
127 It can be retargetted for other microprocessors, support for PIC, AVR is
129 The entire source code for the compiler is distributed under GPL.
130 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
131 SDCC has extensive language extensions suitable for utilizing various microcont
132 rollers and underlying hardware effectively.
137 In addition to the MCU specific optimizations SDCC also does a host of standard
141 global sub expression elimination,
144 loop optimizations (loop invariant, strength reduction of induction variables
148 constant folding & propagation,
154 dead code elimination
164 For the back-end SDCC uses a global register allocation scheme which should
165 be well suited for other 8 bit MCUs.
170 The peep hole optimizer uses a rule based substitution mechanism which is
176 Supported data-types are:
179 char (8 bits, 1 byte),
182 short and int (16 bits, 2 bytes),
185 long (32 bit, 4 bytes)
192 The compiler also allows
194 inline assembler code
196 to be embedded anywhere in a function.
197 In addition, routines developed in assembly can also be called.
201 SDCC also provides an option (-
211 -cyclomatic) to report the relative complexity of a function.
212 These functions can then be further optimized, or hand coded in assembly
218 SDCC also comes with a companion source level debugger SDCDB, the debugger
219 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
224 The latest version can be downloaded from
225 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
235 Please note: the compiler will probably always be some steps ahead of this
240 \begin_inset LatexCommand \index{Status of documentation}
250 Obviously this has pros and cons
259 All packages used in this compiler system are
267 ; source code for all the sub-packages (pre-processor, assemblers, linkers
268 etc) is distributed with the package.
269 This documentation is maintained using a freeware word processor (LyX).
271 This program is free software; you can redistribute it and/or modify it
272 under the terms of the GNU General Public License
273 \begin_inset LatexCommand \index{GNU General Public License, GPL}
277 as published by the Free Software Foundation; either version 2, or (at
278 your option) any later version.
279 This program is distributed in the hope that it will be useful, but WITHOUT
280 ANY WARRANTY; without even the implied warranty
281 \begin_inset LatexCommand \index{warranty}
285 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
286 See the GNU General Public License for more details.
287 You should have received a copy of the GNU General Public License along
288 with this program; if not, write to the Free Software Foundation, 59 Temple
289 Place - Suite 330, Boston, MA 02111-1307, USA.
290 In other words, you are welcome to use, share and improve this program.
291 You are forbidden to forbid anyone else to use, share and improve what
293 Help stamp out software-hoarding!
296 Typographic conventions
297 \begin_inset LatexCommand \index{Typographic conventions}
304 Throughout this manual, we will use the following convention.
305 Commands you have to type in are printed in
313 Code samples are printed in
318 Interesting items and new terms are printed in
323 Compatibility with previous versions
326 This version has numerous bug fixes compared with the previous version.
327 But we also introduced some incompatibilities with older versions.
328 Not just for the fun of it, but to make the compiler more stable, efficient
330 \begin_inset LatexCommand \index{ANSI-compliance}
340 short is now equivalent to int (16 bits), it used to be equivalent to char
341 (8 bits) which is not ANSI compliant
344 the default directory for gcc-builds where include, library and documentation
345 files are stored is now in /usr/local/share
348 char type parameters to vararg functions are casted to int unless explicitly
365 will push a as an int and as a char resp.
378 -regextend has been removed
391 -noregparms has been removed
404 -stack-after-data has been removed
409 <pending: more incompatibilities?>
415 What do you need before you start installation of SDCC? A computer, and
417 The preferred method of installation is to compile SDCC from source using
419 For Windows some pre-compiled binary distributions are available for your
421 You should have some experience with command line tools and compiler use.
427 The SDCC home page at
428 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
432 is a great place to find distribution sets.
433 You can also find links to the user mailing lists that offer help or discuss
434 SDCC with other SDCC users.
435 Web links to other SDCC related sites can also be found here.
436 This document can be found in the DOC directory of the source package as
438 Some of the other tools (simulator and assembler) included with SDCC contain
439 their own documentation and can be found in the source distribution.
440 If you want the latest unreleased software, the complete source package
441 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
444 Wishes for the future
447 There are (and always will be) some things that could be done.
448 Here are some I can think of:
455 char KernelFunction3(char p) at 0x340;
463 \begin_inset LatexCommand \index{code banking (not supported)}
471 If you can think of some more, please see the chapter 9 about filing feature
473 \begin_inset LatexCommand \index{Requesting features}
478 \begin_inset LatexCommand \index{Feature request}
488 \begin_inset LatexCommand \index{Installation}
496 \begin_inset LatexCommand \index{Options SDCC configuration}
503 The install paths, search paths and other options are defined when running
505 The defaults can be overridden by:
507 \labelwidthstring 00.00.0000
519 -prefix see table below
521 \labelwidthstring 00.00.0000
533 -exec_prefix see table below
535 \labelwidthstring 00.00.0000
547 -bindir see table below
549 \labelwidthstring 00.00.0000
561 -datadir see table below
563 \labelwidthstring 00.00.0000
565 docdir environment variable, see table below
567 \labelwidthstring 00.00.0000
569 include_dir_suffix environment variable, see table below
571 \labelwidthstring 00.00.0000
573 lib_dir_suffix environment variable, see table below
575 \labelwidthstring 00.00.0000
577 sdccconf_h_dir_separator environment variable, either / or
582 This character will only be used in sdccconf.h; don't forget it's a C-header,
583 therefore a double-backslash is needed there.
585 \labelwidthstring 00.00.0000
597 -disable-mcs51-port Excludes the Intel mcs51 port
599 \labelwidthstring 00.00.0000
611 -disable-gbz80-port Excludes the Gameboy gbz80 port
613 \labelwidthstring 00.00.0000
625 -z80-port Excludes the z80 port
627 \labelwidthstring 00.00.0000
639 -disable-avr-port Excludes the AVR port
641 \labelwidthstring 00.00.0000
653 -disable-ds390-port Excludes the DS390 port
655 \labelwidthstring 00.00.0000
667 -disable-pic-port Excludes the PIC port
669 \labelwidthstring 00.00.0000
681 -disable-xa51-port Excludes the XA51 port
683 \labelwidthstring 00.00.0000
695 -disable-ucsim Disables configuring and building of ucsim
697 \labelwidthstring 00.00.0000
709 -disable-device-lib-build Disables automatically building device libraries
711 \labelwidthstring 00.00.0000
723 -disable-packihx Disables building packihx
725 \labelwidthstring 00.00.0000
737 -enable-libgc Use the Bohem memory allocator.
738 Lower runtime footprint.
741 Furthermore the environment variables CC, CFLAGS, ...
742 the tools and their arguments can be influenced.
743 Please see `configure -
753 -help` and the man/info pages of `configure` for details.
757 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
758 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
759 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
760 At the moment it's not possible to change the default settings (it was
761 simply never required.
765 These configure options are compiled into the binaries, and can only be
766 changed by rerunning 'configure' and recompiling SDCC.
767 The configure options are written in
771 to distinguish them from run time environment variables (see section search
777 \begin_inset Quotes sld
781 \begin_inset Quotes srd
784 are used by the SDCC team to build the official Win32 binaries.
785 The SDCC team uses Mingw32 to build the official Windows binaries, because
792 a gcc compiler and last but not least
795 the binaries can be built by cross compiling on Sourceforge's compile farm.
798 See the examples, how to pass the Win32 settings to 'configure'.
799 The other Win32 builds using Borland, VC or whatever don't use 'configure',
800 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
812 <lyxtabular version="3" rows="8" columns="3">
814 <column alignment="block" valignment="top" leftline="true" width="0in">
815 <column alignment="block" valignment="top" leftline="true" width="0in">
816 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
817 <row topline="true" bottomline="true">
818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1015 <row topline="true">
1016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1043 <row topline="true" bottomline="true">
1044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1080 'configure' also computes relative paths.
1081 This is needed for full relocatability of a binary package and to complete
1082 search paths (see section search paths below):
1088 \begin_inset Tabular
1089 <lyxtabular version="3" rows="4" columns="3">
1091 <column alignment="block" valignment="top" leftline="true" width="0in">
1092 <column alignment="block" valignment="top" leftline="true" width="0in">
1093 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1094 <row topline="true" bottomline="true">
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1120 <row topline="true" bottomline="true">
1121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1150 <row bottomline="true">
1151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1178 <row bottomline="true">
1179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1230 \begin_inset Quotes srd
1234 \begin_inset Quotes srd
1248 \begin_inset Quotes srd
1252 \begin_inset Quotes srd
1280 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1289 \begin_inset Quotes srd
1292 i586-mingw32msvc-gcc
1293 \begin_inset Quotes srd
1297 \begin_inset Quotes srd
1300 i586-mingw32msvc-g++
1301 \begin_inset Quotes srd
1309 \begin_inset Quotes srd
1312 i586-mingw32msvc-ranlib
1313 \begin_inset Quotes srd
1321 \begin_inset Quotes srd
1324 i586-mingw32msvc-strip
1325 \begin_inset Quotes srd
1343 \begin_inset Quotes srd
1347 \begin_inset Quotes srd
1365 \begin_inset Quotes srd
1369 \begin_inset Quotes srd
1377 \begin_inset Quotes srd
1381 \begin_inset Quotes srd
1389 \begin_inset Quotes srd
1393 \begin_inset Quotes srd
1401 \begin_inset Quotes srd
1405 \begin_inset Quotes srd
1412 sdccconf_h_dir_separator=
1413 \begin_inset Quotes srd
1425 \begin_inset Quotes srd
1442 -disable-device-lib-build
1470 -host=i586-mingw32msvc -
1480 -build=unknown-unknown-linux-gnu
1484 \begin_inset Quotes sld
1488 \begin_inset Quotes srd
1491 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1500 \begin_inset Quotes srd
1504 \begin_inset Quotes srd
1512 \begin_inset Quotes srd
1516 \begin_inset Quotes srd
1534 \begin_inset Quotes srd
1538 \begin_inset Quotes srd
1556 \begin_inset Quotes srd
1560 \begin_inset Quotes srd
1568 \begin_inset Quotes srd
1572 \begin_inset Quotes srd
1580 \begin_inset Quotes srd
1584 \begin_inset Quotes srd
1592 \begin_inset Quotes srd
1596 \begin_inset Quotes srd
1603 sdccconf_h_dir_separator=
1604 \begin_inset Quotes srd
1616 \begin_inset Quotes srd
1636 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1647 -C' turns on caching, which gives a little bit extra speed.
1648 However if options are changed, it can be necessary to delete the config.cache
1653 \begin_inset LatexCommand \index{Install paths}
1659 \added_space_top medskip \align center
1661 \begin_inset Tabular
1662 <lyxtabular version="3" rows="5" columns="4">
1664 <column alignment="center" valignment="top" leftline="true" width="0">
1665 <column alignment="center" valignment="top" leftline="true" width="0">
1666 <column alignment="center" valignment="top" leftline="true" width="0">
1667 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1668 <row topline="true" bottomline="true">
1669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1710 <row topline="true">
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1750 <row topline="true">
1751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 $DATADIR/ $INCLUDE_DIR_SUFFIX
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 /usr/local/share/sdcc/include
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1790 <row topline="true">
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1806 $DATADIR/$LIB_DIR_SUFFIX
1809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 /usr/local/share/sdcc/lib
1817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1830 <row topline="true" bottomline="true">
1831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1854 /usr/local/share/sdcc/doc
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1879 *compiler, preprocessor, assembler, and linker
1885 is auto-appended by the compiler, e.g.
1886 small, large, z80, ds390 etc
1889 The install paths can still be changed during `make install` with e.g.:
1892 make install prefix=$(HOME)/local/sdcc
1895 Of course this doesn't change the search paths compiled into the binaries.
1899 \begin_inset LatexCommand \index{Search path}
1906 Some search paths or parts of them are determined by configure variables
1911 , see section above).
1912 Further search paths are determined by environment variables during runtime.
1915 The paths searched when running the compiler are as follows (the first catch
1921 Binary files (preprocessor, assembler and linker)
1927 \begin_inset Tabular
1928 <lyxtabular version="3" rows="4" columns="3">
1930 <column alignment="block" valignment="top" leftline="true" width="0in">
1931 <column alignment="block" valignment="top" leftline="true" width="0in">
1932 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1933 <row topline="true" bottomline="true">
1934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1959 <row topline="true">
1960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1989 <row topline="true">
1990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 Path of argv[0] (if available)
1998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2015 <row topline="true" bottomline="true">
2016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2057 \begin_inset Tabular
2058 <lyxtabular version="3" rows="6" columns="3">
2060 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2061 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2062 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2063 <row topline="true" bottomline="true">
2064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2089 <row topline="true">
2090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2145 <row topline="true">
2146 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2171 <row topline="true">
2172 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2186 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2209 <row topline="true">
2210 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2291 <row topline="true" bottomline="true">
2292 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2308 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2313 /usr/local/share/sdcc/
2318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2346 -nostdinc disables the last two search paths.
2356 With the exception of
2357 \begin_inset Quotes sld
2371 \begin_inset Quotes srd
2378 is auto-appended by the compiler (e.g.
2379 small, large, z80, ds390 etc.).
2386 \begin_inset Tabular
2387 <lyxtabular version="3" rows="6" columns="3">
2389 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2390 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2391 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2392 <row topline="true" bottomline="true">
2393 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2401 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2418 <row topline="true">
2419 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2474 <row topline="true">
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2487 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2514 <row topline="true">
2515 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2526 $LIB_DIR_SUFFIX/<model>
2529 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2543 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2560 <row topline="true">
2561 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2576 $LIB_DIR_SUFFIX/<model>
2579 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2688 <row topline="true" bottomline="true">
2689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2698 $LIB_DIR_SUFFIX/<model>
2701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2706 /usr/local/share/sdcc/
2713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2731 Don't delete any of the stray spaces in the table above without checking
2732 the HTML output (last line)!
2748 -nostdlib disables the last two search paths.
2752 \begin_inset LatexCommand \index{Building SDCC}
2757 \layout Subsubsection
2759 Building SDCC on Linux
2764 Download the source package
2766 either from the SDCC CVS repository or from the
2767 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2773 , it will be named something like sdcc
2786 Bring up a command line terminal, such as xterm.
2791 Unpack the file using a command like:
2794 "tar -xzf sdcc.src.tar.gz
2799 , this will create a sub-directory called sdcc with all of the sources.
2802 Change directory into the main SDCC directory, for example type:
2819 This configures the package for compilation on your system.
2835 All of the source packages will compile, this can take a while.
2851 This copies the binary executables, the include files, the libraries and
2852 the documentation to the install directories.
2853 \layout Subsubsection
2855 Building SDCC on OSX 2.x
2858 Follow the instruction for Linux.
2862 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2863 )) fails to compile SDCC.
2864 Fortunately there's also gcc 2.9.x installed, which works fine.
2865 This compiler can be selected by running 'configure' with:
2868 ./configure CC=gcc2 CXX=g++2
2869 \layout Subsubsection
2871 Cross compiling SDCC on Linux for Windows
2874 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2875 See section 'Configure Options'.
2876 \layout Subsubsection
2878 Building SDCC on Windows
2881 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2883 They use Unix-sockets, which are not available on Win32.
2884 \layout Subsubsection
2886 Windows Install Using a Binary Package
2889 Download the binary package and unpack it using your favorite unpacking
2890 tool (gunzip, WinZip, etc).
2891 This should unpack to a group of sub-directories.
2892 An example directory structure after unpacking the mingw32 package is:
2897 bin for the executables, c:
2905 lib for the include and libraries.
2908 Adjust your environment variable PATH to include the location of the bin
2909 directory or start sdcc using the full path.
2910 \layout Subsubsection
2912 Building SDCC using Cygwin and Mingw32
2915 For building and installing a Cygwin executable follow the instructions
2921 \begin_inset Quotes sld
2925 \begin_inset Quotes srd
2928 Win32-binary can be built, which will not need the Cygwin-DLL.
2929 For the necessary 'configure' options see section 'configure options' or
2930 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2934 In order to install Cygwin on Windows download setup.exe from
2935 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2941 \begin_inset Quotes sld
2944 default text file type
2945 \begin_inset Quotes srd
2949 \begin_inset Quotes sld
2953 \begin_inset Quotes srd
2956 and download/install at least the following packages.
2957 Some packages are selected by default, others will be automatically selected
2958 because of dependencies with the manually selected packages.
2959 Never deselect these packages!
2968 gcc ; version 3.x is fine, no need to use the old 2.9x
2971 binutils ; selected with gcc
2977 rxvt ; a nice console, which makes life much easier under windoze (see below)
2980 man ; not really needed for building SDCC, but you'll miss it sooner or
2984 less ; not really needed for building SDCC, but you'll miss it sooner or
2988 cvs ; only if you use CVS access
2991 If you want to develop something you'll need:
2994 python ; for the regression tests
2997 gdb ; the gnu debugger, together with the nice GUI
2998 \begin_inset Quotes sld
3002 \begin_inset Quotes srd
3008 openssh ; to access the CF or commit changes
3011 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3012 use autoconf-stable!
3015 rxvt is a nice console with history.
3016 Replace in your cygwin.bat the line
3035 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3038 -bg black -fg white -geometry 100x65 -e bash -
3051 Text selected with the mouse is automatically copied to the clipboard, pasting
3052 works with shift-insert.
3056 The other good tip is to make sure you have no //c/-style paths anywhere,
3057 use /cygdrive/c/ instead.
3058 Using // invokes a network lookup which is very slow.
3060 \begin_inset Quotes sld
3064 \begin_inset Quotes srd
3067 is too long, you can change it with e.g.
3073 SDCC sources use the unix line ending LF.
3074 Life is much easier, if you store the source tree on a drive, which is
3075 mount in binary mode.
3076 And use an editor which can handle LF-only line endings.
3077 Make sure not to commit files with windows line endings.
3078 \layout Subsubsection
3080 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3085 Download the source package
3087 either from the SDCC CVS repository or from the
3088 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3094 , it will be named something like sdcc
3101 SDCC is distributed with all the projects, workspaces, and files you need
3102 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3103 doesn't build under MSVC).
3104 The workspace name is 'sdcc.dsw'.
3105 Please note that as it is now, all the executables are created in a folder
3109 Once built you need to copy the executables from sdcc
3113 bin before running SDCC.
3118 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3119 flex.exe, and gawk.exe.
3120 One good place to get them is
3121 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3129 Download the file UnxUtils
3130 \begin_inset LatexCommand \index{UnxUtils}
3135 Now you have to install the utilities and setup MSVC so it can locate the
3137 Here there are two alternatives (choose one!):
3144 a) Extract UnxUtils.zip to your C:
3146 hard disk PRESERVING the original paths, otherwise bison won't work.
3147 (If you are using WinZip make certain that 'Use folder names' is selected)
3151 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3152 in 'Show directories for:' select 'Executable files', and in the directories
3153 window add a new path: 'C:
3163 (As a side effect, you get a bunch of Unix utilities that could be useful,
3164 such as diff and patch.)
3171 This one avoids extracting a bunch of files you may not use, but requires
3176 a) Create a directory were to put the tools needed, or use a directory already
3184 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3185 to such directory WITHOUT preserving the original paths.
3186 (If you are using WinZip make certain that 'Use folder names' is not selected)
3190 c) Rename bison.exe to '_bison.exe'.
3194 d) Create a batch file 'bison.bat' in 'C:
3198 ' and add these lines:
3218 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3222 Steps 'c' and 'd' are needed because bison requires by default that the
3223 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3224 '/usr/local/share/' I think.
3225 So it is necessary to tell bison where those files are located if they
3226 are not in such directory.
3227 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3231 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3232 in 'Show directories for:' select 'Executable files', and in the directories
3233 window add a new path: 'c:
3236 Note that you can use any other path instead of 'c:
3238 util', even the path where the Visual C++ tools are, probably: 'C:
3242 Microsoft Visual Studio
3247 So you don't have to execute step 'e' :)
3251 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3252 the executables from sdcc
3256 bin, and you can compile using sdcc.
3257 \layout Subsubsection
3259 Building SDCC Using Borland
3262 From the sdcc directory, run the command "make -f Makefile.bcc".
3263 This should regenerate all the .exe files in the bin directory except for
3264 sdcdb.exe (which currently doesn't build under Borland C++).
3267 If you modify any source files and need to rebuild, be aware that the dependenci
3268 es may not be correctly calculated.
3269 The safest option is to delete all .obj files and run the build again.
3270 From a Cygwin BASH prompt, this can easily be done with the command:
3280 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3282 ) -print -exec rm {}
3291 or on Windows NT/2000/XP from the command prompt with the command:
3298 del /s *.obj *.lib *.rul
3301 from the sdcc directory.
3304 Building the Documentation
3311 Testing out the SDCC Compiler
3314 The first thing you should do after installing your SDCC compiler is to
3330 \begin_inset LatexCommand \index{version}
3337 at the prompt, and the program should run and tell you the version.
3338 If it doesn't run, or gives a message about not finding sdcc program, then
3339 you need to check over your installation.
3340 Make sure that the sdcc bin directory is in your executable search path
3341 defined by the PATH environment setting (see the Trouble-shooting section
3343 Make sure that the sdcc program is in the bin folder, if not perhaps something
3344 did not install correctly.
3352 is commonly installed as described in section
3353 \begin_inset Quotes sld
3356 Install and search paths
3357 \begin_inset Quotes srd
3366 Make sure the compiler works on a very simple example.
3367 Type in the following test.c program using your favorite
3393 Compile this using the following command:
3402 If all goes well, the compiler will generate a test.asm and test.rel file.
3403 Congratulations, you've just compiled your first program with SDCC.
3404 We used the -c option to tell SDCC not to link the generated code, just
3405 to keep things simple for this step.
3413 The next step is to try it with the linker.
3423 If all goes well the compiler will link with the libraries and produce
3424 a test.ihx output file.
3429 (no test.ihx, and the linker generates warnings), then the problem is most
3430 likely that sdcc cannot find the
3434 usr/local/share/sdcc/lib directory
3438 (see the Install trouble-shooting section for suggestions).
3446 The final test is to ensure sdcc can use the
3450 header files and libraries.
3451 Edit test.c and change it to the following:
3468 strcpy(str1, "testing");
3475 Compile this by typing
3482 This should generate a test.ihx output file, and it should give no warnings
3483 such as not finding the string.h file.
3484 If it cannot find the string.h file, then the problem is that sdcc cannot
3485 find the /usr/local/share/sdcc/include directory
3489 (see the Install trouble-shooting section for suggestions).
3507 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3511 to find exactly where SDCC is looking for the include and lib files.
3514 Install Trouble-shooting
3515 \begin_inset LatexCommand \index{Install trouble-shooting}
3520 \layout Subsubsection
3522 SDCC does not build correctly.
3525 A thing to try is starting from scratch by unpacking the .tgz source package
3526 again in an empty directory.
3534 ./configure 2>&1 | tee configure.log
3548 make 2>&1 | tee make.log
3555 If anything goes wrong, you can review the log files to locate the problem.
3556 Or a relevant part of this can be attached to an email that could be helpful
3557 when requesting help from the mailing list.
3558 \layout Subsubsection
3561 \begin_inset Quotes sld
3565 \begin_inset Quotes srd
3572 \begin_inset Quotes sld
3576 \begin_inset Quotes srd
3579 command is a script that analyzes your system and performs some configuration
3580 to ensure the source package compiles on your system.
3581 It will take a few minutes to run, and will compile a few tests to determine
3582 what compiler features are installed.
3583 \layout Subsubsection
3586 \begin_inset Quotes sld
3590 \begin_inset Quotes srd
3596 This runs the GNU make tool, which automatically compiles all the source
3597 packages into the final installed binary executables.
3598 \layout Subsubsection
3601 \begin_inset Quotes sld
3605 \begin_inset Quotes erd
3611 This will install the compiler, other executables libraries and include
3612 files in to the appropriate directories.
3614 \begin_inset Quotes sld
3617 Install and Search PATHS
3618 \begin_inset Quotes srd
3623 On most systems you will need super-user privileges to do this.
3629 SDCC is not just a compiler, but a collection of tools by various developers.
3630 These include linkers, assemblers, simulators and other components.
3631 Here is a summary of some of the components.
3632 Note that the included simulator and assembler have separate documentation
3633 which you can find in the source package in their respective directories.
3634 As SDCC grows to include support for other processors, other packages from
3635 various developers are included and may have their own sets of documentation.
3639 You might want to look at the files which are installed in <installdir>.
3640 At the time of this writing, we find the following programs for gcc-builds:
3644 In <installdir>/bin:
3647 sdcc - The compiler.
3650 sdcpp - The C preprocessor.
3653 asx8051 - The assembler for 8051 type processors.
3660 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3663 aslink -The linker for 8051 type processors.
3670 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3673 s51 - The ucSim 8051 simulator.
3676 sdcdb - The source debugger.
3679 packihx - A tool to pack (compress) Intel hex files.
3682 In <installdir>/share/sdcc/include
3688 In <installdir>/share/sdcc/lib
3691 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3695 In <installdir>/share/sdcc/doc
3701 As development for other processors proceeds, this list will expand to include
3702 executables to support processors like AVR, PIC, etc.
3703 \layout Subsubsection
3708 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3709 the assembler and linkage editor.
3710 \layout Subsubsection
3713 \begin_inset LatexCommand \index{sdcpp}
3717 - The C-Preprocessor
3720 The preprocessor is a modified version of the GNU preprocessor.
3721 The C preprocessor is used to pull in #include sources, process #ifdef
3722 statements, #defines and so on.
3723 \layout Subsubsection
3725 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3729 This is retargettable assembler & linkage editor, it was developed by Alan
3731 John Hartman created the version for 8051, and I (Sandeep) have made some
3732 enhancements and bug fixes for it to work properly with the SDCC.
3733 \layout Subsubsection
3736 \begin_inset LatexCommand \index{s51}
3743 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3744 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3749 The simulator is built as part of the build process.
3750 For more information visit Daniel's web site at:
3751 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3756 It currently support the core mcs51, the Dallas DS80C390 and the Phillips
3758 \layout Subsubsection
3761 \begin_inset LatexCommand \index{sdcdb}
3765 - Source Level Debugger
3768 Sdcdb is the companion source level debugger.
3769 The current version of the debugger uses Daniel's Simulator S51
3770 \begin_inset LatexCommand \index{s51}
3774 , but can be easily changed to use other simulators.
3781 \layout Subsubsection
3783 Single Source File Projects
3786 For single source file 8051 projects the process is very simple.
3787 Compile your programs with the following command
3790 "sdcc sourcefile.c".
3794 This will compile, assemble and link your source file.
3795 Output files are as follows
3799 \begin_inset LatexCommand \index{.asm}
3804 \begin_inset LatexCommand \index{Assembler source}
3808 file created by the compiler
3812 \begin_inset LatexCommand \index{.lst}
3817 \begin_inset LatexCommand \index{Assembler listing}
3821 file created by the Assembler
3825 \begin_inset LatexCommand \index{.rst}
3830 \begin_inset LatexCommand \index{Assembler listing}
3834 file updated with linkedit information, created by linkage editor
3838 \begin_inset LatexCommand \index{.sym}
3843 \begin_inset LatexCommand \index{Symbol listing}
3847 for the sourcefile, created by the assembler
3851 \begin_inset LatexCommand \index{.rel}
3856 \begin_inset LatexCommand \index{Object file}
3860 created by the assembler, input to Linkage editor
3864 \begin_inset LatexCommand \index{.map}
3869 \begin_inset LatexCommand \index{Memory map}
3873 for the load module, created by the Linker
3877 \begin_inset LatexCommand \index{.mem}
3881 - A file with a summary of the memory usage
3885 \begin_inset LatexCommand \index{.ihx}
3889 - The load module in Intel hex format
3890 \begin_inset LatexCommand \index{Intel hex format}
3894 (you can select the Motorola S19 format
3895 \begin_inset LatexCommand \index{Motorola S19 format}
3910 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3915 If you need another format you might want to use objdump
3916 \begin_inset LatexCommand \index{objdump}
3921 \begin_inset LatexCommand \index{srecord}
3929 \begin_inset LatexCommand \index{.adb}
3933 - An intermediate file containing debug information needed to create the
3945 \begin_inset LatexCommand \index{-\/-debug}
3953 \begin_inset LatexCommand \index{.cdb}
3957 - An optional file (with -
3967 -debug) containing debug information
3972 \begin_inset LatexCommand \index{. (no extension)}
3976 An optional AOMF51 file containing debug information (with -
3990 \begin_inset LatexCommand \index{.dump*}
3994 - Dump file to debug the compiler it self (with -
4004 -dumpall) (see section
4005 \begin_inset Quotes sld
4008 Anatomy of the compiler
4009 \begin_inset Quotes srd
4013 \layout Subsubsection
4015 Projects with Multiple Source Files
4018 SDCC can compile only ONE file at a time.
4019 Let us for example assume that you have a project containing the following
4024 foo1.c (contains some functions)
4026 foo2.c (contains some more functions)
4028 foomain.c (contains more functions and the function main)
4036 The first two files will need to be compiled separately with the commands:
4068 Then compile the source file containing the
4073 \begin_inset LatexCommand \index{Linker}
4077 the files together with the following command:
4085 foomain.c\SpecialChar ~
4086 foo1.rel\SpecialChar ~
4091 \begin_inset LatexCommand \index{.rel}
4103 can be separately compiled as well:
4114 sdcc foomain.rel foo1.rel foo2.rel
4121 The file containing the
4136 file specified in the command line, since the linkage editor processes
4137 file in the order they are presented to it.
4138 The linker is invoked from sdcc using a script file with extension .lnk
4139 \begin_inset LatexCommand \index{.lnk}
4144 You can view this file to troubleshoot linking problems such as those arising
4145 from missing libraries.
4146 \layout Subsubsection
4148 Projects with Additional Libraries
4149 \begin_inset LatexCommand \index{Libraries}
4156 Some reusable routines may be compiled into a library, see the documentation
4157 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4161 \begin_inset LatexCommand \index{.lib}
4168 Libraries created in this manner can be included in the command line.
4169 Make sure you include the -L <library-path> option to tell the linker where
4170 to look for these files if they are not in the current directory.
4171 Here is an example, assuming you have the source file
4183 (if that is not the same as your current project):
4190 sdcc foomain.c foolib.lib -L mylib
4201 must be an absolute path name.
4205 The most efficient way to use libraries is to keep separate modules in separate
4207 The lib file now should name all the modules.rel
4208 \begin_inset LatexCommand \index{rel}
4213 For an example see the standard library file
4217 in the directory <installdir>/share/lib/small.
4220 Command Line Options
4221 \begin_inset LatexCommand \index{Command Line Options}
4226 \layout Subsubsection
4228 Processor Selection Options
4229 \begin_inset LatexCommand \index{Options processor selection}
4234 \begin_inset LatexCommand \index{Processor selection options}
4240 \labelwidthstring 00.00.0000
4245 \begin_inset LatexCommand \index{-mmcs51}
4251 Generate code for the MCS51
4252 \begin_inset LatexCommand \index{MCS51}
4256 family of processors.
4257 This is the default processor target.
4259 \labelwidthstring 00.00.0000
4264 \begin_inset LatexCommand \index{-mds390}
4270 Generate code for the DS80C390
4271 \begin_inset LatexCommand \index{DS80C390}
4277 \labelwidthstring 00.00.0000
4282 \begin_inset LatexCommand \index{-mds400}
4288 Generate code for the DS80C400
4289 \begin_inset LatexCommand \index{DS80C400}
4295 \labelwidthstring 00.00.0000
4300 \begin_inset LatexCommand \index{-mz80}
4306 Generate code for the Z80
4307 \begin_inset LatexCommand \index{Z80}
4311 family of processors.
4313 \labelwidthstring 00.00.0000
4318 \begin_inset LatexCommand \index{-mgbz80}
4324 Generate code for the GameBoy Z80
4325 \begin_inset LatexCommand \index{GameBoy Z80}
4331 \labelwidthstring 00.00.0000
4336 \begin_inset LatexCommand \index{-mavr}
4342 Generate code for the Atmel AVR
4343 \begin_inset LatexCommand \index{AVR}
4347 processor (In development, not complete).
4348 AVR users should probably have a look at avr-gcc
4349 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4356 I think it is fair to direct users there for now.
4357 Open source is also about avoiding unnecessary work .
4358 But I didn't find the 'official' link.
4360 \labelwidthstring 00.00.0000
4365 \begin_inset LatexCommand \index{-mpic14}
4371 Generate code for the PIC 14
4372 \begin_inset LatexCommand \index{PIC14}
4376 -bit processors (Microchip p16f84 and variants).
4379 p16f627 p16f628 p16f84 p16f873 p16f877?
4381 \labelwidthstring 00.00.0000
4386 \begin_inset LatexCommand \index{-mpic16}
4392 Generate code for the PIC 16
4393 \begin_inset LatexCommand \index{PIC16}
4397 -bit processors (Microchip p18f452 and variants).
4399 \labelwidthstring 00.00.0000
4405 Generate code for the Toshiba TLCS-900H
4406 \begin_inset LatexCommand \index{TLCS-900H}
4410 processor (In development, not complete).
4412 \labelwidthstring 00.00.0000
4417 \begin_inset LatexCommand \index{-mxa51}
4423 Generate code for the Phillips XA51
4424 \begin_inset LatexCommand \index{XA51}
4428 processor (In development, not complete).
4429 \layout Subsubsection
4431 Preprocessor Options
4432 \begin_inset LatexCommand \index{Options preprocessor}
4437 \begin_inset LatexCommand \index{Preprocessor options}
4443 \labelwidthstring 00.00.0000
4448 \begin_inset LatexCommand \index{-I<path>}
4454 The additional location where the pre processor will look for <..h> or
4455 \begin_inset Quotes eld
4459 \begin_inset Quotes erd
4464 \labelwidthstring 00.00.0000
4469 \begin_inset LatexCommand \index{-D<macro[=value]>}
4475 Command line definition of macros.
4476 Passed to the pre processor.
4478 \labelwidthstring 00.00.0000
4483 \begin_inset LatexCommand \index{-M}
4489 Tell the preprocessor to output a rule suitable for make describing the
4490 dependencies of each object file.
4491 For each source file, the preprocessor outputs one make-rule whose target
4492 is the object file name for that source file and whose dependencies are
4493 all the files `#include'd in it.
4494 This rule may be a single line or may be continued with `
4496 '-newline if it is long.
4497 The list of rules is printed on standard output instead of the preprocessed
4501 \labelwidthstring 00.00.0000
4506 \begin_inset LatexCommand \index{-C}
4512 Tell the preprocessor not to discard comments.
4513 Used with the `-E' option.
4515 \labelwidthstring 00.00.0000
4520 \begin_inset LatexCommand \index{-MM}
4531 Like `-M' but the output mentions only the user header files included with
4533 \begin_inset Quotes eld
4537 System header files included with `#include <file>' are omitted.
4539 \labelwidthstring 00.00.0000
4544 \begin_inset LatexCommand \index{-Aquestion(answer)}
4550 Assert the answer answer for question, in case it is tested with a preprocessor
4551 conditional such as `#if #question(answer)'.
4552 `-A-' disables the standard assertions that normally describe the target
4555 \labelwidthstring 00.00.0000
4561 (answer) Assert the answer answer for question, in case it is tested with
4562 a preprocessor conditional such as `#if #question(answer)'.
4563 `-A-' disables the standard assertions that normally describe the target
4566 \labelwidthstring 00.00.0000
4571 \begin_inset LatexCommand \index{-Umacro}
4577 Undefine macro macro.
4578 `-U' options are evaluated after all `-D' options, but before any `-include'
4579 and `-imacros' options.
4581 \labelwidthstring 00.00.0000
4586 \begin_inset LatexCommand \index{-dM}
4592 Tell the preprocessor to output only a list of the macro definitions that
4593 are in effect at the end of preprocessing.
4594 Used with the `-E' option.
4596 \labelwidthstring 00.00.0000
4601 \begin_inset LatexCommand \index{-dD}
4607 Tell the preprocessor to pass all macro definitions into the output, in
4608 their proper sequence in the rest of the output.
4610 \labelwidthstring 00.00.0000
4615 \begin_inset LatexCommand \index{-dN}
4626 Like `-dD' except that the macro arguments and contents are omitted.
4627 Only `#define name' is included in the output.
4628 \layout Subsubsection
4631 \begin_inset LatexCommand \index{Options linker}
4636 \begin_inset LatexCommand \index{Linker options}
4642 \labelwidthstring 00.00.0000
4662 \begin_inset LatexCommand \index{-\/-lib-path}
4667 \begin_inset LatexCommand \index{-L -\/-lib-path}
4676 <absolute path to additional libraries> This option is passed to the linkage
4677 editor's additional libraries
4678 \begin_inset LatexCommand \index{Libraries}
4683 The path name must be absolute.
4684 Additional library files may be specified in the command line.
4685 See section Compiling programs for more details.
4687 \labelwidthstring 00.00.0000
4704 \begin_inset LatexCommand \index{-\/-xram-loc}
4708 <Value> The start location of the external ram
4709 \begin_inset LatexCommand \index{xdata}
4713 , default value is 0.
4714 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4724 -xram-loc 0x8000 or -
4736 \labelwidthstring 00.00.0000
4753 \begin_inset LatexCommand \index{-\/-code-loc}
4757 <Value> The start location of the code
4758 \begin_inset LatexCommand \index{code}
4762 segment, default value 0.
4763 Note when this option is used the interrupt vector table is also relocated
4764 to the given address.
4765 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4775 -code-loc 0x8000 or -
4787 \labelwidthstring 00.00.0000
4804 \begin_inset LatexCommand \index{-\/-stack-loc}
4808 <Value> By default the stack
4809 \begin_inset LatexCommand \index{stack}
4813 is placed after the data segment.
4814 Using this option the stack can be placed anywhere in the internal memory
4816 The value entered can be in Hexadecimal or Decimal format, e.g.
4827 -stack-loc 0x20 or -
4838 Since the sp register is incremented before a push or call, the initial
4839 sp will be set to one byte prior the provided value.
4840 The provided value should not overlap any other memory areas such as used
4841 register banks or the data segment and with enough space for the current
4844 \labelwidthstring 00.00.0000
4861 \begin_inset LatexCommand \index{-\/-data-loc}
4865 <Value> The start location of the internal ram data
4866 \begin_inset LatexCommand \index{data}
4871 The value entered can be in Hexadecimal or Decimal format, eg.
4893 (By default, the start location of the internal ram data segment is set
4894 as low as possible in memory, taking into account the used register banks
4895 and the bit segment at address 0x20.
4896 For example if register banks 0 and 1 are used without bit variables, the
4897 data segment will be set, if -
4907 -data-loc is not used, to location 0x10.)
4909 \labelwidthstring 00.00.0000
4926 \begin_inset LatexCommand \index{-\/-idata-loc}
4930 <Value> The start location of the indirectly addressable internal ram
4931 \begin_inset LatexCommand \index{idata}
4935 , default value is 0x80.
4936 The value entered can be in Hexadecimal or Decimal format, eg.
4947 -idata-loc 0x88 or -
4959 \labelwidthstring 00.00.0000
4974 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4983 The linker output (final object code) is in Intel Hex format.
4984 \begin_inset LatexCommand \index{Intel hex format}
4988 (This is the default option).
4990 \labelwidthstring 00.00.0000
5005 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5014 The linker output (final object code) is in Motorola S19 format
5015 \begin_inset LatexCommand \index{Motorola S19 format}
5020 \layout Subsubsection
5023 \begin_inset LatexCommand \index{Options MCS51}
5028 \begin_inset LatexCommand \index{MCS51 options}
5034 \labelwidthstring 00.00.0000
5049 \begin_inset LatexCommand \index{-\/-model-large}
5055 Generate code for Large model programs see section Memory Models for more
5057 If this option is used all source files in the project should be compiled
5059 In addition the standard library routines are compiled with small model,
5060 they will need to be recompiled.
5062 \labelwidthstring 00.00.0000
5077 \begin_inset LatexCommand \index{-\/-model-small}
5088 Generate code for Small Model programs see section Memory Models for more
5090 This is the default model.
5091 \layout Subsubsection
5094 \begin_inset LatexCommand \index{Options DS390}
5099 \begin_inset LatexCommand \index{DS390 options}
5105 \labelwidthstring 00.00.0000
5122 \begin_inset LatexCommand \index{-\/-model-flat24}
5132 Generate 24-bit flat mode code.
5133 This is the one and only that the ds390 code generator supports right now
5134 and is default when using
5139 See section Memory Models for more details.
5141 \labelwidthstring 00.00.0000
5158 \begin_inset LatexCommand \index{-\/-stack-10bit}
5162 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5163 This is the one and only that the ds390 code generator supports right now
5164 and is default when using
5169 In this mode, the stack is located in the lower 1K of the internal RAM,
5170 which is mapped to 0x400000.
5171 Note that the support is incomplete, since it still uses a single byte
5172 as the stack pointer.
5173 This means that only the lower 256 bytes of the potential 1K stack space
5174 will actually be used.
5175 However, this does allow you to reclaim the precious 256 bytes of low RAM
5176 for use for the DATA and IDATA segments.
5177 The compiler will not generate any code to put the processor into 10 bit
5179 It is important to ensure that the processor is in this mode before calling
5180 any re-entrant functions compiled with this option.
5181 In principle, this should work with the
5194 \begin_inset LatexCommand \index{-\/-stack-auto}
5200 option, but that has not been tested.
5201 It is incompatible with the
5214 \begin_inset LatexCommand \index{-\/-xstack}
5221 It also only makes sense if the processor is in 24 bit contiguous addressing
5234 -model-flat24 option
5237 \layout Subsubsection
5240 \begin_inset LatexCommand \index{Options Z80}
5245 \begin_inset LatexCommand \index{Z80 options}
5251 \labelwidthstring 00.00.0000
5268 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5278 Force a called function to always save BC.
5280 \labelwidthstring 00.00.0000
5297 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5301 When linking, skip the standard crt0.o object file.
5302 You must provide your own crt0.o for your system when linking.
5304 \layout Subsubsection
5306 Optimization Options
5307 \begin_inset LatexCommand \index{Options optimization}
5312 \begin_inset LatexCommand \index{Optimization options}
5318 \labelwidthstring 00.00.0000
5333 \begin_inset LatexCommand \index{-\/-nogcse}
5339 Will not do global subexpression elimination, this option may be used when
5340 the compiler creates undesirably large stack/data spaces to store compiler
5342 A warning message will be generated when this happens and the compiler
5343 will indicate the number of extra bytes it allocated.
5344 It recommended that this option NOT be used, #pragma\SpecialChar ~
5346 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5350 can be used to turn off global subexpression elimination
5351 \begin_inset LatexCommand \index{Subexpression elimination}
5355 for a given function only.
5357 \labelwidthstring 00.00.0000
5372 \begin_inset LatexCommand \index{-\/-noinvariant}
5378 Will not do loop invariant optimizations, this may be turned off for reasons
5379 explained for the previous option.
5380 For more details of loop optimizations performed see section Loop Invariants.It
5381 recommended that this option NOT be used, #pragma\SpecialChar ~
5383 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5387 can be used to turn off invariant optimizations for a given function only.
5389 \labelwidthstring 00.00.0000
5404 \begin_inset LatexCommand \index{-\/-noinduction}
5410 Will not do loop induction optimizations, see section strength reduction
5411 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5414 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5418 can be used to turn off induction optimizations for a given function only.
5420 \labelwidthstring 00.00.0000
5435 \begin_inset LatexCommand \index{-\/-nojtbound}
5446 Will not generate boundary condition check when switch statements
5447 \begin_inset LatexCommand \index{switch statement}
5451 are implemented using jump-tables.
5452 See section Switch Statements for more details.
5453 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5455 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5459 can be used to turn off boundary checking for jump tables for a given function
5462 \labelwidthstring 00.00.0000
5477 \begin_inset LatexCommand \index{-\/-noloopreverse}
5486 Will not do loop reversal
5487 \begin_inset LatexCommand \index{Loop reversing}
5493 \labelwidthstring 00.00.0000
5510 \begin_inset LatexCommand \index{-\/-nolabelopt }
5514 Will not optimize labels (makes the dumpfiles more readable).
5516 \labelwidthstring 00.00.0000
5531 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5537 Will not memcpy initialized data in far space from code space.
5538 This saves a few bytes in code space if you don't have initialized data.
5539 \layout Subsubsection
5542 \begin_inset LatexCommand \index{Options other}
5548 \labelwidthstring 00.00.0000
5564 \begin_inset LatexCommand \index{-\/-compile-only}
5569 \begin_inset LatexCommand \index{-c -\/-compile-only}
5575 will compile and assemble the source, but will not call the linkage editor.
5577 \labelwidthstring 00.00.0000
5596 \begin_inset LatexCommand \index{-\/-c1mode}
5602 reads the preprocessed source from standard input and compiles it.
5603 The file name for the assembler output must be specified using the -o option.
5605 \labelwidthstring 00.00.0000
5610 \begin_inset LatexCommand \index{-E}
5616 Run only the C preprocessor.
5617 Preprocess all the C source files specified and output the results to standard
5620 \labelwidthstring 00.00.0000
5626 \begin_inset LatexCommand \index{-o <path/file>}
5632 The output path resp.
5633 file where everything will be placed.
5634 If the parameter is a path, it must have a trailing slash (or backslash
5635 for the Windows binaries) to be recognized as a path.
5638 \labelwidthstring 00.00.0000
5653 \begin_inset LatexCommand \index{-\/-stack-auto}
5664 All functions in the source file will be compiled as
5669 \begin_inset LatexCommand \index{reentrant}
5674 the parameters and local variables will be allocated on the stack
5675 \begin_inset LatexCommand \index{stack}
5680 see section Parameters and Local Variables for more details.
5681 If this option is used all source files in the project should be compiled
5685 \labelwidthstring 00.00.0000
5700 \begin_inset LatexCommand \index{-\/-xstack}
5706 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5707 variables and passing parameters.
5708 See section on external stack for more details.
5710 \labelwidthstring 00.00.0000
5725 \begin_inset LatexCommand \index{-\/-callee-saves}
5730 \begin_inset LatexCommand \index{function prologue}
5734 function1[,function2][,function3]....
5737 The compiler by default uses a caller saves convention for register saving
5738 across function calls, however this can cause unnecessary register pushing
5739 & popping when calling small functions from larger functions.
5740 This option can be used to switch the register saving convention for the
5741 function names specified.
5742 The compiler will not save registers when calling these functions, no extra
5743 code will be generated at the entry & exit for these functions to save
5744 & restore the registers used by these functions, this can SUBSTANTIALLY
5745 reduce code & improve run time performance of the generated code.
5746 In the future the compiler (with inter procedural analysis) will be able
5747 to determine the appropriate scheme to use for each function call.
5748 DO NOT use this option for built-in functions such as _mulint..., if this
5749 option is used for a library function the appropriate library function
5750 needs to be recompiled with the same option.
5751 If the project consists of multiple source files then all the source file
5752 should be compiled with the same -
5762 -callee-saves option string.
5763 Also see #pragma\SpecialChar ~
5765 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5771 \labelwidthstring 00.00.0000
5786 \begin_inset LatexCommand \index{-\/-debug}
5795 When this option is used the compiler will generate debug information, that
5796 can be used with the SDCDB.
5797 The debug information is collected in a file with .cdb extension.
5798 For more information see documentation for SDCDB.
5800 \labelwidthstring 00.00.0000
5817 \begin_inset LatexCommand \index{-\/-peep-file}
5821 <filename> This option can be used to use additional rules to be used by
5822 the peep hole optimizer.
5823 See section Peep Hole optimizations for details on how to write these rules.
5825 \labelwidthstring 00.00.0000
5830 \begin_inset LatexCommand \index{-S}
5841 Stop after the stage of compilation proper; do not assemble.
5842 The output is an assembler code file for the input file specified.
5844 \labelwidthstring 00.00.0000
5848 -Wa_asmOption[,asmOption]
5851 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5856 Pass the asmOption to the assembler.
5858 \labelwidthstring 00.00.0000
5862 -Wl_linkOption[,linkOption]
5865 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5870 Pass the linkOption to the linker.
5872 \labelwidthstring 00.00.0000
5887 \begin_inset LatexCommand \index{-\/-int-long-reent}
5893 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5894 Note by default these libraries are compiled as non-reentrant.
5895 See section Installation for more details.
5897 \labelwidthstring 00.00.0000
5912 \begin_inset LatexCommand \index{-\/-cyclomatic}
5921 This option will cause the compiler to generate an information message for
5922 each function in the source file.
5923 The message contains some
5927 information about the function.
5928 The number of edges and nodes the compiler detected in the control flow
5929 graph of the function, and most importantly the
5931 cyclomatic complexity
5932 \begin_inset LatexCommand \index{Cyclomatic complexity}
5938 see section on Cyclomatic Complexity for more details.
5940 \labelwidthstring 00.00.0000
5955 \begin_inset LatexCommand \index{-\/-float-reent}
5964 Floating point library is compiled as reentrant
5965 \begin_inset LatexCommand \index{reentrant}
5969 .See section Installation for more details.
5971 \labelwidthstring 00.00.0000
5986 \begin_inset LatexCommand \index{-\/-nooverlay}
5992 The compiler will not overlay parameters and local variables of any function,
5993 see section Parameters and local variables for more details.
5995 \labelwidthstring 00.00.0000
6010 \begin_inset LatexCommand \index{-\/-main-return}
6016 This option can be used when the code generated is called by a monitor
6018 The compiler will generate a 'ret' upon return from the 'main'
6019 \begin_inset LatexCommand \index{main return}
6024 The default option is to lock up i.e.
6027 \labelwidthstring 00.00.0000
6042 \begin_inset LatexCommand \index{-\/-no-peep}
6048 Disable peep-hole optimization.
6050 \labelwidthstring 00.00.0000
6065 \begin_inset LatexCommand \index{-\/-peep-asm}
6071 Pass the inline assembler code through the peep hole optimizer.
6072 This can cause unexpected changes to inline assembler code, please go through
6073 the peephole optimizer
6074 \begin_inset LatexCommand \index{Peephole optimizer}
6078 rules defined in the source file tree '<target>/peeph.def' before using
6081 \labelwidthstring 00.00.0000
6098 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
6102 Causes the linker to check if the internal ram usage is within limits of
6105 \labelwidthstring 00.00.0000
6122 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
6126 Causes the linker to check if the external ram usage is within limits of
6129 \labelwidthstring 00.00.0000
6146 \begin_inset LatexCommand \index{-\/-code-size<Value>}
6150 Causes the linker to check if the code usage is within limits of the given
6153 \labelwidthstring 00.00.0000
6168 \begin_inset LatexCommand \index{-\/-nostdincl}
6174 This will prevent the compiler from passing on the default include path
6175 to the preprocessor.
6177 \labelwidthstring 00.00.0000
6192 \begin_inset LatexCommand \index{-\/-nostdlib}
6198 This will prevent the compiler from passing on the default library
6199 \begin_inset LatexCommand \index{Libraries}
6205 \labelwidthstring 00.00.0000
6220 \begin_inset LatexCommand \index{-\/-verbose}
6226 Shows the various actions the compiler is performing.
6228 \labelwidthstring 00.00.0000
6233 \begin_inset LatexCommand \index{-V}
6239 Shows the actual commands the compiler is executing.
6241 \labelwidthstring 00.00.0000
6256 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6262 Hides your ugly and inefficient c-code from the asm file, so you can always
6263 blame the compiler :).
6265 \labelwidthstring 00.00.0000
6280 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6286 Include i-codes in the asm file.
6287 Sounds like noise but is most helpful for debugging the compiler itself.
6289 \labelwidthstring 00.00.0000
6304 \begin_inset LatexCommand \index{-\/-less-pedantic}
6310 Disable some of the more pedantic warnings (jwk burps: please be more specific
6313 \labelwidthstring 00.00.0000
6328 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6334 Display the directories in the compiler's search path
6336 \labelwidthstring 00.00.0000
6351 \begin_inset LatexCommand \index{-\/-vc}
6357 Display errors and warnings using MSVC style, so you can use SDCC with
6360 \labelwidthstring 00.00.0000
6375 \begin_inset LatexCommand \index{-\/-use-stdout}
6381 Send errors and warnings to stdout instead of stderr
6382 \layout Subsubsection
6384 Intermediate Dump Options
6385 \begin_inset LatexCommand \index{Options intermediate dump}
6390 \begin_inset LatexCommand \index{Intermediate dump options}
6397 The following options are provided for the purpose of retargetting and debugging
6399 These provided a means to dump the intermediate code (iCode
6400 \begin_inset LatexCommand \index{iCode}
6404 ) generated by the compiler in human readable form at various stages of
6405 the compilation process.
6408 \labelwidthstring 00.00.0000
6423 \begin_inset LatexCommand \index{-\/-dumpraw}
6429 This option will cause the compiler to dump the intermediate code into
6432 <source filename>.dumpraw
6434 just after the intermediate code has been generated for a function, i.e.
6435 before any optimizations are done.
6437 \begin_inset LatexCommand \index{Basic blocks}
6441 at this stage ordered in the depth first number, so they may not be in
6442 sequence of execution.
6444 \labelwidthstring 00.00.0000
6459 \begin_inset LatexCommand \index{-\/-dumpgcse}
6465 Will create a dump of iCode's, after global subexpression elimination
6466 \begin_inset LatexCommand \index{Global subexpression elimination}
6472 <source filename>.dumpgcse.
6474 \labelwidthstring 00.00.0000
6489 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6495 Will create a dump of iCode's, after deadcode elimination
6496 \begin_inset LatexCommand \index{Dead-code elimination}
6502 <source filename>.dumpdeadcode.
6504 \labelwidthstring 00.00.0000
6519 \begin_inset LatexCommand \index{-\/-dumploop}
6528 Will create a dump of iCode's, after loop optimizations
6529 \begin_inset LatexCommand \index{Loop optimization}
6535 <source filename>.dumploop.
6537 \labelwidthstring 00.00.0000
6552 \begin_inset LatexCommand \index{-\/-dumprange}
6561 Will create a dump of iCode's, after live range analysis
6562 \begin_inset LatexCommand \index{Live range analysis}
6568 <source filename>.dumprange.
6570 \labelwidthstring 00.00.0000
6585 \begin_inset LatexCommand \index{-\/-dumlrange}
6591 Will dump the life ranges
6592 \begin_inset LatexCommand \index{Live range analysis}
6598 \labelwidthstring 00.00.0000
6613 \begin_inset LatexCommand \index{-\/-dumpregassign}
6622 Will create a dump of iCode's, after register assignment
6623 \begin_inset LatexCommand \index{Register assignment}
6629 <source filename>.dumprassgn.
6631 \labelwidthstring 00.00.0000
6646 \begin_inset LatexCommand \index{-\/-dumplrange}
6652 Will create a dump of the live ranges of iTemp's
6654 \labelwidthstring 00.00.0000
6669 \begin_inset LatexCommand \index{-\/-dumpall}
6680 Will cause all the above mentioned dumps to be created.
6683 Environment variables
6684 \begin_inset LatexCommand \index{Environment variables}
6691 SDCC recognizes the following environment variables:
6693 \labelwidthstring 00.00.0000
6698 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6704 SDCC installs a signal handler
6705 \begin_inset LatexCommand \index{signal handler}
6709 to be able to delete temporary files after an user break (^C) or an exception.
6710 If this environment variable is set, SDCC won't install the signal handler
6711 in order to be able to debug SDCC.
6713 \labelwidthstring 00.00.0000
6718 \begin_inset LatexCommand \index{TMP}
6724 \begin_inset LatexCommand \index{TEMP}
6730 \begin_inset LatexCommand \index{TMPDIR}
6736 Path, where temporary files will be created.
6737 The order of the variables is the search order.
6738 In a standard *nix environment these variables are not set, and there's
6739 no need to set them.
6740 On Windows it's recommended to set one of them.
6742 \labelwidthstring 00.00.0000
6747 \begin_inset LatexCommand \index{SDCC\_HOME}
6754 \begin_inset Quotes sld
6757 2.3 Install and search paths
6758 \begin_inset Quotes srd
6763 \labelwidthstring 00.00.0000
6768 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6775 \begin_inset Quotes sld
6778 2.3 Install and search paths
6779 \begin_inset Quotes srd
6784 \labelwidthstring 00.00.0000
6789 \begin_inset LatexCommand \index{SDCC\_LIB}
6796 \begin_inset Quotes sld
6799 2.3 Install and search paths
6800 \begin_inset Quotes srd
6806 There are some more environment variables recognized by SDCC, but these
6807 are solely used for debugging purposes.
6808 They can change or disappear very quickly, and will never be documented.
6811 MCS51/DS390 Storage Class
6812 \begin_inset LatexCommand \index{Storage class}
6819 In addition to the ANSI storage classes SDCC allows the following MCS51
6820 specific storage classes.
6821 \layout Subsubsection
6824 \begin_inset LatexCommand \index{xdata}
6831 Variables declared with this storage class will be placed in the external
6837 storage class for Large Memory model, e.g.:
6842 xdata unsigned char xduc;
6843 \layout Subsubsection
6846 \begin_inset LatexCommand \index{data}
6857 storage class for Small Memory model.
6858 Variables declared with this storage class will be allocated in the directly
6859 addressable portion of the internal RAM of a 8051, e.g.:
6865 \layout Subsubsection
6868 \begin_inset LatexCommand \index{idata}
6875 Variables declared with this storage class will be allocated into the indirectly
6876 addressable portion of the internal ram of a 8051, e.g.:
6882 \layout Subsubsection
6885 \begin_inset LatexCommand \index{bit}
6892 This is a data-type and a storage class specifier.
6893 When a variable is declared as a bit, it is allocated into the bit addressable
6894 memory of 8051, e.g.:
6900 \layout Subsubsection
6903 \begin_inset LatexCommand \index{sfr}
6908 \begin_inset LatexCommand \index{sbit}
6915 Like the bit keyword,
6919 signifies both a data-type and storage class, they are used to describe
6920 the special function registers and special bit variables of a 8051, eg:
6926 \begin_inset LatexCommand \index{at}
6930 0x80 P0; /* special function register P0 at location 0x80 */
6932 sbit at 0xd7 CY; /* CY (Carry Flag
6933 \begin_inset LatexCommand \index{Flags}
6938 \begin_inset LatexCommand \index{Carry flag}
6946 \begin_inset LatexCommand \index{Pointers}
6953 SDCC allows (via language extensions) pointers to explicitly point to any
6954 of the memory spaces
6955 \begin_inset LatexCommand \index{Memory model}
6960 In addition to the explicit pointers, the compiler uses (by default) generic
6961 pointers which can be used to point to any of the memory spaces.
6965 Pointer declaration examples:
6970 /* pointer physically in xternal ram pointing to object in internal ram
6973 data unsigned char * xdata p;
6977 /* pointer physically in code rom pointing to data in xdata space */
6979 xdata unsigned char * code p;
6983 /* pointer physically in code space pointing to data in code space */
6985 code unsigned char * code p;
6989 /* the following is a generic pointer physically located in xdata space
6995 Well you get the idea.
7000 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7013 The highest order byte of the
7017 pointers contains the data space information.
7018 Assembler support routines are called whenever data is stored or retrieved
7024 These are useful for developing reusable library
7025 \begin_inset LatexCommand \index{Libraries}
7030 Explicitly specifying the pointer type will generate the most efficient
7035 \begin_inset LatexCommand \index{Parameters}
7040 \begin_inset LatexCommand \index{Local variable}
7047 Automatic (local) variables and parameters to functions can either be placed
7048 on the stack or in data-space.
7049 The default action of the compiler is to place these variables in the internal
7050 RAM (for small model) or external RAM (for large model).
7051 This in fact makes them
7054 \begin_inset LatexCommand \index{static}
7060 so by default functions are non-reentrant
7061 \begin_inset LatexCommand \index{reentrant}
7069 They can be placed on the stack
7070 \begin_inset LatexCommand \index{stack}
7087 \begin_inset LatexCommand \index{-\/-stack-auto}
7093 option or by using the
7096 \begin_inset LatexCommand \index{reentrant}
7102 keyword in the function declaration, e.g.:
7107 unsigned char foo(char i) reentrant
7117 Since stack space on 8051 is limited, the
7135 option should be used sparingly.
7136 Note that the reentrant keyword just means that the parameters & local
7137 variables will be allocated to the stack, it
7141 mean that the function is register bank independent.
7145 Local variables can be assigned storage classes and absolute
7146 \begin_inset LatexCommand \index{Absolute addressing}
7155 unsigned char foo() {
7161 xdata unsigned char i;
7173 data at 0x31 unsigned char j;
7185 In the above example the variable
7189 will be allocated in the external ram,
7193 in bit addressable space and
7212 or when a function is declared as
7216 this should only be done for static variables.
7219 Parameters however are not allowed any storage class, (storage classes for
7220 parameters will be ignored), their allocation is governed by the memory
7221 model in use, and the reentrancy options.
7225 \begin_inset LatexCommand \index{Overlaying}
7233 \begin_inset LatexCommand \index{reentrant}
7237 functions SDCC will try to reduce internal ram space usage by overlaying
7238 parameters and local variables of a function (if possible).
7239 Parameters and local variables of a function will be allocated to an overlayabl
7240 e segment if the function has
7242 no other function calls and the function is non-reentrant and the memory
7244 \begin_inset LatexCommand \index{Memory model}
7251 If an explicit storage class
7252 \begin_inset LatexCommand \index{Storage class}
7256 is specified for a local variable, it will NOT be overlayed.
7259 Note that the compiler (not the linkage editor) makes the decision for overlayin
7261 Functions that are called from an interrupt service routine should be preceded
7262 by a #pragma\SpecialChar ~
7264 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7268 if they are not reentrant.
7271 Also note that the compiler does not do any processing of inline
7272 \begin_inset LatexCommand \index{inline}
7276 assembler code, so the compiler might incorrectly assign local variables
7277 and parameters of a function into the overlay segment if the inline assembler
7278 code calls other c-functions that might use the overlay.
7279 In that case the #pragma\SpecialChar ~
7280 NOOVERLAY should be used.
7283 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7285 \begin_inset LatexCommand \index{Multiplication}
7290 \begin_inset LatexCommand \index{Division}
7294 will NOT be overlayed since these are implemented using external functions,
7303 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7309 void set_error(unsigned char errcd)
7325 void some_isr () interrupt
7326 \begin_inset LatexCommand \index{interrupt}
7331 \begin_inset LatexCommand \index{using}
7361 In the above example the parameter
7369 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7371 not present, this could cause unpredictable runtime behavior when called
7373 The #pragma\SpecialChar ~
7374 NOOVERLAY ensures that the parameters and local variables for
7375 the function are NOT overlayed.
7378 Interrupt Service Routines
7381 SDCC allows interrupt service routines to be coded in C, with some extended
7387 void timer_isr (void) interrupt 1 using 1
7397 The optional number following the
7400 \begin_inset LatexCommand \index{interrupt}
7406 keyword is the interrupt number this routine will service.
7407 When present, the compiler will insert a call to this routine in the
7408 interrupt vector table for the interrupt number specified.
7413 keyword can be used to tell the compiler to use the specified register
7414 bank (8051 specific) when generating code for this function.
7415 Note that when some function is called from an interrupt service routine
7416 it should be preceded by a #pragma\SpecialChar ~
7418 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7422 if it is not reentrant.
7423 Furthermore nonreentrant functions should not be called from the main program
7424 while the interrupt service routine might be active.
7425 If the interrupt service routines changes variables which are accessed
7426 by other functions these variables should be declared
7431 \begin_inset LatexCommand \index{volatile}
7439 A special note here, int (16 bit) and long (32 bit) integer division
7440 \begin_inset LatexCommand \index{Division}
7445 \begin_inset LatexCommand \index{Multiplication}
7450 \begin_inset LatexCommand \index{Modulus}
7454 operations are implemented using external support routines developed in
7455 ANSI-C, if an interrupt service routine needs to do any of these operations
7456 then the support routines (as mentioned in a following section) will have
7457 to be recompiled using the
7470 \begin_inset LatexCommand \index{-\/-stack-auto}
7476 option and the source file will need to be compiled using the
7491 \begin_inset LatexCommand \index{-\/-int-long-rent}
7498 If you have multiple source files in your project, interrupt service routines
7499 can be present in any of them, but a prototype of the isr MUST be present
7500 or included in the file that contains the function
7507 Interrupt numbers and the corresponding address & descriptions for the Standard
7508 8051/8052 are listed below.
7509 SDCC will automatically adjust the interrupt vector table to the maximum
7510 interrupt number specified.
7516 \begin_inset Tabular
7517 <lyxtabular version="3" rows="7" columns="3">
7519 <column alignment="center" valignment="top" leftline="true" width="0in">
7520 <column alignment="center" valignment="top" leftline="true" width="0in">
7521 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
7522 <row topline="true" bottomline="true">
7523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7548 <row topline="true">
7549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7574 <row topline="true">
7575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7600 <row topline="true">
7601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7626 <row topline="true">
7627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7652 <row topline="true">
7653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7678 <row topline="true" bottomline="true">
7679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7713 If the interrupt service routine is defined without
7716 \begin_inset LatexCommand \index{using}
7722 a register bank or with register bank 0 (using 0), the compiler will save
7723 the registers used by itself on the stack upon entry and restore them at
7724 exit, however if such an interrupt service routine calls another function
7725 then the entire register bank will be saved on the stack.
7726 This scheme may be advantageous for small interrupt service routines which
7727 have low register usage.
7730 If the interrupt service routine is defined to be using a specific register
7735 are save and restored, if such an interrupt service routine calls another
7736 function (using another register bank) then the entire register bank of
7737 the called function will be saved on the stack.
7738 This scheme is recommended for larger interrupt service routines.
7741 Calling other functions from an interrupt service routine is not recommended,
7742 avoid it if possible.
7746 Also see the _naked modifier.
7754 <TODO: this isn't implemented at all!>
7760 A special keyword may be associated with a function declaring it as
7765 SDCC will generate code to disable all interrupts upon entry to a critical
7766 function and enable them back before returning.
7767 Note that nesting critical functions may cause unpredictable results.
7785 The critical attribute maybe used with other attributes like
7791 \begin_inset LatexCommand \index{Naked functions}
7798 A special keyword may be associated with a function declaring it as
7801 \begin_inset LatexCommand \index{\_naked}
7812 function modifier attribute prevents the compiler from generating prologue
7813 \begin_inset LatexCommand \index{function prologue}
7818 \begin_inset LatexCommand \index{function epilogue}
7822 code for that function.
7823 This means that the user is entirely responsible for such things as saving
7824 any registers that may need to be preserved, selecting the proper register
7825 bank, generating the
7829 instruction at the end, etc.
7830 Practically, this means that the contents of the function must be written
7831 in inline assembler.
7832 This is particularly useful for interrupt functions, which can have a large
7833 (and often unnecessary) prologue/epilogue.
7834 For example, compare the code generated by these two functions:
7840 \begin_inset LatexCommand \index{volatile}
7844 data unsigned char counter;
7846 void simpleInterrupt(void) interrupt
7847 \begin_inset LatexCommand \index{interrupt}
7865 void nakedInterrupt(void) interrupt 2 _naked
7874 \begin_inset LatexCommand \index{\_asm}
7903 ; MUST explicitly include ret or reti in _naked function.
7910 \begin_inset LatexCommand \index{\_endasm}
7919 For an 8051 target, the generated simpleInterrupt looks like:
8060 whereas nakedInterrupt looks like:
8084 ; MUST explicitly include ret(i) in _naked function.
8087 While there is nothing preventing you from writing C code inside a _naked
8088 function, there are many ways to shoot yourself in the foot doing this,
8089 and it is recommended that you stick to inline assembler.
8092 Functions using private banks
8093 \begin_inset LatexCommand \index{bank}
8103 \begin_inset LatexCommand \index{using}
8109 attribute (which tells the compiler to use a register bank other than the
8110 default bank zero) should only be applied to
8113 \begin_inset LatexCommand \index{interrupt}
8119 functions (see note 1 below).
8120 This will in most circumstances make the generated ISR code more efficient
8121 since it will not have to save registers on the stack.
8128 attribute will have no effect on the generated code for a
8132 function (but may occasionally be useful anyway
8138 possible exception: if a function is called ONLY from 'interrupt' functions
8139 using a particular bank, it can be declared with the same 'using' attribute
8140 as the calling 'interrupt' functions.
8141 For instance, if you have several ISRs using bank one, and all of them
8142 call memcpy(), it might make sense to create a specialized version of memcpy()
8143 'using 1', since this would prevent the ISR from having to save bank zero
8144 to the stack on entry and switch to bank zero before calling the function
8151 (pending: I don't think this has been done yet)
8158 function using a non-zero bank will assume that it can trash that register
8159 bank, and will not save it.
8160 Since high-priority interrupts
8161 \begin_inset LatexCommand \index{interrupt priority}
8165 can interrupt low-priority ones on the 8051 and friends, this means that
8166 if a high-priority ISR
8170 a particular bank occurs while processing a low-priority ISR
8174 the same bank, terrible and bad things can happen.
8175 To prevent this, no single register bank should be
8179 by both a high priority and a low priority ISR.
8180 This is probably most easily done by having all high priority ISRs use
8181 one bank and all low priority ISRs use another.
8182 If you have an ISR which can change priority at runtime, you're on your
8183 own: I suggest using the default bank zero and taking the small performance
8187 It is most efficient if your ISR calls no other functions.
8188 If your ISR must call other functions, it is most efficient if those functions
8189 use the same bank as the ISR (see note 1 below); the next best is if the
8190 called functions use bank zero.
8191 It is very inefficient to call a function using a different, non-zero bank
8197 \begin_inset LatexCommand \index{Absolute addressing}
8204 Data items can be assigned an absolute address with the
8207 \begin_inset LatexCommand \index{at}
8213 keyword, in addition to a storage class, e.g.:
8219 \begin_inset LatexCommand \index{xdata}
8224 \begin_inset LatexCommand \index{at}
8228 0x7ffe unsigned int chksum;
8231 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8232 of the external ram.
8233 The compiler does not actually reserve any space for variables declared
8234 in this way (they are implemented with an equate in the assembler).
8235 Thus it is left to the programmer to make sure there are no overlaps with
8236 other variables that are declared without the absolute address.
8237 The assembler listing file (.lst
8238 \begin_inset LatexCommand \index{.lst}
8242 ) and the linker output files (.rst
8243 \begin_inset LatexCommand \index{.rst}
8248 \begin_inset LatexCommand \index{.map}
8252 ) are good places to look for such overlaps.
8255 In case of memory mapped I/O devices the keyword
8259 should be used to tell the compiler that accesses might not be optimized
8266 \begin_inset LatexCommand \index{volatile}
8271 \begin_inset LatexCommand \index{xdata}
8276 \begin_inset LatexCommand \index{at}
8280 0x8000 unsigned char PORTA_8255;
8283 Absolute address can be specified for variables in all storage classes,
8290 \begin_inset LatexCommand \index{bit}
8295 \begin_inset LatexCommand \index{at}
8302 The above example will allocate the variable at offset 0x02 in the bit-addressab
8304 There is no real advantage to assigning absolute addresses to variables
8305 in this manner, unless you want strict control over all the variables allocated.
8306 One possible use would be to write hardware portable code.
8307 For example, if you have a routine that uses one or more of the microcontroller
8308 I/O pins, and such pins are different for two different hardwares, you
8309 can declare the I/O pins in you routine using
8322 void DS1306_put(unsigned char value)
8330 unsigned char mask=0x80;
8354 SDI=(value & mask)?1:0;
8395 Then, someplace in the code for the first hardware you would use
8400 bit at 0x80 SDI;\SpecialChar ~
8404 /*I/O port 0, bit 0*/
8406 bit at 0x81 SCLK;\SpecialChar ~
8409 /*I/O port 0, bit 1*/
8411 bit CPOL;\SpecialChar ~
8422 /*This is a variable, let the linker allocate this one*/
8425 Similarly, for the second hardware you would use
8430 bit at 0x83 SDI;\SpecialChar ~
8434 /*I/O port 0, bit 3*/
8436 bit at 0x91 SCLK;\SpecialChar ~
8439 /*I/O port 1, bit 1*/
8441 bit CPOL;\SpecialChar ~
8452 /*This is a variable, let the linker allocate this one*/
8455 and you can use the same hardware dependent routine without changes, as
8456 for example in a library.
8457 This is somehow similar to sbit, but only one absolute address has to be
8458 specified in the whole project.
8462 \begin_inset LatexCommand \index{Startup code}
8469 The compiler inserts a call to the C routine
8471 _sdcc_external_startup()
8472 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8481 at the start of the CODE area.
8482 This routine is in the runtime library
8483 \begin_inset LatexCommand \index{Runtime library}
8488 By default this routine returns 0, if this routine returns a non-zero value,
8489 the static & global variable initialization will be skipped and the function
8490 main will be invoked Other wise static & global variables will be initialized
8491 before the function main is invoked.
8494 _sdcc_external_startup()
8496 routine to your program to override the default if you need to setup hardware
8497 or perform some other critical operation prior to static & global variable
8501 Inline Assembler Code
8502 \begin_inset LatexCommand \index{Assembler routines}
8509 SDCC allows the use of in-line assembler with a few restriction as regards
8511 All labels defined within inline assembler code
8519 where nnnn is a number less than 100 (which implies a limit of utmost 100
8520 inline assembler labels
8528 It is strongly recommended that each assembly instruction (including labels)
8529 be placed in a separate line (as the example shows).
8543 \begin_inset LatexCommand \index{-\/-peep-asm}
8549 command line option is used, the inline assembler code will be passed through
8550 the peephole optimizer
8551 \begin_inset LatexCommand \index{Peephole optimizer}
8556 This might cause some unexpected changes in the inline assembler code.
8557 Please go through the peephole optimizer rules defined in file
8561 carefully before using this option.
8567 \begin_inset LatexCommand \index{\_asm}
8597 \begin_inset LatexCommand \index{\_endasm}
8604 The inline assembler code can contain any valid code understood by the assembler
8605 , this includes any assembler directives and comment lines.
8606 The compiler does not do any validation of the code within the
8616 Inline assembler code cannot reference any C-Labels, however it can reference
8618 \begin_inset LatexCommand \index{Labels}
8622 defined by the inline assembler, e.g.:
8647 ; some assembler code
8667 /* some more c code */
8669 clabel:\SpecialChar ~
8671 /* inline assembler cannot reference this label */
8683 $0003: ;label (can be reference by inline assembler only)
8695 /* some more c code */
8700 In other words inline assembly code can access labels defined in inline
8701 assembly within the scope of the function.
8702 The same goes the other way, ie.
8703 labels defines in inline assembly CANNOT be accessed by C statements.
8707 \begin_inset LatexCommand \index{int (16 bit)}
8712 \begin_inset LatexCommand \index{long (32 bit)}
8719 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
8720 multiplication and modulus operations are implemented by support routines.
8721 These support routines are all developed in ANSI-C to facilitate porting
8722 to other MCUs, although some model specific assembler optimizations are
8724 The following files contain the described routine, all of them can be found
8725 in <installdir>/share/sdcc/lib.
8731 \begin_inset Tabular
8732 <lyxtabular version="3" rows="11" columns="2">
8734 <column alignment="center" valignment="top" leftline="true" width="0">
8735 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
8736 <row topline="true" bottomline="true">
8737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8758 <row topline="true">
8759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8772 16 bit multiplication
8776 <row topline="true">
8777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8790 signed 16 bit division (calls _divuint)
8794 <row topline="true">
8795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8808 unsigned 16 bit division
8812 <row topline="true">
8813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8826 signed 16 bit modulus (calls _moduint)
8830 <row topline="true">
8831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8844 unsigned 16 bit modulus
8848 <row topline="true">
8849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8862 32 bit multiplication
8866 <row topline="true">
8867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8880 signed 32 division (calls _divulong)
8884 <row topline="true">
8885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8898 unsigned 32 division
8902 <row topline="true">
8903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8916 signed 32 bit modulus (calls _modulong)
8920 <row topline="true" bottomline="true">
8921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8934 unsigned 32 bit modulus
8947 Since they are compiled as
8952 \begin_inset LatexCommand \index{reentrant}
8957 \begin_inset LatexCommand \index{interrupt}
8961 service routines should not do any of the above operations.
8962 If this is unavoidable then the above routines will need to be compiled
8976 \begin_inset LatexCommand \index{-\/-stack-auto}
8982 option, after which the source program will have to be compiled with
8995 \begin_inset LatexCommand \index{-\/-int-long-rent}
9002 Notice that you don't have to call this routines directly.
9003 The compiler will use them automatically every time a integer operation
9007 Floating Point Support
9008 \begin_inset LatexCommand \index{Floating point support}
9015 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9016 floating point support routines are derived from gcc's floatlib.c and consists
9017 of the following routines:
9025 \begin_inset Tabular
9026 <lyxtabular version="3" rows="17" columns="2">
9028 <column alignment="center" valignment="top" leftline="true" width="0">
9029 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
9030 <row topline="true" bottomline="true">
9031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9057 <row topline="true">
9058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9089 add floating point numbers
9093 <row topline="true">
9094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9125 subtract floating point numbers
9129 <row topline="true">
9130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9161 divide floating point numbers
9165 <row topline="true">
9166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9197 multiply floating point numbers
9201 <row topline="true">
9202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9233 convert floating point to unsigned char
9237 <row topline="true">
9238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9269 convert floating point to signed char
9273 <row topline="true">
9274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9305 convert floating point to unsigned int
9309 <row topline="true">
9310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9341 convert floating point to signed int
9345 <row topline="true">
9346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9386 convert floating point to unsigned long
9390 <row topline="true">
9391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9422 convert floating point to signed long
9426 <row topline="true">
9427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9458 convert unsigned char to floating point
9462 <row topline="true">
9463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9494 convert char to floating point number
9498 <row topline="true">
9499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9530 convert unsigned int to floating point
9534 <row topline="true">
9535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9566 convert int to floating point numbers
9570 <row topline="true">
9571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9602 convert unsigned long to floating point number
9606 <row topline="true" bottomline="true">
9607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9638 convert long to floating point number
9651 Note if all these routines are used simultaneously the data space might
9653 For serious floating point usage it is strongly recommended that the large
9655 Also notice that you don't have to call this routines directly.
9656 The compiler will use them automatically every time a floating point operation
9661 \begin_inset LatexCommand \index{Memory model}
9666 \begin_inset LatexCommand \index{MCS51 memory}
9673 SDCC allows two memory models for MCS51 code, small and large.
9674 Modules compiled with different memory models should
9678 be combined together or the results would be unpredictable.
9679 The library routines supplied with the compiler are compiled as both small
9681 The compiled library modules are contained in separate directories as small
9682 and large so that you can link to either set.
9686 When the large model is used all variables declared without a storage class
9687 will be allocated into the external ram, this includes all parameters and
9688 local variables (for non-reentrant
9689 \begin_inset LatexCommand \index{reentrant}
9694 When the small model is used variables without storage class are allocated
9695 in the internal ram.
9698 Judicious usage of the processor specific storage classes
9699 \begin_inset LatexCommand \index{Storage class}
9703 and the 'reentrant' function type will yield much more efficient code,
9704 than using the large model.
9705 Several optimizations are disabled when the program is compiled using the
9706 large model, it is therefore strongly recommended that the small model
9707 be used unless absolutely required.
9711 \begin_inset LatexCommand \index{Memory model}
9716 \begin_inset LatexCommand \index{DS390 memory model}
9723 The only model supported is Flat 24
9724 \begin_inset LatexCommand \index{Flat 24 (memory model)}
9729 This generates code for the 24 bit contiguous addressing mode of the Dallas
9731 In this mode, up to four meg of external RAM or code space can be directly
9733 See the data sheets at www.dalsemi.com for further information on this part.
9737 In older versions of the compiler, this option was used with the MCS51 code
9743 Now, however, the '390 has it's own code generator, selected by the
9752 Note that the compiler does not generate any code to place the processor
9753 into 24 bitmode (although
9757 in the ds390 libraries will do that for you).
9763 \begin_inset LatexCommand \index{Tinibios (DS390)}
9767 , the boot loader or similar code must ensure that the processor is in 24
9768 bit contiguous addressing mode before calling the SDCC startup code.
9786 option, variables will by default be placed into the XDATA segment.
9791 Segments may be placed anywhere in the 4 meg address space using the usual
9803 Note that if any segments are located above 64K, the -r flag must be passed
9804 to the linker to generate the proper segment relocations, and the Intel
9805 HEX output format must be used.
9806 The -r flag can be passed to the linker by using the option
9810 on the sdcc command line.
9811 However, currently the linker can not handle code segments > 64k.
9814 Defines Created by the Compiler
9815 \begin_inset LatexCommand \index{Defines created by the compiler}
9822 The compiler creates the following #defines
9823 \begin_inset LatexCommand \index{\#defines}
9833 \begin_inset Tabular
9834 <lyxtabular version="3" rows="10" columns="2">
9836 <column alignment="center" valignment="top" leftline="true" width="0">
9837 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
9838 <row topline="true" bottomline="true">
9839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9860 <row topline="true">
9861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9867 \begin_inset LatexCommand \index{SDCC}
9874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9879 this Symbol is always defined
9883 <row topline="true">
9884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9890 \begin_inset LatexCommand \index{SDCC\_mcs51}
9895 \begin_inset LatexCommand \index{SDCC\_ds390}
9900 \begin_inset LatexCommand \index{SDCC\_z80}
9907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9912 depending on the model used (e.g.: -mds390
9916 <row topline="true">
9917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9923 \begin_inset LatexCommand \index{\_\_mcs51}
9928 \begin_inset LatexCommand \index{\_\_ds390}
9933 \begin_inset LatexCommand \index{\_\_z80}
9940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9945 depending on the model used (e.g.
9950 <row topline="true">
9951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9957 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
9964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9987 <row topline="true">
9988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9994 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
10001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10024 <row topline="true">
10025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10031 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
10038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10061 <row topline="true">
10062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10068 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
10075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10098 <row topline="true">
10099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10105 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
10112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10125 <row topline="true" bottomline="true">
10126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10132 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
10139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10161 Redirecting output on Windows Shells
10164 By default SDCC writes it's error messages to
10165 \begin_inset Quotes sld
10169 \begin_inset Quotes srd
10173 To force all messages to
10174 \begin_inset Quotes sld
10178 \begin_inset Quotes srd
10202 \begin_inset LatexCommand \index{-\/-use-stdout}
10207 Aditionaly, if you happen to have visual studio installed in your windows
10208 machine, you can use it to compile your sources using a custom build and
10224 \begin_inset LatexCommand \index{-\/-vc}
10229 Something like this should work:
10273 -model-large -c $(InputPath)
10276 SDCC Technical Data
10280 \begin_inset LatexCommand \index{Optimizations}
10287 SDCC performs a host of standard optimizations in addition to some MCU specific
10290 \layout Subsubsection
10292 Sub-expression Elimination
10293 \begin_inset LatexCommand \index{Subexpression elimination}
10300 The compiler does local and global common subexpression elimination, e.g.:
10311 will be translated to
10323 Some subexpressions are not as obvious as the above example, e.g.:
10333 In this case the address arithmetic a->b[i] will be computed only once;
10334 the equivalent code in C would be.
10346 The compiler will try to keep these temporary variables in registers.
10347 \layout Subsubsection
10349 Dead-Code Elimination
10350 \begin_inset LatexCommand \index{Dead-code elimination}
10369 i = 1; \SpecialChar ~
10374 global = 1;\SpecialChar ~
10387 global = 3;\SpecialChar ~
10398 int global; void f ()
10411 \layout Subsubsection
10414 \begin_inset LatexCommand \index{Copy propagation}
10470 Note: the dead stores created by this copy propagation will be eliminated
10471 by dead-code elimination.
10472 \layout Subsubsection
10475 \begin_inset LatexCommand \index{Loop optimization}
10482 Two types of loop optimizations are done by SDCC loop invariant lifting
10483 and strength reduction of loop induction variables.
10484 In addition to the strength reduction the optimizer marks the induction
10485 variables and the register allocator tries to keep the induction variables
10486 in registers for the duration of the loop.
10487 Because of this preference of the register allocator
10488 \begin_inset LatexCommand \index{Register allocation}
10492 , loop induction optimization causes an increase in register pressure, which
10493 may cause unwanted spilling of other temporary variables into the stack
10494 \begin_inset LatexCommand \index{stack}
10499 The compiler will generate a warning message when it is forced to allocate
10500 extra space either on the stack or data space.
10501 If this extra space allocation is undesirable then induction optimization
10502 can be eliminated either for the entire source file (with -
10512 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10514 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10527 for (i = 0 ; i < 100 ; i ++)
10541 for (i = 0; i < 100; i++)
10548 As mentioned previously some loop invariants are not as apparent, all static
10549 address computations are also moved out of the loop.
10554 \begin_inset LatexCommand \index{Strength reduction}
10558 , this optimization substitutes an expression by a cheaper expression:
10563 for (i=0;i < 100; i++)
10579 for (i=0;i< 100;i++) {
10585 ar[itemp1] = itemp2;
10602 The more expensive multiplication
10603 \begin_inset LatexCommand \index{Multiplication}
10607 is changed to a less expensive addition.
10608 \layout Subsubsection
10611 \begin_inset LatexCommand \index{Loop reversing}
10618 This optimization is done to reduce the overhead of checking loop boundaries
10619 for every iteration.
10620 Some simple loops can be reversed and implemented using a
10621 \begin_inset Quotes eld
10624 decrement and jump if not zero
10625 \begin_inset Quotes erd
10629 SDCC checks for the following criterion to determine if a loop is reversible
10630 (note: more sophisticated compilers use data-dependency analysis to make
10631 this determination, SDCC uses a more simple minded analysis).
10634 The 'for' loop is of the form
10640 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
10650 The <for body> does not contain
10651 \begin_inset Quotes eld
10655 \begin_inset Quotes erd
10659 \begin_inset Quotes erd
10665 All goto's are contained within the loop.
10668 No function calls within the loop.
10671 The loop control variable <sym> is not assigned any value within the loop
10674 The loop control variable does NOT participate in any arithmetic operation
10678 There are NO switch statements in the loop.
10679 \layout Subsubsection
10681 Algebraic Simplifications
10684 SDCC does numerous algebraic simplifications, the following is a small sub-set
10685 of these optimizations.
10690 i = j + 0 ; /* changed to */ i = j;
10692 i /= 2; /* changed to */ i >>= 1;
10694 i = j - j ; /* changed to */ i = 0;
10696 i = j / 1 ; /* changed to */ i = j;
10699 Note the subexpressions
10700 \begin_inset LatexCommand \index{Subexpression}
10704 given above are generally introduced by macro expansions or as a result
10705 of copy/constant propagation.
10706 \layout Subsubsection
10708 'switch' Statements
10709 \begin_inset LatexCommand \index{switch statement}
10716 SDCC changes switch statements to jump tables
10717 \begin_inset LatexCommand \index{jump tables}
10721 when the following conditions are true.
10725 The case labels are in numerical sequence, the labels need not be in order,
10726 and the starting number need not be one or zero.
10732 switch(i) {\SpecialChar ~
10763 case 4: ...\SpecialChar ~
10795 case 5: ...\SpecialChar ~
10827 case 3: ...\SpecialChar ~
10859 case 6: ...\SpecialChar ~
10927 Both the above switch statements will be implemented using a jump-table.
10931 The number of case labels is at least three, since it takes two conditional
10932 statements to handle the boundary conditions.
10935 The number of case labels is less than 84, since each label takes 3 bytes
10936 and a jump-table can be utmost 256 bytes long.
10939 Switch statements which have gaps in the numeric sequence or those that
10940 have more that 84 case labels can be split into more than one switch statement
10941 for efficient code generation, e.g.:
10991 If the above switch statement is broken down into two switch statements
11030 case 9: \SpecialChar ~
11046 case 12:\SpecialChar ~
11053 then both the switch statements will be implemented using jump-tables whereas
11054 the unmodified switch statement will not be.
11055 The pragma NOJTBOUND
11056 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11060 can be used to turn off checking the
11073 \layout Subsubsection
11075 Bit-shifting Operations
11076 \begin_inset LatexCommand \index{Bit shifting}
11083 Bit shifting is one of the most frequently used operation in embedded programmin
11085 SDCC tries to implement bit-shift operations in the most efficient way
11101 generates the following code:
11115 In general SDCC will never setup a loop if the shift count is known.
11147 Note that SDCC stores numbers in little-endian format (i.e.
11148 lowest order first).
11149 \layout Subsubsection
11152 \begin_inset LatexCommand \index{Bit rotation}
11159 A special case of the bit-shift operation is bit rotation, SDCC recognizes
11160 the following expression to be a left bit-rotation:
11170 i = ((i << 1) | (i >> 7));
11179 will generate the following code:
11191 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
11192 ns of this case will also be recognized as bit-rotation, i.e.:
11197 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
11198 \layout Subsubsection
11201 \begin_inset LatexCommand \index{Highest Order Bit}
11208 It is frequently required to obtain the highest order bit of an integral
11209 type (long, int, short or char types).
11210 SDCC recognizes the following expression to yield the highest order bit
11211 and generates optimized code for it, e.g.:
11231 hob = (gint >> 15) & 1;
11241 will generate the following code:
11274 000A E5*01\SpecialChar ~
11301 000C 23\SpecialChar ~
11332 000D 54 01\SpecialChar ~
11358 000F F5*02\SpecialChar ~
11386 Variations of this case however will
11391 It is a standard C expression, so I heartily recommend this be the only
11392 way to get the highest order bit, (it is portable).
11393 Of course it will be recognized even if it is embedded in other expressions,
11399 xyz = gint + ((gint >> 15) & 1);
11402 will still be recognized.
11403 \layout Subsubsection
11406 \begin_inset LatexCommand \index{Peephole optimizer}
11413 The compiler uses a rule based, pattern matching and re-writing mechanism
11414 for peep-hole optimization.
11419 a peep-hole optimizer by Christopher W.
11420 Fraser (cwfraser@microsoft.com).
11421 A default set of rules are compiled into the compiler, additional rules
11422 may be added with the
11435 \begin_inset LatexCommand \index{-\/-peep-file}
11442 The rule language is best illustrated with examples.
11466 The above rule will change the following assembly
11467 \begin_inset LatexCommand \index{Assembler routines}
11489 Note: All occurrences of a
11493 (pattern variable) must denote the same string.
11494 With the above rule, the assembly sequence:
11504 will remain unmodified.
11508 Other special case optimizations may be added by the user (via
11524 some variants of the 8051 MCU allow only
11533 The following two rules will change all
11552 replace { lcall %1 } by { acall %1 }
11554 replace { ljmp %1 } by { ajmp %1 }
11559 inline-assembler code
11561 is also passed through the peep hole optimizer, thus the peephole optimizer
11562 can also be used as an assembly level macro expander.
11563 The rules themselves are MCU dependent whereas the rule language infra-structur
11564 e is MCU independent.
11565 Peephole optimization rules for other MCU can be easily programmed using
11570 The syntax for a rule is as follows:
11575 rule := replace [ restart ] '{' <assembly sequence> '
11613 <assembly sequence> '
11631 '}' [if <functionName> ] '
11636 <assembly sequence> := assembly instruction (each instruction including
11637 labels must be on a separate line).
11641 The optimizer will apply to the rules one by one from the top in the sequence
11642 of their appearance, it will terminate when all rules are exhausted.
11643 If the 'restart' option is specified, then the optimizer will start matching
11644 the rules again from the top, this option for a rule is expensive (performance)
11645 , it is intended to be used in situations where a transformation will trigger
11646 the same rule again.
11647 An example of this (not a good one, it has side effects) is the following
11670 Note that the replace pattern cannot be a blank, but can be a comment line.
11671 Without the 'restart' option only the inner most 'pop' 'push' pair would
11672 be eliminated, i.e.:
11702 the restart option the rule will be applied again to the resulting code
11703 and then all the pop-push pairs will be eliminated to yield:
11713 A conditional function can be attached to a rule.
11714 Attaching rules are somewhat more involved, let me illustrate this with
11741 The optimizer does a look-up of a function name table defined in function
11746 in the source file SDCCpeeph.c, with the name
11751 If it finds a corresponding entry the function is called.
11752 Note there can be no parameters specified for these functions, in this
11757 is crucial, since the function
11761 expects to find the label in that particular variable (the hash table containin
11762 g the variable bindings is passed as a parameter).
11763 If you want to code more such functions, take a close look at the function
11764 labelInRange and the calling mechanism in source file SDCCpeeph.c.
11765 I know this whole thing is a little kludgey, but maybe some day we will
11766 have some better means.
11767 If you are looking at this file, you will also see the default rules that
11768 are compiled into the compiler, you can add your own rules in the default
11769 set there if you get tired of specifying the -
11783 \begin_inset LatexCommand \index{Pragmas}
11790 SDCC supports the following #pragma directives.
11794 \begin_inset LatexCommand \index{\#pragma SAVE}
11798 - this will save all current options to the SAVE/RESTORE stack.
11803 \begin_inset LatexCommand \index{\#pragma RESTORE}
11807 - will restore saved options from the last save.
11808 SAVEs & RESTOREs can be nested.
11809 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11810 RESTORE pulls current options from the stack.
11815 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11819 - will stop global subexpression elimination.
11823 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11827 - will stop loop induction optimizations.
11831 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11835 - will not generate code for boundary value checking, when switch statements
11836 are turned into jump-tables.
11840 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
11844 - the compiler will not overlay the parameters and local variables of a
11849 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
11853 - the compiler will not warn you anymore for obvious mistakes, you'r on
11858 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
11862 - Will not do loop reversal optimization
11866 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11870 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
11872 \begin_inset LatexCommand \index{push/pop}
11876 instruction in ISR function (using interrupt
11877 \begin_inset LatexCommand \index{interrupt}
11882 The directive should be placed immediately before the ISR function definition
11883 and it affects ALL ISR functions following it.
11884 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
11885 EXCLUDE\SpecialChar ~
11887 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11895 \begin_inset LatexCommand \index{\#pragma NOIV}
11899 - Do not generate interrupt vector table entries for all ISR functions
11900 defined after the pragma.
11901 This is useful in cases where the interrupt vector table must be defined
11902 manually, or when there is a secondary, manually defined interrupt vector
11904 for the autovector feature of the Cypress EZ-USB FX2).
11908 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11913 \begin_inset LatexCommand \index{function prologue}
11917 function1[,function2[,function3...]] - The compiler by default uses a caller
11918 saves convention for register saving across function calls, however this
11919 can cause unnecessary register pushing & popping when calling small functions
11920 from larger functions.
11921 This option can be used to switch off the register saving convention for
11922 the function names specified.
11923 The compiler will not save registers when calling these functions, extra
11924 code need to be manually inserted at the entry & exit for these functions
11925 to save & restore the registers used by these functions, this can SUBSTANTIALLY
11926 reduce code & improve run time performance of the generated code.
11927 In the future the compiler (with inter procedural analysis) may be able
11928 to determine the appropriate scheme to use for each function call.
11939 -callee-saves command line option is used, the function names specified
11940 in #pragma\SpecialChar ~
11942 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11946 is appended to the list of functions specified in the command line.
11949 The pragma's are intended to be used to turn-off certain optimizations which
11950 might cause the compiler to generate extra stack / data space to store
11951 compiler generated temporary variables.
11952 This usually happens in large functions.
11953 Pragma directives should be used as shown in the following example, they
11954 are used to control options & optimizations for a given function; pragmas
11955 should be placed before and/or after a function, placing pragma's inside
11956 a function body could have unpredictable results.
11962 \begin_inset LatexCommand \index{\#pragma SAVE}
11966 /* save the current settings */
11969 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11973 /* turnoff global subexpression elimination */
11975 #pragma NOINDUCTION
11976 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11980 /* turn off induction optimizations */
12003 \begin_inset LatexCommand \index{\#pragma RESTORE}
12007 /* turn the optimizations back on */
12010 The compiler will generate a warning message when extra space is allocated.
12011 It is strongly recommended that the SAVE and RESTORE pragma's be used when
12012 changing options for a function.
12017 <pending: this is messy and incomplete>
12022 Compiler support routines (_gptrget, _mulint etc)
12025 Stdclib functions (puts, printf, strcat etc)
12028 Math functions (sin, pow, sqrt etc)
12031 license statements for the libraries are missing
12034 Interfacing with Assembly Routines
12035 \begin_inset LatexCommand \index{Assembler routines}
12040 \layout Subsubsection
12042 Global Registers used for Parameter Passing
12043 \begin_inset LatexCommand \index{Parameter passing}
12050 The compiler always uses the global registers
12053 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12058 \begin_inset LatexCommand \index{B (register)}
12067 \begin_inset LatexCommand \index{ACC}
12073 to pass the first parameter to a routine.
12074 The second parameter onwards is either allocated on the stack (for reentrant
12085 -stack-auto is used) or in the internal / external ram (depending on the
12088 \layout Subsubsection
12090 Assembler Routine(non-reentrant
12091 \begin_inset LatexCommand \index{reentrant}
12096 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12103 In the following example the function c_func calls an assembler routine
12104 asm_func, which takes two parameters.
12109 extern int asm_func(unsigned char, unsigned char);
12113 int c_func (unsigned char i, unsigned char j)
12121 return asm_func(i,j);
12135 return c_func(10,9);
12140 The corresponding assembler function is:
12145 .globl _asm_func_PARM_2
12209 add a,_asm_func_PARM_2
12234 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12251 Note here that the return values are placed in 'dpl' - One byte return value,
12252 'dpl' LSB & 'dph' MSB for two byte values.
12253 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12254 b' & 'acc' for four byte values.
12257 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12258 the parameter number starting from 1, and counting from the left.
12259 The first parameter is passed in
12260 \begin_inset Quotes eld
12264 \begin_inset Quotes erd
12267 for One bye parameter,
12268 \begin_inset Quotes eld
12272 \begin_inset Quotes erd
12276 \begin_inset Quotes eld
12280 \begin_inset Quotes erd
12283 for three bytes and
12284 \begin_inset Quotes eld
12288 \begin_inset Quotes erd
12291 for four bytes, the variable name for the second parameter will be _<function_n
12296 Assemble the assembler routine with the following command:
12303 asx8051 -losg asmfunc.asm
12310 Then compile and link the assembler routine to the C source file with the
12318 sdcc cfunc.c asmfunc.rel
12319 \layout Subsubsection
12321 Assembler Routine(reentrant
12322 \begin_inset LatexCommand \index{reentrant}
12327 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12334 In this case the second parameter onwards will be passed on the stack, the
12335 parameters are pushed from right to left i.e.
12336 after the call the left most parameter will be on the top of the stack.
12337 Here is an example:
12342 extern int asm_func(unsigned char, unsigned char);
12346 int c_func (unsigned char i, unsigned char j) reentrant
12354 return asm_func(i,j);
12368 return c_func(10,9);
12373 The corresponding assembler routine is:
12479 The compiling and linking procedure remains the same, however note the extra
12480 entry & exit linkage required for the assembler code, _bp is the stack
12481 frame pointer and is used to compute the offset into the stack for parameters
12482 and local variables.
12486 \begin_inset LatexCommand \index{stack}
12491 \begin_inset LatexCommand \index{External stack}
12498 The external stack is located at the start of the external ram segment,
12499 and is 256 bytes in size.
12510 -xstack option is used to compile the program, the parameters and local
12511 variables of all reentrant functions are allocated in this area.
12512 This option is provided for programs with large stack space requirements.
12513 When used with the -
12523 -stack-auto option, all parameters and local variables are allocated on
12524 the external stack (note support libraries will need to be recompiled with
12528 The compiler outputs the higher order address byte of the external ram segment
12529 into PORT P2, therefore when using the External Stack option, this port
12530 MAY NOT be used by the application program.
12534 \begin_inset LatexCommand \index{ANSI-compliance}
12541 Deviations from the compliance:
12544 functions are not always reentrant.
12547 structures cannot be assigned values directly, cannot be passed as function
12548 parameters or assigned to each other and cannot be a return value from
12575 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
12586 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
12608 return rets;/* is invalid in SDCC although allowed in ANSI */
12615 \begin_inset LatexCommand \index{long long (not supported)}
12620 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
12628 \begin_inset LatexCommand \index{double (not supported)}
12632 ' precision floating point
12633 \begin_inset LatexCommand \index{Floating point support}
12640 No support for setjmp and longjmp (for now).
12644 \begin_inset LatexCommand \index{K\&R style}
12648 function declarations are NOT allowed.
12654 foo(i,j) /* this old style of function declarations */
12656 int i,j; /* are valid in ANSI but not valid in SDCC */
12671 functions declared as pointers must be dereferenced during the call.
12682 /* has to be called like this */
12684 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
12688 Cyclomatic Complexity
12689 \begin_inset LatexCommand \index{Cyclomatic complexity}
12696 Cyclomatic complexity of a function is defined as the number of independent
12697 paths the program can take during execution of the function.
12698 This is an important number since it defines the number test cases you
12699 have to generate to validate the function.
12700 The accepted industry standard for complexity number is 10, if the cyclomatic
12701 complexity reported by SDCC exceeds 10 you should think about simplification
12702 of the function logic.
12703 Note that the complexity level is not related to the number of lines of
12704 code in a function.
12705 Large functions can have low complexity, and small functions can have large
12711 SDCC uses the following formula to compute the complexity:
12716 complexity = (number of edges in control flow graph) - (number of nodes
12717 in control flow graph) + 2;
12721 Having said that the industry standard is 10, you should be aware that in
12722 some cases it be may unavoidable to have a complexity level of less than
12724 For example if you have switch statement with more than 10 case labels,
12725 each case label adds one to the complexity level.
12726 The complexity level is by no means an absolute measure of the algorithmic
12727 complexity of the function, it does however provide a good starting point
12728 for which functions you might look at for further optimization.
12734 Here are a few guidelines that will help the compiler generate more efficient
12735 code, some of the tips are specific to this compiler others are generally
12736 good programming practice.
12739 Use the smallest data type to represent your data-value.
12740 If it is known in advance that the value is going to be less than 256 then
12741 use an 'unsigned char' instead of a 'short' or 'int'.
12744 Use unsigned when it is known in advance that the value is not going to
12746 This helps especially if you are doing division or multiplication.
12749 NEVER jump into a LOOP.
12752 Declare the variables to be local whenever possible, especially loop control
12753 variables (induction).
12756 Since the compiler does not always do implicit integral promotion, the programme
12757 r should do an explicit cast when integral promotion is required.
12760 Reducing the size of division, multiplication & modulus operations can reduce
12761 code size substantially.
12762 Take the following code for example.
12768 foobar(unsigned int p1, unsigned char ch)
12776 unsigned char ch1 = p1 % ch ;
12787 For the modulus operation the variable ch will be promoted to unsigned int
12788 first then the modulus operation will be performed (this will lead to a
12789 call to support routine _moduint()), and the result will be casted to a
12791 If the code is changed to
12796 foobar(unsigned int p1, unsigned char ch)
12804 unsigned char ch1 = (unsigned char)p1 % ch ;
12815 It would substantially reduce the code generated (future versions of the
12816 compiler will be smart enough to detect such optimization opportunities).
12820 Notes on MCS51 memory
12821 \begin_inset LatexCommand \index{MCS51 memory}
12828 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12829 RAM memory which is structured as follows
12833 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12836 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12838 - Bytes 30-7F - 80 bytes for general purpose use.
12843 Additionally some members of the MCS51 family may have up to 128 bytes of
12844 additional, indirectly addressable, internal RAM memory (
12849 Furthermore, some chips may have some built in external memory (
12853 ) which should not be confused with the internal, directly addressable RAM
12859 Usually this built in
12863 memory has to be activated before using it (you can probably find this
12864 information on the datasheet of the microcontroller your are using).
12867 Normally SDCC will only use the first bank
12868 \begin_inset LatexCommand \index{bank}
12872 of registers (register bank 0), but it is possible to specify that other
12873 banks of registers should be used in interrupt
12874 \begin_inset LatexCommand \index{interrupt}
12879 By default, the compiler will place the stack after the last byte of allocated
12880 memory for variables.
12881 For example, if the first 2 banks of registers are used, and only four
12886 variables, it will position the base of the internal stack at address 20
12888 This implies that as the stack
12889 \begin_inset LatexCommand \index{stack}
12893 grows, it will use up the remaining register banks, and the 16 bytes used
12894 by the 128 bit variables, and 80 bytes for general purpose use.
12895 If any bit variables are used, the data variables will be placed after
12896 the byte holding the last bit variable.
12897 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12902 variables will be placed starting at address 0x22.
12914 \begin_inset LatexCommand \index{-\/-data-loc}
12918 to specify the start address of the
12932 -iram-size to specify the size of the total internal RAM (
12944 By default the 8051 linker will place the stack after the last byte of data
12957 \begin_inset LatexCommand \index{-\/-stack-loc}
12961 allows you to specify the start of the stack, i.e.
12962 you could start it after any data in the general purpose area.
12963 If your microcontroller has additional indirectly addressable internal
12968 ) you can place the stack on it.
12969 You may also need to use -
12980 \begin_inset LatexCommand \index{-\/-data-loc}
12984 to set the start address of the external RAM (
12999 \begin_inset LatexCommand \index{-\/-data-loc}
13003 to specify its size.
13004 Same goes for the code memory, using -
13015 \begin_inset LatexCommand \index{-\/-data-loc}
13030 \begin_inset LatexCommand \index{-\/-data-loc}
13035 If in doubt, don't specify any options and see if the resulting memory
13036 layout is appropriate, then you can adjust it.
13039 The 8051 linker generates two files with memory allocation information.
13040 The first, with extension .map shows all the variables and segments.
13041 The second with extension .mem shows the final memory layout.
13042 The linker will complaint either if memory segments overlap, there is not
13043 enough memory, or there is not enough space for stack.
13044 If you get any linking warnings and/or errors related to stack or segments
13045 allocation, take a look at either the .map or .mem files to find out what
13047 The .mem file may even suggest a solution to the problem.
13051 \begin_inset LatexCommand \index{Tools}
13055 included in the distribution
13061 \begin_inset Tabular
13062 <lyxtabular version="3" rows="12" columns="3">
13064 <column alignment="center" valignment="top" leftline="true" width="0pt">
13065 <column alignment="center" valignment="top" leftline="true" width="0pt">
13066 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13067 <row topline="true" bottomline="true">
13068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13093 <row topline="true">
13094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13107 Simulator for various architectures
13110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13119 <row topline="true">
13120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13133 header file conversion
13136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13141 sdcc/support/scripts
13145 <row topline="true">
13146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13159 header file conversion
13162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13167 sdcc/support/scripts
13171 <row topline="true">
13172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13206 <row topline="true">
13207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13241 <row topline="true">
13242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13276 <row topline="true">
13277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13311 <row topline="true">
13312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13346 <row topline="true">
13347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13381 <row topline="true">
13382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13416 <row topline="true" bottomline="true">
13417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13460 Related open source tools
13461 \begin_inset LatexCommand \index{Related tools}
13471 \begin_inset Tabular
13472 <lyxtabular version="3" rows="8" columns="3">
13474 <column alignment="center" valignment="top" leftline="true" width="0pt">
13475 <column alignment="block" valignment="top" leftline="true" width="30line%">
13476 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13477 <row topline="true" bottomline="true">
13478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13503 <row topline="true">
13504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13510 \begin_inset LatexCommand \index{gpsim}
13517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13531 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13539 <row topline="true">
13540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13562 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
13570 <row topline="true">
13571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13577 \begin_inset LatexCommand \index{srecord}
13584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13589 Object file conversion, checksumming, ...
13592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13598 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13606 <row topline="true">
13607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13613 \begin_inset LatexCommand \index{objdump}
13620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13625 Object file conversion, ...
13628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13633 Part of binutils (should be there anyway)
13637 <row topline="true">
13638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13644 \begin_inset LatexCommand \index{doxygen}
13651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13656 Source code documentation system
13659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13665 \begin_inset LatexCommand \url{http://www.doxygen.org}
13673 <row topline="true">
13674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13680 \begin_inset LatexCommand \index{splint}
13687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13692 Statically checks c sources
13695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13701 \begin_inset LatexCommand \url{http://www.splint.org}
13709 <row topline="true" bottomline="true">
13710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13716 \begin_inset LatexCommand \index{ddd}
13723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13728 Debugger, serves nicely as GUI to sdcdb
13729 \begin_inset LatexCommand \index{sdcdb}
13739 (sdcdb and ddd are available for Unix only)
13745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13751 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13768 Related documentation / recommended reading
13774 \begin_inset Tabular
13775 <lyxtabular version="3" rows="5" columns="3">
13777 <column alignment="center" valignment="top" leftline="true" width="0pt">
13778 <column alignment="block" valignment="top" leftline="true" width="30line%">
13779 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13780 <row topline="true" bottomline="true">
13781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13806 <row topline="true">
13807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13822 Advanced Compiler Design and Implementation
13825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13834 <row topline="true">
13835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13858 \begin_inset LatexCommand \index{C Reference card}
13865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13871 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13879 <row topline="true">
13880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13885 test_suite_spec.pdf
13888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13893 sdcc regression test
13894 \begin_inset LatexCommand \index{Regression test}
13901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13910 <row topline="true" bottomline="true">
13911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13942 sdcc internal documentation
13945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13963 Retargetting for other MCUs.
13966 The issues for retargetting the compiler are far too numerous to be covered
13968 What follows is a brief description of each of the seven phases of the
13969 compiler and its MCU dependency.
13972 Parsing the source and building the annotated parse tree.
13973 This phase is largely MCU independent (except for the language extensions).
13974 Syntax & semantic checks are also done in this phase, along with some initial
13975 optimizations like back patching labels and the pattern matching optimizations
13976 like bit-rotation etc.
13979 The second phase involves generating an intermediate code which can be easy
13980 manipulated during the later phases.
13981 This phase is entirely MCU independent.
13982 The intermediate code generation assumes the target machine has unlimited
13983 number of registers, and designates them with the name iTemp.
13984 The compiler can be made to dump a human readable form of the code generated
13998 This phase does the bulk of the standard optimizations and is also MCU independe
14000 This phase can be broken down into several sub-phases:
14004 Break down intermediate code (iCode) into basic blocks.
14006 Do control flow & data flow analysis on the basic blocks.
14008 Do local common subexpression elimination, then global subexpression elimination
14010 Dead code elimination
14014 If loop optimizations caused any changes then do 'global subexpression eliminati
14015 on' and 'dead code elimination' again.
14018 This phase determines the live-ranges; by live range I mean those iTemp
14019 variables defined by the compiler that still survive after all the optimization
14021 Live range analysis
14022 \begin_inset LatexCommand \index{Live range analysis}
14026 is essential for register allocation, since these computation determines
14027 which of these iTemps will be assigned to registers, and for how long.
14030 Phase five is register allocation.
14031 There are two parts to this process.
14035 The first part I call 'register packing' (for lack of a better term).
14036 In this case several MCU specific expression folding is done to reduce
14041 The second part is more MCU independent and deals with allocating registers
14042 to the remaining live ranges.
14043 A lot of MCU specific code does creep into this phase because of the limited
14044 number of index registers available in the 8051.
14047 The Code generation phase is (unhappily), entirely MCU dependent and very
14048 little (if any at all) of this code can be reused for other MCU.
14049 However the scheme for allocating a homogenized assembler operand for each
14050 iCode operand may be reused.
14053 As mentioned in the optimization section the peep-hole optimizer is rule
14054 based system, which can reprogrammed for other MCUs.
14058 \begin_inset LatexCommand \index{sdcdb}
14062 - Source Level Debugger
14063 \begin_inset LatexCommand \index{Debugger}
14070 SDCC is distributed with a source level debugger.
14071 The debugger uses a command line interface, the command repertoire of the
14072 debugger has been kept as close to gdb
14073 \begin_inset LatexCommand \index{gdb}
14077 (the GNU debugger) as possible.
14078 The configuration and build process is part of the standard compiler installati
14079 on, which also builds and installs the debugger in the target directory
14080 specified during configuration.
14081 The debugger allows you debug BOTH at the C source and at the ASM source
14083 Sdcdb is available on Unix platforms only.
14086 Compiling for Debugging
14089 The \SpecialChar \-
14091 debug option must be specified for all files for which debug information
14092 is to be generated.
14093 The complier generates a .adb file for each of these files.
14094 The linker creates the .cdb file from the .adb files and the address information.
14095 This .cdb is used by the debugger.
14098 How the Debugger Works
14111 -debug option is specified the compiler generates extra symbol information
14112 some of which are put into the the assembler source and some are put into
14114 Then the linker creates the .cdb file from the individual .adb files with
14115 the address information for the symbols.
14116 The debugger reads the symbolic information generated by the compiler &
14117 the address information generated by the linker.
14118 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
14119 execution is controlled by the debugger.
14120 When a command is issued for the debugger, it translates it into appropriate
14121 commands for the simulator.
14124 Starting the Debugger
14127 The debugger can be started using the following command line.
14128 (Assume the file you are debugging has the file name foo).
14142 The debugger will look for the following files.
14145 foo.c - the source file.
14148 foo.cdb - the debugger symbol information file.
14151 foo.ihx - the Intel hex format
14152 \begin_inset LatexCommand \index{Intel hex format}
14159 Command Line Options.
14172 -directory=<source file directory> this option can used to specify the directory
14174 The debugger will look into the directory list specified for source, cdb
14176 The items in the directory list must be separated by ':', e.g.
14177 if the source files can be in the directories /home/src1 and /home/src2,
14188 -directory option should be -
14198 -directory=/home/src1:/home/src2.
14199 Note there can be no spaces in the option.
14203 -cd <directory> - change to the <directory>.
14206 -fullname - used by GUI front ends.
14209 -cpu <cpu-type> - this argument is passed to the simulator please see the
14210 simulator docs for details.
14213 -X <Clock frequency > this options is passed to the simulator please see
14214 the simulator docs for details.
14217 -s <serial port file> passed to simulator see the simulator docs for details.
14220 -S <serial in,out> passed to simulator see the simulator docs for details.
14226 As mention earlier the command interface for the debugger has been deliberately
14227 kept as close the GNU debugger gdb, as possible.
14228 This will help the integration with existing graphical user interfaces
14229 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14230 \layout Subsubsection
14232 break [line | file:line | function | file:function]
14235 Set breakpoint at specified line or function:
14244 sdcdb>break foo.c:100
14246 sdcdb>break funcfoo
14248 sdcdb>break foo.c:funcfoo
14249 \layout Subsubsection
14251 clear [line | file:line | function | file:function ]
14254 Clear breakpoint at specified line or function:
14263 sdcdb>clear foo.c:100
14265 sdcdb>clear funcfoo
14267 sdcdb>clear foo.c:funcfoo
14268 \layout Subsubsection
14273 Continue program being debugged, after breakpoint.
14274 \layout Subsubsection
14279 Execute till the end of the current function.
14280 \layout Subsubsection
14285 Delete breakpoint number 'n'.
14286 If used without any option clear ALL user defined break points.
14287 \layout Subsubsection
14289 info [break | stack | frame | registers ]
14292 info break - list all breakpoints
14295 info stack - show the function call stack.
14298 info frame - show information about the current execution frame.
14301 info registers - show content of all registers.
14302 \layout Subsubsection
14307 Step program until it reaches a different source line.
14308 \layout Subsubsection
14313 Step program, proceeding through subroutine calls.
14314 \layout Subsubsection
14319 Start debugged program.
14320 \layout Subsubsection
14325 Print type information of the variable.
14326 \layout Subsubsection
14331 print value of variable.
14332 \layout Subsubsection
14337 load the given file name.
14338 Note this is an alternate method of loading file for debugging.
14339 \layout Subsubsection
14344 print information about current frame.
14345 \layout Subsubsection
14350 Toggle between C source & assembly source.
14351 \layout Subsubsection
14353 ! simulator command
14356 Send the string following '!' to the simulator, the simulator response is
14358 Note the debugger does not interpret the command being sent to the simulator,
14359 so if a command like 'go' is sent the debugger can loose its execution
14360 context and may display incorrect values.
14361 \layout Subsubsection
14368 My name is Bobby Brown"
14371 Interfacing with XEmacs
14372 \begin_inset LatexCommand \index{XEmacs}
14377 \begin_inset LatexCommand \index{Emacs}
14384 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14385 sdcdb.el and sdcdbsrc.el.
14386 These two files can be found in the $(prefix)/bin directory after the installat
14388 These files need to be loaded into XEmacs for the interface to work.
14389 This can be done at XEmacs startup time by inserting the following into
14390 your '.xemacs' file (which can be found in your HOME directory):
14396 (load-file sdcdbsrc.el)
14402 .xemacs is a lisp file so the () around the command is REQUIRED.
14403 The files can also be loaded dynamically while XEmacs is running, set the
14404 environment variable 'EMACSLOADPATH' to the installation bin directory
14405 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14406 To start the interface enter the following command:
14420 You will prompted to enter the file name to be debugged.
14425 The command line options that are passed to the simulator directly are bound
14426 to default values in the file sdcdbsrc.el.
14427 The variables are listed below, these values maybe changed as required.
14430 sdcdbsrc-cpu-type '51
14433 sdcdbsrc-frequency '11059200
14436 sdcdbsrc-serial nil
14439 The following is a list of key mapping for the debugger interface.
14447 ;; Current Listing ::
14449 ;;key\SpecialChar ~
14464 binding\SpecialChar ~
14488 ;;---\SpecialChar ~
14503 ------\SpecialChar ~
14543 sdcdb-next-from-src\SpecialChar ~
14569 sdcdb-back-from-src\SpecialChar ~
14595 sdcdb-cont-from-src\SpecialChar ~
14605 SDCDB continue command
14621 sdcdb-step-from-src\SpecialChar ~
14647 sdcdb-whatis-c-sexp\SpecialChar ~
14657 SDCDB ptypecommand for data at
14721 sdcdbsrc-delete\SpecialChar ~
14735 SDCDB Delete all breakpoints if no arg
14783 given or delete arg (C-u arg x)
14799 sdcdbsrc-frame\SpecialChar ~
14814 SDCDB Display current frame if no arg,
14863 given or display frame arg
14928 sdcdbsrc-goto-sdcdb\SpecialChar ~
14938 Goto the SDCDB output buffer
14954 sdcdb-print-c-sexp\SpecialChar ~
14965 SDCDB print command for data at
15029 sdcdbsrc-goto-sdcdb\SpecialChar ~
15039 Goto the SDCDB output buffer
15055 sdcdbsrc-mode\SpecialChar ~
15071 Toggles Sdcdbsrc mode (turns it off)
15075 ;; C-c C-f\SpecialChar ~
15083 sdcdb-finish-from-src\SpecialChar ~
15091 SDCDB finish command
15095 ;; C-x SPC\SpecialChar ~
15103 sdcdb-break\SpecialChar ~
15121 Set break for line with point
15123 ;; ESC t\SpecialChar ~
15133 sdcdbsrc-mode\SpecialChar ~
15149 Toggle Sdcdbsrc mode
15151 ;; ESC m\SpecialChar ~
15161 sdcdbsrc-srcmode\SpecialChar ~
15185 The Z80 and gbz80 port
15188 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
15189 The port is incomplete - long support is incomplete (mul, div and mod are
15190 unimplemented), and both float and bitfield support is missing.
15191 Apart from that the code generated is correct.
15194 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
15195 The stack frame is similar to that generated by the IAR Z80 compiler.
15196 IX is used as the base pointer, HL is used as a temporary register, and
15197 BC and DE are available for holding variables.
15198 IY is currently unused.
15199 Return values are stored in HL.
15200 One bad side effect of using IX as the base pointer is that a functions
15201 stack frame is limited to 127 bytes - this will be fixed in a later version.
15205 \begin_inset LatexCommand \index{Support}
15212 SDCC has grown to be a large project.
15213 The compiler alone (without the preprocessor, assembler and linker) is
15214 about 40,000 lines of code (blank stripped).
15215 The open source nature of this project is a key to its continued growth
15217 You gain the benefit and support of many active software developers and
15219 Is SDCC perfect? No, that's why we need your help.
15220 The developers take pride in fixing reported bugs.
15221 You can help by reporting the bugs and helping other SDCC users.
15222 There are lots of ways to contribute, and we encourage you to take part
15223 in making SDCC a great software package.
15227 The SDCC project is hosted on the sdcc sourceforge site at
15228 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
15233 You'll find the complete set of mailing lists
15234 \begin_inset LatexCommand \index{Mailing list}
15238 , forums, bug reporting system, patch submission
15239 \begin_inset LatexCommand \index{Patch submission}
15244 \begin_inset LatexCommand \index{download}
15248 area and cvs code repository
15249 \begin_inset LatexCommand \index{cvs code repository}
15257 \begin_inset LatexCommand \index{Bugs}
15262 \begin_inset LatexCommand \index{Reporting bugs}
15269 The recommended way of reporting bugs is using the infrastructure of the
15271 You can follow the status of bug reports there and have an overview about
15275 Bug reports are automatically forwarded to the developer mailing list and
15276 will be fixed ASAP.
15277 When reporting a bug, it is very useful to include a small test program
15278 (the smaller the better) which reproduces the problem.
15279 If you can isolate the problem by looking at the generated assembly code,
15280 this can be very helpful.
15281 Compiling your program with the -
15292 \begin_inset LatexCommand \index{-\/-dumpall}
15296 option can sometimes be useful in locating optimization problems.
15297 When reporting a bug please maker sure you:
15300 Attach the code you are compiling with SDCC.
15304 Specify the exact command you use to run SDCC, or attach your Makefile.
15308 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15313 Provide an exact copy of any error message or incorrect output.
15317 Put something meaningful in the subject of your message.
15320 Please attempt to include these 5 important parts, as applicable, in all
15321 requests for support or when reporting any problems or bugs with SDCC.
15322 Though this will make your message lengthy, it will greatly improve your
15323 chance that SDCC users and developers will be able to help you.
15324 Some SDCC developers are frustrated by bug reports without code provided
15325 that they can use to reproduce and ultimately fix the problem, so please
15326 be sure to provide sample code if you are reporting a bug!
15329 Please have a short check that you are using a recent version of SDCC and
15330 the bug is not yet known.
15331 This is the link for reporting bugs:
15332 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15339 Requesting Features
15340 \begin_inset LatexCommand \index{Feature request}
15345 \begin_inset LatexCommand \index{Requesting features}
15352 Like bug reports feature requests are forwarded to the developer mailing
15354 This is the link for requesting features:
15355 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15365 These links should take you directly to the
15366 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15376 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15377 automated messages (mid 2003)
15381 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15385 , lists and forums are archived so if you are lucky someone already had
15390 \begin_inset LatexCommand \index{Changelog}
15397 You can follow the status of the cvs version
15398 \begin_inset LatexCommand \index{version}
15402 of SDCC by watching the file
15403 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15407 in the cvs-repository.
15411 \begin_inset LatexCommand \index{Release policy}
15418 Historically there often were long delays between official releases and
15419 the sourceforge download area tends to get not updated at all.
15420 Current excuses might refer to problems with live range analysis, but if
15421 this is fixed, the next problem rising is that another excuse will have
15423 Kidding aside, we have to get better there! On the other hand there are
15424 daily snapshots available at
15425 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15429 , and you can always built the very last version (hopefully with many bugs
15430 fixed, and features added) from the source code available at
15431 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15439 \begin_inset LatexCommand \index{Examples}
15446 You'll find some small examples in the directory sdcc/device/examples/
15449 Maybe we should include some links to real world applications.
15450 Preferably pointer to pointers (one for each architecture) so this stays
15455 \begin_inset LatexCommand \index{Quality control}
15462 The compiler is passed through nightly compile and build checks.
15468 \begin_inset LatexCommand \index{Regression test}
15472 check that SDCC itself compiles flawlessly on several platforms and checks
15473 the quality of the code generated by SDCC by running the code through simulator
15475 There is a separate document
15478 \begin_inset LatexCommand \index{Test suite}
15487 You'll find the test code in the directory
15489 sdcc/support/regression
15492 You can run these tests manually by running
15496 in this directory (or f.e.
15501 if you don't want to run the complete tests).
15502 The test code might also be interesting if you want to look for examples
15503 \begin_inset LatexCommand \index{Examples}
15507 checking corner cases of SDCC or if you plan to submit patches
15508 \begin_inset LatexCommand \index{Patch submission}
15515 The pic port uses a different set of regression tests, you'll find them
15518 sdcc/src/regression
15524 \begin_inset LatexCommand \index{Compiler internals}
15531 The anatomy of the compiler
15536 This is an excerpt from an article published in Circuit Cellar Magazine
15538 It's a little outdated (the compiler is much more efficient now and user/develo
15539 per friendly), but pretty well exposes the guts of it all.
15545 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
15546 It is fairly easy to retarget for other 8-bit MCU.
15547 Here we take a look at some of the internals of the compiler.
15552 \begin_inset LatexCommand \index{Parsing}
15559 Parsing the input source file and creating an AST (Annotated Syntax Tree
15560 \begin_inset LatexCommand \index{Annotated syntax tree}
15565 This phase also involves propagating types (annotating each node of the
15566 parse tree with type information) and semantic analysis.
15567 There are some MCU specific parsing rules.
15568 For example the storage classes, the extended storage classes are MCU specific
15569 while there may be a xdata storage class for 8051 there is no such storage
15570 class for z80 or Atmel AVR.
15571 SDCC allows MCU specific storage class extensions, i.e.
15572 xdata will be treated as a storage class specifier when parsing 8051 C
15573 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
15578 \begin_inset LatexCommand \index{iCode}
15585 Intermediate code generation.
15586 In this phase the AST is broken down into three-operand form (iCode).
15587 These three operand forms are represented as doubly linked lists.
15588 ICode is the term given to the intermediate form generated by the compiler.
15589 ICode example section shows some examples of iCode generated for some simple
15590 C source functions.
15594 \begin_inset LatexCommand \index{Optimizations}
15601 Bulk of the target independent optimizations is performed in this phase.
15602 The optimizations include constant propagation, common sub-expression eliminati
15603 on, loop invariant code movement, strength reduction of loop induction variables
15604 and dead-code elimination.
15607 Live range analysis
15608 \begin_inset LatexCommand \index{Live range analysis}
15615 During intermediate code generation phase, the compiler assumes the target
15616 machine has infinite number of registers and generates a lot of temporary
15618 The live range computation determines the lifetime of each of these compiler-ge
15619 nerated temporaries.
15620 A picture speaks a thousand words.
15621 ICode example sections show the live range annotations for each of the
15623 It is important to note here, each iCode is assigned a number in the order
15624 of its execution in the function.
15625 The live ranges are computed in terms of these numbers.
15626 The from number is the number of the iCode which first defines the operand
15627 and the to number signifies the iCode which uses this operand last.
15630 Register Allocation
15631 \begin_inset LatexCommand \index{Register allocation}
15638 The register allocation determines the type and number of registers needed
15640 In most MCUs only a few registers can be used for indirect addressing.
15641 In case of 8051 for example the registers R0 & R1 can be used to indirectly
15642 address the internal ram and DPTR to indirectly address the external ram.
15643 The compiler will try to allocate the appropriate register to pointer variables
15645 ICode example section shows the operands annotated with the registers assigned
15647 The compiler will try to keep operands in registers as much as possible;
15648 there are several schemes the compiler uses to do achieve this.
15649 When the compiler runs out of registers the compiler will check to see
15650 if there are any live operands which is not used or defined in the current
15651 basic block being processed, if there are any found then it will push that
15652 operand and use the registers in this block, the operand will then be popped
15653 at the end of the basic block.
15657 There are other MCU specific considerations in this phase.
15658 Some MCUs have an accumulator; very short-lived operands could be assigned
15659 to the accumulator instead of general-purpose register.
15665 Figure II gives a table of iCode operations supported by the compiler.
15666 The code generation involves translating these operations into corresponding
15667 assembly code for the processor.
15668 This sounds overly simple but that is the essence of code generation.
15669 Some of the iCode operations are generated on a MCU specific manner for
15670 example, the z80 port does not use registers to pass parameters so the
15671 SEND and RECV iCode operations will not be generated, and it also does
15672 not support JUMPTABLES.
15679 <Where is Figure II ?>
15683 \begin_inset LatexCommand \index{iCode}
15690 This section shows some details of iCode.
15691 The example C code does not do anything useful; it is used as an example
15692 to illustrate the intermediate code generated by the compiler.
15704 /* This function does nothing useful.
15711 for the purpose of explaining iCode */
15714 short function (data int *x)
15722 short i=10; /* dead initialization eliminated */
15727 short sum=10; /* dead initialization eliminated */
15740 while (*x) *x++ = *p++;
15754 /* compiler detects i,j to be induction variables */
15758 for (i = 0, j = 10 ; i < 10 ; i++, j
15784 mul += i * 3; /* this multiplication remains */
15790 gint += j * 3;/* this multiplication changed to addition */
15804 In addition to the operands each iCode contains information about the filename
15805 and line it corresponds to in the source file.
15806 The first field in the listing should be interpreted as follows:
15811 Filename(linenumber: iCode Execution sequence number : ICode hash table
15812 key : loop depth of the iCode).
15817 Then follows the human readable form of the ICode operation.
15818 Each operand of this triplet form can be of three basic types a) compiler
15819 generated temporary b) user defined variable c) a constant value.
15820 Note that local variables and parameters are replaced by compiler generated
15823 \begin_inset LatexCommand \index{Live range analysis}
15827 are computed only for temporaries (i.e.
15828 live ranges are not computed for global variables).
15830 \begin_inset LatexCommand \index{Register allocation}
15834 are allocated for temporaries only.
15835 Operands are formatted in the following manner:
15840 Operand Name [lr live-from : live-to ] { type information } [ registers
15846 As mentioned earlier the live ranges are computed in terms of the execution
15847 sequence number of the iCodes, for example
15849 the iTemp0 is live from (i.e.
15850 first defined in iCode with execution sequence number 3, and is last used
15851 in the iCode with sequence number 5).
15852 For induction variables such as iTemp21 the live range computation extends
15853 the lifetime from the start to the end of the loop.
15855 The register allocator used the live range information to allocate registers,
15856 the same registers may be used for different temporaries if their live
15857 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
15858 iTemp17 since their live ranges do not overlap.
15859 In addition the allocator also takes into consideration the type and usage
15860 of a temporary, for example itemp6 is a pointer to near space and is used
15861 as to fetch data from (i.e.
15862 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
15863 Some short lived temporaries are allocated to special registers which have
15864 meaning to the code generator e.g.
15865 iTemp13 is allocated to a pseudo register CC which tells the back end that
15866 the temporary is used only for a conditional jump the code generation makes
15867 use of this information to optimize a compare and jump ICode.
15869 There are several loop optimizations
15870 \begin_inset LatexCommand \index{Loop optimization}
15874 performed by the compiler.
15875 It can detect induction variables iTemp21(i) and iTemp23(j).
15876 Also note the compiler does selective strength reduction
15877 \begin_inset LatexCommand \index{Strength reduction}
15882 the multiplication of an induction variable in line 18 (gint = j * 3) is
15883 changed to addition, a new temporary iTemp17 is allocated and assigned
15884 a initial value, a constant 3 is then added for each iteration of the loop.
15885 The compiler does not change the multiplication
15886 \begin_inset LatexCommand \index{Multiplication}
15890 in line 17 however since the processor does support an 8 * 8 bit multiplication.
15892 Note the dead code elimination
15893 \begin_inset LatexCommand \index{Dead-code elimination}
15897 optimization eliminated the dead assignments in line 7 & 8 to I and sum
15905 Sample.c (5:1:0:0) _entry($9) :
15910 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
15915 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
15920 Sample.c(11:4:53:0) preHeaderLbl0($11) :
15925 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
15931 Sample.c(11:6:5:1) _whilecontinue_0($1) :
15936 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
15942 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15947 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
15953 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
15959 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
15965 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
15971 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
15972 * int}[r0] + 0x2 {short}
15977 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
15982 Sample.c(11:17:21:0)_whilebreak_0($3) :
15987 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15992 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15997 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16002 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16007 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16012 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16017 Sample.c(15:24:26:1)_forcond_0($4) :
16022 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16028 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16033 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16034 + ITemp21 [lr21:38]{short}[r4]
16039 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16045 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16046 + iTemp15 [lr29:30]{short}[r1]
16051 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16057 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16063 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16069 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16075 Sample.c(19:38:47:1) goto _forcond_0($4)
16080 Sample.c(19:39:48:0)_forbreak_0($7) :
16085 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16086 + ITemp11 [lr19:40]{short}[r3]
16091 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16096 Sample.c(20:42:51:0)_return($8) :
16101 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16107 Finally the code generated for this function:
16148 ; ----------------------------------------------
16153 ; function function
16158 ; ----------------------------------------------
16168 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16180 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16192 ;_whilecontinue_0($1) :
16202 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16207 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16266 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16285 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16332 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16372 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16398 ; iTemp6 [lr5:16]{_near * int}[r0] =
16403 ; iTemp6 [lr5:16]{_near * int}[r0] +
16420 ; goto _whilecontinue_0($1)
16432 ; _whilebreak_0($3) :
16442 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16454 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16466 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16478 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16497 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16526 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
16531 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16576 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
16581 ; iTemp21 [lr21:38]{short}[r4]
16607 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
16640 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
16645 ; iTemp15 [lr29:30]{short}[r1]
16664 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
16711 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
16758 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
16770 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
16784 cjne r5,#0xff,00104$
16796 ; goto _forcond_0($4)
16808 ; _forbreak_0($7) :
16818 ; ret iTemp24 [lr40:41]{short}
16861 A few words about basic block successors, predecessors and dominators
16864 Successors are basic blocks
16865 \begin_inset LatexCommand \index{Basic blocks}
16869 that might execute after this basic block.
16871 Predecessors are basic blocks that might execute before reaching this basic
16874 Dominators are basic blocks that WILL execute before reaching this basic
16900 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
16903 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
16906 c) domVect of [BB4] = BB1 ...
16907 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
16915 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
16925 Thanks to all the other volunteer developers who have helped with coding,
16926 testing, web-page creation, distribution sets, etc.
16927 You know who you are :-)
16934 This document was initially written by Sandeep Dutta
16937 All product names mentioned herein may be trademarks
16938 \begin_inset LatexCommand \index{Trademarks}
16942 of their respective companies.
16949 To avoid confusion, the installation and building options for sdcc itself
16950 (chapter 2) are not part of the index.
16954 \begin_inset LatexCommand \printindex{}