1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
6 pdftitle={SDCC Compiler User Guide},
7 pdfauthor={SDCC development team},
8 pdfsubject={installation, user manual},
9 pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
10 embedded, GPL, HC08, manual, mcs51, PIC, Z80},
12 linkcolor=blue] {hyperref}
16 \emergencystretch=30pt
21 \inputencoding default
24 \paperfontsize default
26 \papersize letterpaper
31 \use_numerical_citations 0
32 \paperorientation portrait
39 \paragraph_separation indent
41 \quotes_language swedish
49 Please note: double dashed longoptions (e.g.
50 --version) are written this way: -
64 three consecutive dashes simply result in a long resp.
68 Architecture specific stuff (like memory models, code examples) should maybe
72 into seperate sections/chapters/appendices (it is hard to document PIC or
76 a 8051 centered document) - for now simply add.
79 SDCC Compiler User Guide
93 The above strings enclosed in $ are automatically updated by cvs
97 \begin_inset LatexCommand \tableofcontents{}
130 ompiler) is a Freeware, retargettable, optimizing ANSI-C compiler by
134 designed for 8 bit Microprocessors.
135 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
137 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
141 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
142 It can be retargetted for other microprocessors, support for Microchip
143 PIC, Atmel AVR is under development.
144 The entire source code for the compiler is distributed under GPL.
145 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
146 SDCC has extensive language extensions suitable for utilizing various microcont
147 rollers and underlying hardware effectively.
152 In addition to the MCU specific optimizations SDCC also does a host of standard
156 global sub expression elimination,
159 loop optimizations (loop invariant, strength reduction of induction variables
163 constant folding & propagation,
169 dead code elimination
179 For the back-end SDCC uses a global register allocation scheme which should
180 be well suited for other 8 bit MCUs.
185 The peep hole optimizer uses a rule based substitution mechanism which is
191 Supported data-types are:
194 char (8 bits, 1 byte),
197 short and int (16 bits, 2 bytes),
200 long (32 bit, 4 bytes)
207 The compiler also allows
209 inline assembler code
211 to be embedded anywhere in a function.
212 In addition, routines developed in assembly can also be called.
216 SDCC also provides an option (-
226 -cyclomatic) to report the relative complexity of a function.
227 These functions can then be further optimized, or hand coded in assembly
233 SDCC also comes with a companion source level debugger SDCDB, the debugger
234 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
239 The latest version can be downloaded from
240 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
250 Please note: the compiler will probably always be some steps ahead of this
255 \begin_inset LatexCommand \index{Status of documentation}
265 Obviously this has pros and cons
274 All packages used in this compiler system are
282 ; source code for all the sub-packages (pre-processor, assemblers, linkers
283 etc) is distributed with the package.
284 This documentation is maintained using a freeware word processor (LyX).
286 This program is free software; you can redistribute it and/or modify it
287 under the terms of the GNU General Public License
288 \begin_inset LatexCommand \index{GNU General Public License, GPL}
292 as published by the Free Software Foundation; either version 2, or (at
293 your option) any later version.
294 This program is distributed in the hope that it will be useful, but WITHOUT
295 ANY WARRANTY; without even the implied warranty
296 \begin_inset LatexCommand \index{warranty}
300 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
301 See the GNU General Public License for more details.
302 You should have received a copy of the GNU General Public License along
303 with this program; if not, write to the Free Software Foundation, 59 Temple
304 Place - Suite 330, Boston, MA 02111-1307, USA.
305 In other words, you are welcome to use, share and improve this program.
306 You are forbidden to forbid anyone else to use, share and improve what
308 Help stamp out software-hoarding!
311 Typographic conventions
312 \begin_inset LatexCommand \index{Typographic conventions}
319 Throughout this manual, we will use the following convention.
320 Commands you have to type in are printed in
328 Code samples are printed in
333 Interesting items and new terms are printed in
338 Compatibility with previous versions
341 This version has numerous bug fixes compared with the previous version.
342 But we also introduced some incompatibilities with older versions.
343 Not just for the fun of it, but to make the compiler more stable, efficient
345 \begin_inset LatexCommand \index{ANSI-compliance}
350 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
354 for ANSI-Compliance).
360 short is now equivalent to int (16 bits), it used to be equivalent to char
361 (8 bits) which is not ANSI compliant
364 the default directory for gcc-builds where include, library and documentation
365 files are stored is now in /usr/local/share
368 char type parameters to vararg functions are casted to int unless explicitly
385 will push a as an int and as a char resp.
398 -regextend has been removed
411 -noregparms has been removed
424 -stack-after-data has been removed
429 <pending: more incompatibilities?>
435 What do you need before you start installation of SDCC? A computer, and
437 The preferred method of installation is to compile SDCC from source using
439 For Windows some pre-compiled binary distributions are available for your
441 You should have some experience with command line tools and compiler use.
447 The SDCC home page at
448 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
452 is a great place to find distribution sets.
453 You can also find links to the user mailing lists that offer help or discuss
454 SDCC with other SDCC users.
455 Web links to other SDCC related sites can also be found here.
456 This document can be found in the DOC directory of the source package as
458 Some of the other tools (simulator and assembler) included with SDCC contain
459 their own documentation and can be found in the source distribution.
460 If you want the latest unreleased software, the complete source package
461 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
464 Wishes for the future
467 There are (and always will be) some things that could be done.
468 Here are some I can think of:
475 char KernelFunction3(char p) at 0x340;
483 \begin_inset LatexCommand \index{code banking (not supported)}
493 If you can think of some more, please see the chapter
494 \begin_inset LatexCommand \ref{sub:Requesting-Features}
498 about filing feature requests
499 \begin_inset LatexCommand \index{Requesting features}
504 \begin_inset LatexCommand \index{Feature request}
514 \begin_inset LatexCommand \index{Installation}
521 For most users it is sufficient to skip to either section
522 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
527 \begin_inset LatexCommand \ref{sub:Windows-Install}
532 More detailled instructions follow below.
536 \begin_inset LatexCommand \index{Options SDCC configuration}
543 The install paths, search paths and other options are defined when running
545 The defaults can be overridden by:
547 \labelwidthstring 00.00.0000
559 -prefix see table below
561 \labelwidthstring 00.00.0000
573 -exec_prefix see table below
575 \labelwidthstring 00.00.0000
587 -bindir see table below
589 \labelwidthstring 00.00.0000
601 -datadir see table below
603 \labelwidthstring 00.00.0000
605 docdir environment variable, see table below
607 \labelwidthstring 00.00.0000
609 include_dir_suffix environment variable, see table below
611 \labelwidthstring 00.00.0000
613 lib_dir_suffix environment variable, see table below
615 \labelwidthstring 00.00.0000
617 sdccconf_h_dir_separator environment variable, either / or
622 This character will only be used in sdccconf.h; don't forget it's a C-header,
623 therefore a double-backslash is needed there.
625 \labelwidthstring 00.00.0000
637 -disable-mcs51-port Excludes the Intel mcs51 port
639 \labelwidthstring 00.00.0000
651 -disable-gbz80-port Excludes the Gameboy gbz80 port
653 \labelwidthstring 00.00.0000
665 -disable-z80-port Excludes the z80 port
667 \labelwidthstring 00.00.0000
679 -disable-avr-port Excludes the AVR port
681 \labelwidthstring 00.00.0000
693 -disable-ds390-port Excludes the DS390 port
695 \labelwidthstring 00.00.0000
707 -disable-hc08-port Excludes the HC08 port
709 \labelwidthstring 00.00.0000
721 -disable-pic-port Excludes the PIC port
723 \labelwidthstring 00.00.0000
735 -disable-xa51-port Excludes the XA51 port
737 \labelwidthstring 00.00.0000
749 -disable-ucsim Disables configuring and building of ucsim
751 \labelwidthstring 00.00.0000
763 -disable-device-lib-build Disables automatically building device libraries
765 \labelwidthstring 00.00.0000
777 -disable-packihx Disables building packihx
779 \labelwidthstring 00.00.0000
791 -enable-libgc Use the Bohem memory allocator.
792 Lower runtime footprint.
795 Furthermore the environment variables CC, CFLAGS, ...
796 the tools and their arguments can be influenced.
797 Please see `configure -
807 -help` and the man/info pages of `configure` for details.
811 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
812 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
813 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
814 At the moment it's not possible to change the default settings (it was
815 simply never required).
819 These configure options are compiled into the binaries, and can only be
820 changed by rerunning 'configure' and recompiling SDCC.
821 The configure options are written in
825 to distinguish them from run time environment variables (see section search
831 \begin_inset Quotes sld
835 \begin_inset Quotes srd
838 are used by the SDCC team to build the official Win32 binaries.
839 The SDCC team uses Mingw32 to build the official Windows binaries, because
846 a gcc compiler and last but not least
849 the binaries can be built by cross compiling on Sourceforge's compile farm.
852 See the examples, how to pass the Win32 settings to 'configure'.
853 The other Win32 builds using Borland, VC or whatever don't use 'configure',
854 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
866 <lyxtabular version="3" rows="8" columns="3">
868 <column alignment="block" valignment="top" leftline="true" width="0in">
869 <column alignment="block" valignment="top" leftline="true" width="0in">
870 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
871 <row topline="true" bottomline="true">
872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1031 <row topline="true">
1032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1069 <row topline="true">
1070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1097 <row topline="true" bottomline="true">
1098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1134 'configure' also computes relative paths.
1135 This is needed for full relocatability of a binary package and to complete
1136 search paths (see section search paths below):
1142 \begin_inset Tabular
1143 <lyxtabular version="3" rows="4" columns="3">
1145 <column alignment="block" valignment="top" leftline="true" width="0in">
1146 <column alignment="block" valignment="top" leftline="true" width="0in">
1147 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1148 <row topline="true" bottomline="true">
1149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1174 <row topline="true" bottomline="true">
1175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1202 <row bottomline="true">
1203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1230 <row bottomline="true">
1231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1282 \begin_inset Quotes srd
1286 \begin_inset Quotes srd
1300 \begin_inset Quotes srd
1304 \begin_inset Quotes srd
1332 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1341 \begin_inset Quotes srd
1344 i586-mingw32msvc-gcc
1345 \begin_inset Quotes srd
1349 \begin_inset Quotes srd
1352 i586-mingw32msvc-g++
1353 \begin_inset Quotes srd
1361 \begin_inset Quotes srd
1364 i586-mingw32msvc-ranlib
1365 \begin_inset Quotes srd
1373 \begin_inset Quotes srd
1376 i586-mingw32msvc-strip
1377 \begin_inset Quotes srd
1395 \begin_inset Quotes srd
1399 \begin_inset Quotes srd
1417 \begin_inset Quotes srd
1421 \begin_inset Quotes srd
1429 \begin_inset Quotes srd
1433 \begin_inset Quotes srd
1441 \begin_inset Quotes srd
1445 \begin_inset Quotes srd
1453 \begin_inset Quotes srd
1457 \begin_inset Quotes srd
1464 sdccconf_h_dir_separator=
1465 \begin_inset Quotes srd
1477 \begin_inset Quotes srd
1494 -disable-device-lib-build
1522 -host=i586-mingw32msvc -
1532 -build=unknown-unknown-linux-gnu
1536 \begin_inset Quotes sld
1540 \begin_inset Quotes srd
1543 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1552 \begin_inset Quotes srd
1556 \begin_inset Quotes srd
1564 \begin_inset Quotes srd
1568 \begin_inset Quotes srd
1586 \begin_inset Quotes srd
1590 \begin_inset Quotes srd
1608 \begin_inset Quotes srd
1612 \begin_inset Quotes srd
1620 \begin_inset Quotes srd
1624 \begin_inset Quotes srd
1632 \begin_inset Quotes srd
1636 \begin_inset Quotes srd
1644 \begin_inset Quotes srd
1648 \begin_inset Quotes srd
1655 sdccconf_h_dir_separator=
1656 \begin_inset Quotes srd
1668 \begin_inset Quotes srd
1688 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1699 -C' turns on caching, which gives a little bit extra speed.
1700 However if options are changed, it can be necessary to delete the config.cache
1705 \begin_inset LatexCommand \label{sub:Install-paths}
1710 \begin_inset LatexCommand \index{Install paths}
1716 \added_space_top medskip \align center
1718 \begin_inset Tabular
1719 <lyxtabular version="3" rows="5" columns="4">
1721 <column alignment="center" valignment="top" leftline="true" width="0">
1722 <column alignment="center" valignment="top" leftline="true" width="0">
1723 <column alignment="center" valignment="top" leftline="true" width="0">
1724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1725 <row topline="true" bottomline="true">
1726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1767 <row topline="true">
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1807 <row topline="true">
1808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1823 $DATADIR/ $INCLUDE_DIR_SUFFIX
1826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1831 /usr/local/share/sdcc/include
1834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1847 <row topline="true">
1848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 $DATADIR/$LIB_DIR_SUFFIX
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 /usr/local/share/sdcc/lib
1874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1887 <row topline="true" bottomline="true">
1888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1911 /usr/local/share/sdcc/doc
1914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1936 *compiler, preprocessor, assembler, and linker
1942 is auto-appended by the compiler, e.g.
1943 small, large, z80, ds390 etc
1946 The install paths can still be changed during `make install` with e.g.:
1949 make install prefix=$(HOME)/local/sdcc
1952 Of course this doesn't change the search paths compiled into the binaries.
1956 \begin_inset LatexCommand \label{sub:Search-Paths}
1961 \begin_inset LatexCommand \index{Search path}
1968 Some search paths or parts of them are determined by configure variables
1973 , see section above).
1974 Further search paths are determined by environment variables during runtime.
1977 The paths searched when running the compiler are as follows (the first catch
1983 Binary files (preprocessor, assembler and linker)
1989 \begin_inset Tabular
1990 <lyxtabular version="3" rows="4" columns="3">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" width="0in">
1994 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1995 <row topline="true" bottomline="true">
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2021 <row topline="true">
2022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2051 <row topline="true">
2052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2057 Path of argv[0] (if available)
2060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2077 <row topline="true" bottomline="true">
2078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2119 \begin_inset Tabular
2120 <lyxtabular version="3" rows="6" columns="3">
2122 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2123 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2124 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2125 <row topline="true" bottomline="true">
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2151 <row topline="true">
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2207 <row topline="true">
2208 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2233 <row topline="true">
2234 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2248 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2271 <row topline="true">
2272 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2353 <row topline="true" bottomline="true">
2354 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2370 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2375 /usr/local/share/sdcc/
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2408 -nostdinc disables the last two search paths.
2418 With the exception of
2419 \begin_inset Quotes sld
2433 \begin_inset Quotes srd
2440 is auto-appended by the compiler (e.g.
2441 small, large, z80, ds390 etc.).
2448 \begin_inset Tabular
2449 <lyxtabular version="3" rows="6" columns="3">
2451 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2452 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2453 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2454 <row topline="true" bottomline="true">
2455 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2463 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2480 <row topline="true">
2481 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2536 <row topline="true">
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2576 <row topline="true">
2577 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2588 $LIB_DIR_SUFFIX/<model>
2591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2605 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2622 <row topline="true">
2623 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2638 $LIB_DIR_SUFFIX/<model>
2641 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2750 <row topline="true" bottomline="true">
2751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2760 $LIB_DIR_SUFFIX/<model>
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2768 /usr/local/share/sdcc/
2775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2793 Don't delete any of the stray spaces in the table above without checking
2794 the HTML output (last line)!
2810 -nostdlib disables the last two search paths.
2814 \begin_inset LatexCommand \index{Building SDCC}
2821 Building SDCC on Linux
2822 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2831 Download the source package
2833 either from the SDCC CVS repository or from the nightly snapshots
2835 , it will be named something like sdcc
2846 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2855 Bring up a command line terminal, such as xterm.
2860 Unpack the file using a command like:
2863 "tar -xvzf sdcc.src.tar.gz
2868 , this will create a sub-directory called sdcc with all of the sources.
2871 Change directory into the main SDCC directory, for example type:
2888 This configures the package for compilation on your system.
2904 All of the source packages will compile, this can take a while.
2920 This copies the binary executables, the include files, the libraries and
2921 the documentation to the install directories.
2922 Proceed with section
2923 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2930 Building SDCC on OSX 2.x
2933 Follow the instruction for Linux.
2937 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2938 )) fails to compile SDCC.
2939 Fortunately there's also gcc 2.9.x installed, which works fine.
2940 This compiler can be selected by running 'configure' with:
2943 ./configure CC=gcc2 CXX=g++2
2946 Cross compiling SDCC on Linux for Windows
2949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2950 See section 'Configure Options'.
2953 Building SDCC on Windows
2956 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2958 They use Unix-sockets, which are not available on Win32.
2961 Building SDCC using Cygwin and Mingw32
2964 For building and installing a Cygwin executable follow the instructions
2970 \begin_inset Quotes sld
2974 \begin_inset Quotes srd
2977 Win32-binary can be built, which will not need the Cygwin-DLL.
2978 For the necessary 'configure' options see section 'configure options' or
2979 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2983 In order to install Cygwin on Windows download setup.exe from
2984 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2990 \begin_inset Quotes sld
2993 default text file type
2994 \begin_inset Quotes srd
2998 \begin_inset Quotes sld
3002 \begin_inset Quotes srd
3005 and download/install at least the following packages.
3006 Some packages are selected by default, others will be automatically selected
3007 because of dependencies with the manually selected packages.
3008 Never deselect these packages!
3017 gcc ; version 3.x is fine, no need to use the old 2.9x
3020 binutils ; selected with gcc
3026 rxvt ; a nice console, which makes life much easier under windoze (see below)
3029 man ; not really needed for building SDCC, but you'll miss it sooner or
3033 less ; not really needed for building SDCC, but you'll miss it sooner or
3037 cvs ; only if you use CVS access
3040 If you want to develop something you'll need:
3043 python ; for the regression tests
3046 gdb ; the gnu debugger, together with the nice GUI
3047 \begin_inset Quotes sld
3051 \begin_inset Quotes srd
3057 openssh ; to access the CF or commit changes
3060 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3061 use autoconf-stable!
3064 rxvt is a nice console with history.
3065 Replace in your cygwin.bat the line
3084 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3087 -bg black -fg white -geometry 100x65 -e bash -
3100 Text selected with the mouse is automatically copied to the clipboard, pasting
3101 works with shift-insert.
3105 The other good tip is to make sure you have no //c/-style paths anywhere,
3106 use /cygdrive/c/ instead.
3107 Using // invokes a network lookup which is very slow.
3109 \begin_inset Quotes sld
3113 \begin_inset Quotes srd
3116 is too long, you can change it with e.g.
3122 SDCC sources use the unix line ending LF.
3123 Life is much easier, if you store the source tree on a drive which is mounted
3125 And use an editor which can handle LF-only line endings.
3126 Make sure not to commit files with windows line endings.
3127 The tabulator spacing
3128 \begin_inset LatexCommand \index{tabulator spacing (8)}
3132 used in the project is 8.
3135 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3140 Download the source package
3142 either from the SDCC CVS repository or from the
3143 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3149 , it will be named something like sdcc
3156 SDCC is distributed with all the projects, workspaces, and files you need
3157 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3158 doesn't build under MSVC).
3159 The workspace name is 'sdcc.dsw'.
3160 Please note that as it is now, all the executables are created in a folder
3164 Once built you need to copy the executables from sdcc
3168 bin before running SDCC.
3173 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3174 flex.exe, and gawk.exe.
3175 One good place to get them is
3176 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3184 Download the file UnxUtils
3185 \begin_inset LatexCommand \index{UnxUtils}
3190 Now you have to install the utilities and setup MSVC so it can locate the
3192 Here there are two alternatives (choose one!):
3199 a) Extract UnxUtils.zip to your C:
3201 hard disk PRESERVING the original paths, otherwise bison won't work.
3202 (If you are using WinZip make certain that 'Use folder names' is selected)
3206 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3207 in 'Show directories for:' select 'Executable files', and in the directories
3208 window add a new path: 'C:
3218 (As a side effect, you get a bunch of Unix utilities that could be useful,
3219 such as diff and patch.)
3226 This one avoids extracting a bunch of files you may not use, but requires
3231 a) Create a directory were to put the tools needed, or use a directory already
3239 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3240 to such directory WITHOUT preserving the original paths.
3241 (If you are using WinZip make certain that 'Use folder names' is not selected)
3245 c) Rename bison.exe to '_bison.exe'.
3249 d) Create a batch file 'bison.bat' in 'C:
3253 ' and add these lines:
3273 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3277 Steps 'c' and 'd' are needed because bison requires by default that the
3278 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3279 '/usr/local/share/' I think.
3280 So it is necessary to tell bison where those files are located if they
3281 are not in such directory.
3282 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3286 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3287 in 'Show directories for:' select 'Executable files', and in the directories
3288 window add a new path: 'c:
3291 Note that you can use any other path instead of 'c:
3293 util', even the path where the Visual C++ tools are, probably: 'C:
3297 Microsoft Visual Studio
3302 So you don't have to execute step 'e' :)
3306 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3307 the executables from sdcc
3311 bin, and you can compile using SDCC.
3314 Building SDCC Using Borland
3317 From the sdcc directory, run the command "make -f Makefile.bcc".
3318 This should regenerate all the .exe files in the bin directory except for
3319 sdcdb.exe (which currently doesn't build under Borland C++).
3322 If you modify any source files and need to rebuild, be aware that the dependenci
3323 es may not be correctly calculated.
3324 The safest option is to delete all .obj files and run the build again.
3325 From a Cygwin BASH prompt, this can easily be done with the command (be
3326 sure you are in the sdcc directory):
3336 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3338 ) -print -exec rm {}
3347 or on Windows NT/2000/XP from the command prompt with the command:
3354 del /s *.obj *.lib *.rul
3357 from the sdcc directory.
3360 Windows Install Using a Binary Package
3361 \begin_inset LatexCommand \label{sub:Windows-Install}
3368 Download the binary package from
3369 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3373 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3374 This should unpack to a group of sub-directories.
3375 An example directory structure after unpacking the mingw32 package is:
3380 bin for the executables, c:
3388 lib for the include and libraries.
3391 Adjust your environment variable PATH to include the location of the bin
3392 directory or start sdcc using the full path.
3395 Building the Documentation
3398 If the necessary tools (LyX, LaTeX, latex2html) are installed it is as easy
3399 as changing into the doc directory and typing
3403 \begin_inset Quotes srd
3407 \begin_inset Quotes srd
3414 You're invited to make changes and additions to this manual.
3416 \begin_inset LatexCommand \url{www.lyx.org}
3420 as editor this is straightforward.
3421 If you want to avoid installing the tools you will have some success with
3422 a bootable Knoppix CD
3423 \begin_inset LatexCommand \url{http://www.knoppix.net}
3428 Prebuilt documentation in html and pdf format is available from
3429 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3436 Reading the Documentation
3439 Currently reading the document in pdf format is recommended, as for unknown
3440 reason the hyperlinks are working there whereas in the html version they
3443 This documentation is in some aspects different from a commercial documentation:
3447 It tries to document SDCC for several processor architectures in one document
3448 (commercially these probably would be separate documents/products).
3450 \begin_inset LatexCommand \index{Status of documentation}
3454 currently matches SDCC for mcs51 and DS390 best and does give too few informati
3459 There are many references pointing away from this documentation.
3460 Don't let this distract you.
3462 was a reference like
3463 \begin_inset LatexCommand \url{www.opencores.org}
3467 together with a statement
3468 \begin_inset Quotes sld
3471 some processors which are targetted by SDCC can be implemented in a
3488 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3493 \begin_inset Quotes srd
3496 we expect you to have a quick look there and come back.
3497 If you read this you are on the right track.
3500 Some sections attribute more space to problems, restrictions and warnings
3501 than to the solution.
3504 The installation section and the section about the debugger is intimidating.
3507 There are still lots of typos and there are more different writing styles
3511 Testing the SDCC Compiler
3512 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3519 The first thing you should do after installing your SDCC compiler is to
3535 \begin_inset LatexCommand \index{version}
3542 at the prompt, and the program should run and tell you the version.
3543 If it doesn't run, or gives a message about not finding sdcc program, then
3544 you need to check over your installation.
3545 Make sure that the sdcc bin directory is in your executable search path
3546 defined by the PATH environment setting (
3551 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3558 Install trouble-shooting for suggestions
3561 Make sure that the sdcc program is in the bin folder, if not perhaps something
3562 did not install correctly.
3570 is commonly installed as described in section
3571 \begin_inset Quotes sld
3574 Install and search paths
3575 \begin_inset Quotes srd
3584 Make sure the compiler works on a very simple example.
3585 Type in the following test.c program using your favorite
3611 Compile this using the following command:
3620 If all goes well, the compiler will generate a test.asm and test.rel file.
3621 Congratulations, you've just compiled your first program with SDCC.
3622 We used the -c option to tell SDCC not to link the generated code, just
3623 to keep things simple for this step.
3631 The next step is to try it with the linker.
3641 If all goes well the compiler will link with the libraries and produce
3642 a test.ihx output file.
3647 (no test.ihx, and the linker generates warnings), then the problem is most
3656 usr/local/share/sdcc/lib directory
3663 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3670 Install trouble-shooting for suggestions).
3678 The final test is to ensure
3686 header files and libraries.
3687 Edit test.c and change it to the following:
3704 strcpy(str1, "testing");
3711 Compile this by typing
3718 This should generate a test.ihx output file, and it should give no warnings
3719 such as not finding the string.h file.
3720 If it cannot find the string.h file, then the problem is that
3724 cannot find the /usr/local/share/sdcc/include directory
3731 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3738 Install trouble-shooting section for suggestions).
3756 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3760 to find exactly where SDCC is looking for the include and lib files.
3763 Install Trouble-shooting
3764 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3769 \begin_inset LatexCommand \index{Install trouble-shooting}
3776 If SDCC does not build correctly
3779 A thing to try is starting from scratch by unpacking the .tgz source package
3780 again in an empty directory.
3788 ./configure 2>&1 | tee configure.log
3802 make 2>&1 | tee make.log
3809 If anything goes wrong, you can review the log files to locate the problem.
3810 Or a relevant part of this can be attached to an email that could be helpful
3811 when requesting help from the mailing list.
3815 \begin_inset Quotes sld
3819 \begin_inset Quotes srd
3826 \begin_inset Quotes sld
3830 \begin_inset Quotes srd
3833 command is a script that analyzes your system and performs some configuration
3834 to ensure the source package compiles on your system.
3835 It will take a few minutes to run, and will compile a few tests to determine
3836 what compiler features are installed.
3840 \begin_inset Quotes sld
3844 \begin_inset Quotes srd
3850 This runs the GNU make tool, which automatically compiles all the source
3851 packages into the final installed binary executables.
3855 \begin_inset Quotes sld
3859 \begin_inset Quotes erd
3865 This will install the compiler, other executables libraries and include
3866 files into the appropriate directories.
3868 \begin_inset LatexCommand \ref{sub:Install-paths}
3874 \begin_inset LatexCommand \ref{sub:Search-Paths}
3879 about install and search paths.
3881 On most systems you will need super-user privileges to do this.
3887 SDCC is not just a compiler, but a collection of tools by various developers.
3888 These include linkers, assemblers, simulators and other components.
3889 Here is a summary of some of the components.
3890 Note that the included simulator and assembler have separate documentation
3891 which you can find in the source package in their respective directories.
3892 As SDCC grows to include support for other processors, other packages from
3893 various developers are included and may have their own sets of documentation.
3897 You might want to look at the files which are installed in <installdir>.
3898 At the time of this writing, we find the following programs for gcc-builds:
3902 In <installdir>/bin:
3905 sdcc - The compiler.
3908 sdcpp - The C preprocessor.
3911 asx8051 - The assembler for 8051 type processors.
3918 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3921 aslink -The linker for 8051 type processors.
3928 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3931 s51 - The ucSim 8051 simulator.
3934 sdcdb - The source debugger.
3937 packihx - A tool to pack (compress) Intel hex files.
3940 In <installdir>/share/sdcc/include
3946 In <installdir>/share/sdcc/lib
3949 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3953 In <installdir>/share/sdcc/doc
3959 As development for other processors proceeds, this list will expand to include
3960 executables to support processors like AVR, PIC, etc.
3966 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3967 the assembler and linkage editor.
3970 sdcpp - The C-Preprocessor
3974 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
3978 is a modified version of the GNU preprocessor.
3979 The C preprocessor is used to pull in #include sources, process #ifdef
3980 statements, #defines and so on.
3991 - The Assemblers and Linkage Editors
3994 This is retargettable assembler & linkage editor, it was developed by Alan
3996 John Hartman created the version for 8051, and I (Sandeep) have made some
3997 enhancements and bug fixes for it to work properly with SDCC.
4004 \begin_inset LatexCommand \index{s51}
4008 is a freeware, opensource simulator developed by Daniel Drotos (
4009 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4014 The simulator is built as part of the build process.
4015 For more information visit Daniel's web site at:
4016 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4021 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4025 sdcdb - Source Level Debugger
4029 \begin_inset LatexCommand \index{sdcdb (debugger)}
4033 is the companion source level debugger.
4034 More about sdcdb in section
4035 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4040 The current version of the debugger uses Daniel's Simulator S51
4041 \begin_inset LatexCommand \index{s51}
4045 , but can be easily changed to use other simulators.
4055 Single Source File Projects
4058 For single source file 8051 projects the process is very simple.
4059 Compile your programs with the following command
4062 "sdcc sourcefile.c".
4066 This will compile, assemble and link your source file.
4067 Output files are as follows:
4071 \begin_inset LatexCommand \index{<file>.asm}
4076 \begin_inset LatexCommand \index{Assembler source}
4080 file created by the compiler
4084 \begin_inset LatexCommand \index{<file>.lst}
4089 \begin_inset LatexCommand \index{Assembler listing}
4093 file created by the Assembler
4097 \begin_inset LatexCommand \index{<file>.rst}
4102 \begin_inset LatexCommand \index{Assembler listing}
4106 file updated with linkedit information, created by linkage editor
4110 \begin_inset LatexCommand \index{<file>.sym}
4115 \begin_inset LatexCommand \index{Symbol listing}
4119 for the sourcefile, created by the assembler
4123 \begin_inset LatexCommand \index{<file>.rel}
4128 \begin_inset LatexCommand \index{<file>.o}
4133 \begin_inset LatexCommand \index{Object file}
4137 created by the assembler, input to Linkage editor
4141 \begin_inset LatexCommand \index{<file>.map}
4146 \begin_inset LatexCommand \index{Memory map}
4150 for the load module, created by the Linker
4154 \begin_inset LatexCommand \index{<file>.mem}
4158 - A file with a summary of the memory usage
4162 \begin_inset LatexCommand \index{<file>.ihx}
4166 - The load module in Intel hex format
4167 \begin_inset LatexCommand \index{Intel hex format}
4171 (you can select the Motorola S19 format
4172 \begin_inset LatexCommand \index{Motorola S19 format}
4187 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4192 If you need another format you might want to use
4199 \begin_inset LatexCommand \index{objdump (tool)}
4210 \begin_inset LatexCommand \index{srecord (tool)}
4215 Both formats are documented in the the documentation of srecord
4216 \begin_inset LatexCommand \index{srecord (tool)}
4224 \begin_inset LatexCommand \index{.adb}
4228 - An intermediate file containing debug information needed to create the
4240 \begin_inset LatexCommand \index{-\/-debug}
4248 \begin_inset LatexCommand \index{<file>.cdb}
4252 - An optional file (with -
4262 -debug) containing debug information.
4263 The format is documented in cdbfileformat.pdf.
4268 \begin_inset LatexCommand \index{<file> (no extension)}
4272 An optional AOMF or AOMF51
4273 \begin_inset LatexCommand \index{AOMF, AOMF51}
4277 file containing debug information (generated with option -
4304 ormat is commonly used by third party tools (debuggers
4305 \begin_inset LatexCommand \index{Debugger}
4309 , simulators, emulators)
4313 \begin_inset LatexCommand \index{<file>.dump*}
4317 - Dump file to debug the compiler it self (generated with option -
4327 -dumpall) (see section
4328 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4334 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4340 \begin_inset Quotes sld
4343 Anatomy of the compiler
4344 \begin_inset Quotes srd
4350 Projects with Multiple Source Files
4353 SDCC can compile only ONE file at a time.
4354 Let us for example assume that you have a project containing the following
4359 foo1.c (contains some functions)
4361 foo2.c (contains some more functions)
4363 foomain.c (contains more functions and the function main)
4371 The first two files will need to be compiled separately with the commands:
4403 Then compile the source file containing the
4408 \begin_inset LatexCommand \index{Linker}
4412 the files together with the following command:
4420 foomain.c\SpecialChar ~
4421 foo1.rel\SpecialChar ~
4426 \begin_inset LatexCommand \index{<file>.rel}
4438 can be separately compiled as well:
4449 sdcc foomain.rel foo1.rel foo2.rel
4456 The file containing the
4471 file specified in the command line, since the linkage editor processes
4472 file in the order they are presented to it.
4473 The linker is invoked from SDCC using a script file with extension .lnk
4474 \begin_inset LatexCommand \index{.lnk}
4479 You can view this file to troubleshoot linking problems such as those arising
4480 from missing libraries.
4483 Projects with Additional Libraries
4484 \begin_inset LatexCommand \index{Libraries}
4491 Some reusable routines may be compiled into a library, see the documentation
4492 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4496 \begin_inset LatexCommand \index{.lib}
4503 Libraries created in this manner can be included in the command line.
4504 Make sure you include the -L <library-path> option to tell the linker where
4505 to look for these files if they are not in the current directory.
4506 Here is an example, assuming you have the source file
4518 (if that is not the same as your current project):
4525 sdcc foomain.c foolib.lib -L mylib
4536 must be an absolute path name.
4540 The most efficient way to use libraries is to keep separate modules in separate
4542 The lib file now should name all the modules.rel
4543 \begin_inset LatexCommand \index{<file>.rel}
4548 For an example see the standard library file
4552 in the directory <installdir>/share/lib/small.
4555 Command Line Options
4556 \begin_inset LatexCommand \index{Command Line Options}
4563 Processor Selection Options
4564 \begin_inset LatexCommand \index{Options processor selection}
4569 \begin_inset LatexCommand \index{Processor selection options}
4575 \labelwidthstring 00.00.0000
4580 \begin_inset LatexCommand \index{-mmcs51}
4586 Generate code for the Intel MCS51
4587 \begin_inset LatexCommand \index{MCS51}
4591 family of processors.
4592 This is the default processor target.
4594 \labelwidthstring 00.00.0000
4599 \begin_inset LatexCommand \index{-mds390}
4605 Generate code for the Dallas DS80C390
4606 \begin_inset LatexCommand \index{DS80C390}
4612 \labelwidthstring 00.00.0000
4617 \begin_inset LatexCommand \index{-mds400}
4623 Generate code for the Dallas DS80C400
4624 \begin_inset LatexCommand \index{DS80C400}
4630 \labelwidthstring 00.00.0000
4635 \begin_inset LatexCommand \index{-mhc08}
4641 Generate code for the Motorola HC08
4642 \begin_inset LatexCommand \index{HC08}
4646 family of processors (added Oct 2003).
4648 \labelwidthstring 00.00.0000
4653 \begin_inset LatexCommand \index{-mz80}
4659 Generate code for the Zilog Z80
4660 \begin_inset LatexCommand \index{Z80}
4664 family of processors.
4666 \labelwidthstring 00.00.0000
4671 \begin_inset LatexCommand \index{-mgbz80}
4677 Generate code for the GameBoy Z80
4678 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
4682 processor (Not actively maintained).
4684 \labelwidthstring 00.00.0000
4689 \begin_inset LatexCommand \index{-mavr}
4695 Generate code for the Atmel AVR
4696 \begin_inset LatexCommand \index{AVR}
4700 processor (In development, not complete).
4701 AVR users should probably have a look at avr-gcc
4702 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4709 I think it is fair to direct users there for now.
4710 Open source is also about avoiding unnecessary work .
4711 But I didn't find the 'official' link.
4713 \labelwidthstring 00.00.0000
4718 \begin_inset LatexCommand \index{-mpic14}
4724 Generate code for the Microchip PIC 14
4725 \begin_inset LatexCommand \index{PIC14}
4729 -bit processors (p16f84 and variants.
4730 In development, not complete).
4733 p16f627 p16f628 p16f84 p16f873 p16f877?
4735 \labelwidthstring 00.00.0000
4740 \begin_inset LatexCommand \index{-mpic16}
4746 Generate code for the Microchip PIC 16
4747 \begin_inset LatexCommand \index{PIC16}
4751 -bit processors (p18f452 and variants.
4752 In development, not complete).
4754 \labelwidthstring 00.00.0000
4760 Generate code for the Toshiba TLCS-900H
4761 \begin_inset LatexCommand \index{TLCS-900H}
4765 processor (Not maintained, not complete).
4767 \labelwidthstring 00.00.0000
4772 \begin_inset LatexCommand \index{-mxa51}
4778 Generate code for the Phillips XA51
4779 \begin_inset LatexCommand \index{XA51}
4783 processor (Not maintained, not complete).
4786 Preprocessor Options
4787 \begin_inset LatexCommand \index{Options preprocessor}
4792 \begin_inset LatexCommand \index{Preprocessor options}
4798 \labelwidthstring 00.00.0000
4803 \begin_inset LatexCommand \index{-I<path>}
4809 The additional location where the pre processor will look for <..h> or
4810 \begin_inset Quotes eld
4814 \begin_inset Quotes erd
4819 \labelwidthstring 00.00.0000
4824 \begin_inset LatexCommand \index{-D<macro[=value]>}
4830 Command line definition of macros.
4831 Passed to the preprocessor.
4833 \labelwidthstring 00.00.0000
4838 \begin_inset LatexCommand \index{-M}
4844 Tell the preprocessor to output a rule suitable for make describing the
4845 dependencies of each object file.
4846 For each source file, the preprocessor outputs one make-rule whose target
4847 is the object file name for that source file and whose dependencies are
4848 all the files `#include'd in it.
4849 This rule may be a single line or may be continued with `
4851 '-newline if it is long.
4852 The list of rules is printed on standard output instead of the preprocessed
4855 \begin_inset LatexCommand \index{-E}
4861 \labelwidthstring 00.00.0000
4866 \begin_inset LatexCommand \index{-C}
4872 Tell the preprocessor not to discard comments.
4873 Used with the `-E' option.
4875 \labelwidthstring 00.00.0000
4880 \begin_inset LatexCommand \index{-MM}
4891 Like `-M' but the output mentions only the user header files included with
4893 \begin_inset Quotes eld
4897 System header files included with `#include <file>' are omitted.
4899 \labelwidthstring 00.00.0000
4904 \begin_inset LatexCommand \index{-Aquestion(answer)}
4910 Assert the answer answer for question, in case it is tested with a preprocessor
4911 conditional such as `#if #question(answer)'.
4912 `-A-' disables the standard assertions that normally describe the target
4915 \labelwidthstring 00.00.0000
4920 \begin_inset LatexCommand \index{-Umacro}
4926 Undefine macro macro.
4927 `-U' options are evaluated after all `-D' options, but before any `-include'
4928 and `-imacros' options.
4930 \labelwidthstring 00.00.0000
4935 \begin_inset LatexCommand \index{-dM}
4941 Tell the preprocessor to output only a list of the macro definitions that
4942 are in effect at the end of preprocessing.
4943 Used with the `-E' option.
4945 \labelwidthstring 00.00.0000
4950 \begin_inset LatexCommand \index{-dD}
4956 Tell the preprocessor to pass all macro definitions into the output, in
4957 their proper sequence in the rest of the output.
4959 \labelwidthstring 00.00.0000
4964 \begin_inset LatexCommand \index{-dN}
4975 Like `-dD' except that the macro arguments and contents are omitted.
4976 Only `#define name' is included in the output.
4978 \labelwidthstring 00.00.0000
4983 preprocessorOption[,preprocessorOption]
4986 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
4991 Pass the preprocessorOption to the preprocessor.
4995 \begin_inset LatexCommand \index{Options linker}
5000 \begin_inset LatexCommand \index{Linker options}
5006 \labelwidthstring 00.00.0000
5026 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5031 \begin_inset LatexCommand \index{-L -\/-lib-path}
5038 <absolute path to additional libraries> This option is passed to the linkage
5039 editor's additional libraries
5040 \begin_inset LatexCommand \index{Libraries}
5045 The path name must be absolute.
5046 Additional library files may be specified in the command line.
5047 See section Compiling programs for more details.
5049 \labelwidthstring 00.00.0000
5066 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5071 <Value> The start location of the external ram
5072 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5076 , default value is 0.
5077 The value entered can be in Hexadecimal or Decimal format, e.g.: -
5087 -xram-loc 0x8000 or -
5099 \labelwidthstring 00.00.0000
5116 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5121 <Value> The start location of the code
5122 \begin_inset LatexCommand \index{code}
5126 segment, default value 0.
5127 Note when this option is used the interrupt vector table is also relocated
5128 to the given address.
5129 The value entered can be in Hexadecimal or Decimal format, e.g.: -
5139 -code-loc 0x8000 or -
5151 \labelwidthstring 00.00.0000
5168 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5173 <Value> By default the stack
5174 \begin_inset LatexCommand \index{stack}
5178 is placed after the data segment.
5179 Using this option the stack can be placed anywhere in the internal memory
5181 The value entered can be in Hexadecimal or Decimal format, e.g.
5192 -stack-loc 0x20 or -
5203 Since the sp register is incremented before a push or call, the initial
5204 sp will be set to one byte prior the provided value.
5205 The provided value should not overlap any other memory areas such as used
5206 register banks or the data segment and with enough space for the current
5209 \labelwidthstring 00.00.0000
5226 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5231 <Value> The start location of the internal ram data
5232 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5237 The value entered can be in Hexadecimal or Decimal format, eg.
5259 (By default, the start location of the internal ram data segment is set
5260 as low as possible in memory, taking into account the used register banks
5261 and the bit segment at address 0x20.
5262 For example if register banks 0 and 1 are used without bit variables, the
5263 data segment will be set, if -
5273 -data-loc is not used, to location 0x10.)
5275 \labelwidthstring 00.00.0000
5292 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5297 <Value> The start location of the indirectly addressable internal ram
5298 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5302 of the 8051, default value is 0x80.
5303 The value entered can be in Hexadecimal or Decimal format, eg.
5314 -idata-loc 0x88 or -
5326 \labelwidthstring 00.00.0000
5343 <Value> The start location of the bit
5344 \begin_inset LatexCommand \index{bit}
5348 addressable internal ram of the 8051.
5354 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5357 \labelwidthstring 00.00.0000
5372 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5381 The linker output (final object code) is in Intel Hex format.
5382 \begin_inset LatexCommand \index{Intel hex format}
5386 This is the default option.
5387 The format itself is documented in the documentation of srecord
5388 \begin_inset LatexCommand \index{srecord (tool)}
5394 \labelwidthstring 00.00.0000
5409 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5418 The linker output (final object code) is in Motorola S19 format
5419 \begin_inset LatexCommand \index{Motorola S19 format}
5424 The format itself is documented in the documentation of srecord.
5426 \labelwidthstring 00.00.0000
5431 linkOption[,linkOption]
5434 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5439 Pass the linkOption to the linker.
5440 See file sdcc/as/doc/asxhtm.html for more on linker options.
5444 \begin_inset LatexCommand \index{Options MCS51}
5449 \begin_inset LatexCommand \index{MCS51 options}
5455 \labelwidthstring 00.00.0000
5470 \begin_inset LatexCommand \index{-\/-model-small}
5481 Generate code for Small Model programs, see section Memory Models for more
5483 This is the default model.
5485 \labelwidthstring 00.00.0000
5500 \begin_inset LatexCommand \index{-\/-model-large}
5506 Generate code for Large model programs, see section Memory Models for more
5508 If this option is used all source files in the project have to be compiled
5511 \labelwidthstring 00.00.0000
5526 \begin_inset LatexCommand \index{-\/-xstack}
5532 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5533 variables and passing parameters.
5535 \begin_inset LatexCommand \ref{sub:External-Stack}
5540 External Stack for more details.
5542 \labelwidthstring 00.00.0000
5560 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5564 Causes the linker to check if the internal ram usage is within limits of
5567 \labelwidthstring 00.00.0000
5585 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5589 Causes the linker to check if the external ram usage is within limits of
5592 \labelwidthstring 00.00.0000
5610 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5614 Causes the linker to check if the code memory usage is within limits of
5618 DS390 / DS400 Options
5619 \begin_inset LatexCommand \index{Options DS390}
5624 \begin_inset LatexCommand \index{DS390 options}
5630 \labelwidthstring 00.00.0000
5647 \begin_inset LatexCommand \index{-\/-model-flat24}
5657 Generate 24-bit flat mode code.
5658 This is the one and only that the ds390 code generator supports right now
5659 and is default when using
5664 See section Memory Models for more details.
5666 \labelwidthstring 00.00.0000
5681 \begin_inset LatexCommand \index{-\/-protect-sp-update}
5687 disable interrupts during ESP:SP updates.
5689 \labelwidthstring 00.00.0000
5706 \begin_inset LatexCommand \index{-\/-stack-10bit}
5710 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5711 This is the one and only that the ds390 code generator supports right now
5712 and is default when using
5717 In this mode, the stack is located in the lower 1K of the internal RAM,
5718 which is mapped to 0x400000.
5719 Note that the support is incomplete, since it still uses a single byte
5720 as the stack pointer.
5721 This means that only the lower 256 bytes of the potential 1K stack space
5722 will actually be used.
5723 However, this does allow you to reclaim the precious 256 bytes of low RAM
5724 for use for the DATA and IDATA segments.
5725 The compiler will not generate any code to put the processor into 10 bit
5727 It is important to ensure that the processor is in this mode before calling
5728 any re-entrant functions compiled with this option.
5729 In principle, this should work with the
5742 \begin_inset LatexCommand \index{-\/-stack-auto}
5748 option, but that has not been tested.
5749 It is incompatible with the
5762 \begin_inset LatexCommand \index{-\/-xstack}
5769 It also only makes sense if the processor is in 24 bit contiguous addressing
5782 -model-flat24 option
5786 \labelwidthstring 00.00.0000
5801 \begin_inset LatexCommand \index{-\/-stack-probe}
5807 insert call to function __stack_probe at each function prologue.
5809 \labelwidthstring 00.00.0000
5824 \begin_inset LatexCommand \index{-\/-tini-libid}
5830 <nnnn> LibraryID used in -mTININative.
5833 \labelwidthstring 00.00.0000
5848 \begin_inset LatexCommand \index{-\/-use-accelerator}
5854 generate code for DS390 Arithmetic Accelerator.
5859 \begin_inset LatexCommand \index{Options PIC}
5864 \begin_inset LatexCommand \index{PIC options}
5870 \labelwidthstring 00.00.0000
5885 \begin_inset LatexCommand \index{-\/-gen-banksel}
5891 enable the generation of banksel assembler directives in the PIC16 port.
5895 \begin_inset LatexCommand \index{Options Z80}
5900 \begin_inset LatexCommand \index{Z80 options}
5906 \labelwidthstring 00.00.0000
5923 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5933 Force a called function to always save BC.
5935 \labelwidthstring 00.00.0000
5952 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5956 When linking, skip the standard crt0.o object file.
5957 You must provide your own crt0.o for your system when linking.
5961 Optimization Options
5962 \begin_inset LatexCommand \index{Options optimization}
5967 \begin_inset LatexCommand \index{Optimization options}
5973 \labelwidthstring 00.00.0000
5988 \begin_inset LatexCommand \index{-\/-nogcse}
5994 Will not do global subexpression elimination, this option may be used when
5995 the compiler creates undesirably large stack/data spaces to store compiler
5997 A warning message will be generated when this happens and the compiler
5998 will indicate the number of extra bytes it allocated.
5999 It is recommended that this option NOT be used, #pragma\SpecialChar ~
6001 \begin_inset LatexCommand \index{\#pragma nogcse}
6005 can be used to turn off global subexpression elimination
6006 \begin_inset LatexCommand \index{Subexpression elimination}
6010 for a given function only.
6012 \labelwidthstring 00.00.0000
6027 \begin_inset LatexCommand \index{-\/-noinvariant}
6033 Will not do loop invariant optimizations, this may be turned off for reasons
6034 explained for the previous option.
6035 For more details of loop optimizations performed see section Loop Invariants.
6036 It is recommended that this option NOT be used, #pragma\SpecialChar ~
6038 \begin_inset LatexCommand \index{\#pragma noinvariant}
6042 can be used to turn off invariant optimizations for a given function only.
6044 \labelwidthstring 00.00.0000
6059 \begin_inset LatexCommand \index{-\/-noinduction}
6065 Will not do loop induction optimizations, see section strength reduction
6067 It is recommended that this option is NOT used, #pragma\SpecialChar ~
6069 \begin_inset LatexCommand \index{\#pragma noinduction}
6073 can be used to turn off induction optimizations for a given function only.
6075 \labelwidthstring 00.00.0000
6090 \begin_inset LatexCommand \index{-\/-nojtbound}
6101 Will not generate boundary condition check when switch statements
6102 \begin_inset LatexCommand \index{switch statement}
6106 are implemented using jump-tables.
6108 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6113 Switch Statements for more details.
6114 It is recommended that this option is NOT used, #pragma\SpecialChar ~
6116 \begin_inset LatexCommand \index{\#pragma nojtbound}
6120 can be used to turn off boundary checking for jump tables for a given function
6123 \labelwidthstring 00.00.0000
6138 \begin_inset LatexCommand \index{-\/-noloopreverse}
6147 Will not do loop reversal
6148 \begin_inset LatexCommand \index{Loop reversing}
6154 \labelwidthstring 00.00.0000
6171 \begin_inset LatexCommand \index{-\/-nolabelopt }
6175 Will not optimize labels (makes the dumpfiles more readable).
6177 \labelwidthstring 00.00.0000
6192 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6198 Will not memcpy initialized data from code space into xdata space.
6199 This saves a few bytes in code space if you don't have initialized data.
6201 \labelwidthstring 00.00.0000
6216 \begin_inset LatexCommand \index{-\/-nooverlay}
6222 The compiler will not overlay parameters and local variables of any function,
6223 see section Parameters and local variables for more details.
6225 \labelwidthstring 00.00.0000
6240 \begin_inset LatexCommand \index{-\/-no-peep}
6246 Disable peep-hole optimization.
6248 \labelwidthstring 00.00.0000
6265 \begin_inset LatexCommand \index{-\/-peep-file}
6270 <filename> This option can be used to use additional rules to be used by
6271 the peep hole optimizer.
6273 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6278 Peep Hole optimizations for details on how to write these rules.
6280 \labelwidthstring 00.00.0000
6295 \begin_inset LatexCommand \index{-\/-peep-asm}
6301 Pass the inline assembler code through the peep hole optimizer.
6302 This can cause unexpected changes to inline assembler code, please go through
6303 the peephole optimizer
6304 \begin_inset LatexCommand \index{Peephole optimizer}
6308 rules defined in the source file tree '<target>/peeph.def' before using
6313 \begin_inset LatexCommand \index{Options other}
6319 \labelwidthstring 00.00.0000
6335 \begin_inset LatexCommand \index{-\/-compile-only}
6340 \begin_inset LatexCommand \index{-c -\/-compile-only}
6346 will compile and assemble the source, but will not call the linkage editor.
6348 \labelwidthstring 00.00.0000
6367 \begin_inset LatexCommand \index{-\/-c1mode}
6373 reads the preprocessed source from standard input and compiles it.
6374 The file name for the assembler output must be specified using the -o option.
6376 \labelwidthstring 00.00.0000
6381 \begin_inset LatexCommand \index{-E}
6387 Run only the C preprocessor.
6388 Preprocess all the C source files specified and output the results to standard
6391 \labelwidthstring 00.00.0000
6397 \begin_inset LatexCommand \index{-o <path/file>}
6403 The output path resp.
6404 file where everything will be placed.
6405 If the parameter is a path, it must have a trailing slash (or backslash
6406 for the Windows binaries) to be recognized as a path.
6409 \labelwidthstring 00.00.0000
6424 \begin_inset LatexCommand \index{-\/-stack-auto}
6435 All functions in the source file will be compiled as
6440 \begin_inset LatexCommand \index{reentrant}
6445 the parameters and local variables will be allocated on the stack
6446 \begin_inset LatexCommand \index{stack}
6451 see section Parameters and Local Variables for more details.
6452 If this option is used all source files in the project should be compiled
6456 \labelwidthstring 00.00.0000
6471 \begin_inset LatexCommand \index{-\/-callee-saves}
6475 function1[,function2][,function3]....
6478 The compiler by default uses a caller saves convention for register saving
6479 across function calls, however this can cause unnecessary register pushing
6480 & popping when calling small functions from larger functions.
6481 This option can be used to switch the register saving convention for the
6482 function names specified.
6483 The compiler will not save registers when calling these functions, no extra
6484 code will be generated at the entry & exit (function prologue
6487 \begin_inset LatexCommand \index{function prologue}
6496 \begin_inset LatexCommand \index{function epilogue}
6502 ) for these functions to save & restore the registers used by these functions,
6503 this can SUBSTANTIALLY reduce code & improve run time performance of the
6505 In the future the compiler (with inter procedural analysis) will be able
6506 to determine the appropriate scheme to use for each function call.
6507 DO NOT use this option for built-in functions such as _mulint..., if this
6508 option is used for a library function the appropriate library function
6509 needs to be recompiled with the same option.
6510 If the project consists of multiple source files then all the source file
6511 should be compiled with the same -
6521 -callee-saves option string.
6522 Also see #pragma\SpecialChar ~
6524 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6530 \labelwidthstring 00.00.0000
6545 \begin_inset LatexCommand \index{-\/-debug}
6554 When this option is used the compiler will generate debug information.
6555 The debug information collected in a file with .cdb extension can be used
6557 For more information see documentation for SDCDB.
6558 Another file with no extension contains debug information in AOMF or AOMF51
6559 \begin_inset LatexCommand \index{AOMF, AOMF51}
6563 format which is commonly used by third party tools.
6565 \labelwidthstring 00.00.0000
6570 \begin_inset LatexCommand \index{-S}
6581 Stop after the stage of compilation proper; do not assemble.
6582 The output is an assembler code file for the input file specified.
6584 \labelwidthstring 00.00.0000
6599 \begin_inset LatexCommand \index{-\/-int-long-reent}
6605 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6606 Note by default these libraries are compiled as non-reentrant.
6607 See section Installation for more details.
6609 \labelwidthstring 00.00.0000
6624 \begin_inset LatexCommand \index{-\/-cyclomatic}
6633 This option will cause the compiler to generate an information message for
6634 each function in the source file.
6635 The message contains some
6639 information about the function.
6640 The number of edges and nodes the compiler detected in the control flow
6641 graph of the function, and most importantly the
6643 cyclomatic complexity
6644 \begin_inset LatexCommand \index{Cyclomatic complexity}
6650 see section on Cyclomatic Complexity for more details.
6652 \labelwidthstring 00.00.0000
6667 \begin_inset LatexCommand \index{-\/-float-reent}
6673 Floating point library is compiled as reentrant
6674 \begin_inset LatexCommand \index{reentrant}
6679 See section Installation for more details.
6681 \labelwidthstring 00.00.0000
6696 \begin_inset LatexCommand \index{-\/-main-return}
6702 This option can be used when the code generated is called by a monitor
6704 The compiler will generate a 'ret' upon return from the 'main'
6705 \begin_inset LatexCommand \index{main return}
6710 The default setting is to lock up i.e.
6717 \labelwidthstring 00.00.0000
6732 \begin_inset LatexCommand \index{-\/-nostdincl}
6738 This will prevent the compiler from passing on the default include path
6739 to the preprocessor.
6741 \labelwidthstring 00.00.0000
6756 \begin_inset LatexCommand \index{-\/-nostdlib}
6762 This will prevent the compiler from passing on the default library
6763 \begin_inset LatexCommand \index{Libraries}
6769 \labelwidthstring 00.00.0000
6784 \begin_inset LatexCommand \index{-\/-verbose}
6790 Shows the various actions the compiler is performing.
6792 \labelwidthstring 00.00.0000
6797 \begin_inset LatexCommand \index{-V}
6803 Shows the actual commands the compiler is executing.
6805 \labelwidthstring 00.00.0000
6820 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6826 Hides your ugly and inefficient c-code from the asm file, so you can always
6827 blame the compiler :).
6829 \labelwidthstring 00.00.0000
6844 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6850 Include i-codes in the asm file.
6851 Sounds like noise but is most helpful for debugging the compiler itself.
6853 \labelwidthstring 00.00.0000
6868 \begin_inset LatexCommand \index{-\/-less-pedantic}
6874 Disable some of the more pedantic warnings
6875 \begin_inset LatexCommand \index{Warnings}
6879 (jwk burps: please be more specific here, please!).
6880 If you want rather more than less warnings you should consider using a
6881 separate tool dedicated to syntax checking like splint
6882 \begin_inset LatexCommand \url{www.splint.org}
6888 \labelwidthstring 00.00.0000
6903 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6909 Display the directories in the compiler's search path
6911 \labelwidthstring 00.00.0000
6926 \begin_inset LatexCommand \index{-\/-vc}
6932 Display errors and warnings using MSVC style, so you can use SDCC with
6935 \labelwidthstring 00.00.0000
6950 \begin_inset LatexCommand \index{-\/-use-stdout}
6956 Send errors and warnings to stdout instead of stderr.
6958 \labelwidthstring 00.00.0000
6963 asmOption[,asmOption]
6966 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
6971 Pass the asmOption to the assembler
6972 \begin_inset LatexCommand \index{Options assembler}
6977 \begin_inset LatexCommand \index{Assembler options}
6982 See file sdcc/as/doc/asxhtm.html for assembler options.
6985 Intermediate Dump Options
6986 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
6991 \begin_inset LatexCommand \index{Options intermediate dump}
6996 \begin_inset LatexCommand \index{Intermediate dump options}
7003 The following options are provided for the purpose of retargetting and debugging
7005 These provided a means to dump the intermediate code (iCode
7006 \begin_inset LatexCommand \index{iCode}
7010 ) generated by the compiler in human readable form at various stages of
7011 the compilation process.
7012 More on iCodes see chapter
7013 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7018 \begin_inset Quotes srd
7021 The anatomy of the compiler
7022 \begin_inset Quotes srd
7027 \labelwidthstring 00.00.0000
7042 \begin_inset LatexCommand \index{-\/-dumpraw}
7048 This option will cause the compiler to dump the intermediate code into
7051 <source filename>.dumpraw
7053 just after the intermediate code has been generated for a function, i.e.
7054 before any optimizations are done.
7056 \begin_inset LatexCommand \index{Basic blocks}
7060 at this stage ordered in the depth first number, so they may not be in
7061 sequence of execution.
7063 \labelwidthstring 00.00.0000
7078 \begin_inset LatexCommand \index{-\/-dumpgcse}
7084 Will create a dump of iCode's, after global subexpression elimination
7085 \begin_inset LatexCommand \index{Global subexpression elimination}
7091 <source filename>.dumpgcse.
7093 \labelwidthstring 00.00.0000
7108 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7114 Will create a dump of iCode's, after deadcode elimination
7115 \begin_inset LatexCommand \index{Dead-code elimination}
7121 <source filename>.dumpdeadcode.
7123 \labelwidthstring 00.00.0000
7138 \begin_inset LatexCommand \index{-\/-dumploop}
7147 Will create a dump of iCode's, after loop optimizations
7148 \begin_inset LatexCommand \index{Loop optimization}
7154 <source filename>.dumploop.
7156 \labelwidthstring 00.00.0000
7171 \begin_inset LatexCommand \index{-\/-dumprange}
7180 Will create a dump of iCode's, after live range analysis
7181 \begin_inset LatexCommand \index{Live range analysis}
7187 <source filename>.dumprange.
7189 \labelwidthstring 00.00.0000
7204 \begin_inset LatexCommand \index{-\/-dumlrange}
7210 Will dump the life ranges
7211 \begin_inset LatexCommand \index{Live range analysis}
7217 \labelwidthstring 00.00.0000
7232 \begin_inset LatexCommand \index{-\/-dumpregassign}
7241 Will create a dump of iCode's, after register assignment
7242 \begin_inset LatexCommand \index{Register assignment}
7248 <source filename>.dumprassgn.
7250 \labelwidthstring 00.00.0000
7265 \begin_inset LatexCommand \index{-\/-dumplrange}
7271 Will create a dump of the live ranges of iTemp's
7273 \labelwidthstring 00.00.0000
7288 \begin_inset LatexCommand \index{-\/-dumpall}
7299 Will cause all the above mentioned dumps to be created.
7302 Redirecting output on Windows Shells
7305 By default SDCC writes it's error messages to
7306 \begin_inset Quotes sld
7310 \begin_inset Quotes srd
7314 To force all messages to
7315 \begin_inset Quotes sld
7319 \begin_inset Quotes srd
7343 \begin_inset LatexCommand \index{-\/-use-stdout}
7348 Additionally, if you happen to have visual studio installed in your windows
7349 machine, you can use it to compile your sources using a custom build and
7365 \begin_inset LatexCommand \index{-\/-vc}
7370 Something like this should work:
7414 -model-large -c $(InputPath)
7417 Environment variables
7418 \begin_inset LatexCommand \index{Environment variables}
7425 SDCC recognizes the following environment variables:
7427 \labelwidthstring 00.00.0000
7432 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7438 SDCC installs a signal handler
7439 \begin_inset LatexCommand \index{signal handler}
7443 to be able to delete temporary files after an user break (^C) or an exception.
7444 If this environment variable is set, SDCC won't install the signal handler
7445 in order to be able to debug SDCC.
7447 \labelwidthstring 00.00.0000
7454 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7460 Path, where temporary files will be created.
7461 The order of the variables is the search order.
7462 In a standard *nix environment these variables are not set, and there's
7463 no need to set them.
7464 On Windows it's recommended to set one of them.
7466 \labelwidthstring 00.00.0000
7471 \begin_inset LatexCommand \index{SDCC\_HOME}
7478 \begin_inset LatexCommand \ref{sub:Install-paths}
7484 \begin_inset Quotes sld
7488 \begin_inset Quotes srd
7493 \labelwidthstring 00.00.0000
7498 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7505 \begin_inset LatexCommand \ref{sub:Search-Paths}
7511 \begin_inset Quotes sld
7515 \begin_inset Quotes srd
7520 \labelwidthstring 00.00.0000
7525 \begin_inset LatexCommand \index{SDCC\_LIB}
7532 \begin_inset LatexCommand \ref{sub:Search-Paths}
7538 \begin_inset Quotes sld
7542 \begin_inset Quotes srd
7548 There are some more environment variables recognized by SDCC, but these
7549 are solely used for debugging purposes.
7550 They can change or disappear very quickly, and will never be documented.
7553 Storage Class Language Extensions
7556 MCS51/DS390 Storage Class
7557 \begin_inset LatexCommand \index{Storage class}
7564 In addition to the ANSI storage classes SDCC allows the following MCS51
7565 specific storage classes:
7566 \layout Subsubsection
7569 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7574 \begin_inset LatexCommand \index{near (storage class)}
7585 storage class for the Small Memory model (
7593 can be used synonymously).
7594 Variables declared with this storage class will be allocated in the directly
7595 addressable portion of the internal RAM of a 8051, e.g.:
7600 data unsigned char test_data;
7603 Writing 0x01 to this variable generates the assembly code:
7608 75*00 01\SpecialChar ~
7614 \layout Subsubsection
7617 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7622 \begin_inset LatexCommand \index{far (storage class)}
7629 Variables declared with this storage class will be placed in the external
7635 storage class for the Large Memory model, e.g.:
7640 xdata unsigned char test_xdata;
7643 Writing 0x01 to this variable generates the assembly code:
7648 90s00r00\SpecialChar ~
7677 \layout Subsubsection
7680 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7687 Variables declared with this storage class will be allocated into the indirectly
7688 addressable portion of the internal ram of a 8051, e.g.:
7693 idata unsigned char test_idata;
7696 Writing 0x01 to this variable generates the assembly code:
7725 Please note, the first 128 byte of idata physically access the same RAM
7727 The original 8051 had 128 byte idata memory, nowadays most devices have
7728 256 byte idata memory.
7730 \begin_inset LatexCommand \index{stack}
7734 is located in idata memory.
7735 \layout Subsubsection
7738 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7745 Paged xdata access is currently not as straightforward as using the other
7746 addressing modes of a 8051.
7747 The following example writes 0x01 to the address pointed to.
7748 Please note, pdata access physically accesses xdata memory.
7749 The high byte of the address is determined by port P2
7750 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
7754 (or in case of some 8051 variants by a separate Special Function Register,
7756 \begin_inset LatexCommand \ref{sub:MCS51-variants}
7765 pdata unsigned char *test_pdata_ptr;
7777 test_pdata_ptr = (pdata *)0xfe;
7783 *test_pdata_ptr = 1;
7788 Generates the assembly code:
7793 75*01 FE\SpecialChar ~
7797 _test_pdata_ptr,#0xFE
7829 Be extremely carefull if you use pdata together with the -
7840 \begin_inset LatexCommand \index{-\/-xstack}
7845 \layout Subsubsection
7848 \begin_inset LatexCommand \index{code}
7855 'Variables' declared with this storage class will be placed in the code
7861 code unsigned char test_code;
7864 Read access to this variable generates the assembly code:
7869 90s00r6F\SpecialChar ~
7872 mov dptr,#_test_code
7901 indexed arrays of characters in code memory can be accessed efficiently:
7906 code char test_array[] = {'c','h','e','a','p'};
7909 Read access to this array using an 8-bit unsigned index generates the assembly
7926 90s00r41\SpecialChar ~
7929 mov dptr,#_test_array
7944 \layout Subsubsection
7947 \begin_inset LatexCommand \index{bit}
7954 This is a data-type and a storage class specifier.
7955 When a variable is declared as a bit, it is allocated into the bit addressable
7956 memory of 8051, e.g.:
7964 Writing 1 to this variable generates the assembly code:
7980 The bit addressable memory consists of 128 bits which are located from 0x20
7981 to 0x2f in data memory.
7985 Apart from this 8051 specific storage class most architectures support ANSI-C
7987 \begin_inset LatexCommand \index{bitfields}
7997 Not really meant as examples, but nevertheless showing what bitfields are
7998 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8002 \layout Subsubsection
8005 \begin_inset LatexCommand \index{sfr}
8010 \begin_inset LatexCommand \index{sbit}
8017 Like the bit keyword,
8021 signifies both a data-type and storage class, they are used to describe
8042 variables of a 8051, eg:
8048 \begin_inset LatexCommand \index{at}
8052 0x80 P0;\SpecialChar ~
8053 /* special function register P0 at location 0x80 */
8055 sbit at 0xd7 CY; /* CY (Carry Flag
8056 \begin_inset LatexCommand \index{Flags}
8061 \begin_inset LatexCommand \index{Carry flag}
8068 Special function registers which are located on an address dividable by
8069 8 are bit-addressable, an
8073 addresses a specific bit within these sfr.
8074 \layout Subsubsection
8077 \begin_inset LatexCommand \index{Pointer}
8081 to MCS51/DS390 specific memory spaces
8084 SDCC allows (via language extensions) pointers to explicitly point to any
8085 of the memory spaces
8086 \begin_inset LatexCommand \index{Memory model}
8091 In addition to the explicit pointers, the compiler uses (by default) generic
8092 pointers which can be used to point to any of the memory spaces.
8096 Pointer declaration examples:
8101 /* pointer physically in internal ram pointing to object in external ram
8104 xdata unsigned char * data p;
8108 /* pointer physically in external ram pointing to object in internal ram
8111 data unsigned char * xdata p;
8115 /* pointer physically in code rom pointing to data in xdata space */
8117 xdata unsigned char * code p;
8121 /* pointer physically in code space pointing to data in code space */
8123 code unsigned char * code p;
8127 /* the following is a generic pointer physically located in xdata space
8133 Well you get the idea.
8138 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
8151 The highest order byte of the
8155 pointers contains the data space information.
8156 Assembler support routines are called whenever data is stored or retrieved
8162 These are useful for developing reusable library
8163 \begin_inset LatexCommand \index{Libraries}
8168 Explicitly specifying the pointer type will generate the most efficient
8170 \layout Subsubsection
8172 Notes on MCS51 memory
8173 \begin_inset LatexCommand \index{MCS51 memory}
8180 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8181 RAM memory which is structured as follows:
8185 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8188 - Bytes 20-2F - 16 bytes to hold 128 bit
8189 \begin_inset LatexCommand \index{bit}
8195 - Bytes 30-7F - 80 bytes for general purpose use.
8200 Additionally some members of the MCS51 family may have up to 128 bytes of
8201 additional, indirectly addressable, internal RAM memory (
8206 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8211 Furthermore, some chips may have some built in external memory (
8216 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8220 ) which should not be confused with the internal, directly addressable RAM
8226 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8231 Sometimes this built in
8235 memory has to be activated before using it (you can probably find this
8236 information on the datasheet of the microcontroller your are using, see
8238 \begin_inset LatexCommand \ref{sub:Startup-Code}
8246 Normally SDCC will only use the first bank
8247 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8251 of registers (register bank 0), but it is possible to specify that other
8252 banks of registers should be used in interrupt
8253 \begin_inset LatexCommand \index{interrupt}
8258 By default, the compiler will place the stack after the last byte of allocated
8259 memory for variables.
8260 For example, if the first 2 banks of registers are used, and only four
8265 variables, it will position the base of the internal stack at address 20
8267 This implies that as the stack
8268 \begin_inset LatexCommand \index{stack}
8272 grows, it will use up the remaining register banks, and the 16 bytes used
8273 by the 128 bit variables, and 80 bytes for general purpose use.
8274 If any bit variables are used, the data variables will be placed after
8275 the byte holding the last bit variable.
8276 For example, if register banks 0 and 1 are used, and there are 9 bit variables
8281 variables will be placed starting at address 0x22.
8293 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8297 to specify the start address of the
8311 -iram-size to specify the size of the total internal RAM (
8323 By default the 8051 linker will place the stack after the last byte of data
8336 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8340 allows you to specify the start of the stack, i.e.
8341 you could start it after any data in the general purpose area.
8342 If your microcontroller has additional indirectly addressable internal
8347 ) you can place the stack on it.
8348 You may also need to use -
8359 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8363 to set the start address of the external RAM (
8378 \begin_inset LatexCommand \index{-\/-data-loc}
8382 to specify its size.
8383 Same goes for the code memory, using -
8394 \begin_inset LatexCommand \index{-\/-data-loc}
8409 \begin_inset LatexCommand \index{-\/-data-loc}
8414 If in doubt, don't specify any options and see if the resulting memory
8415 layout is appropriate, then you can adjust it.
8418 The linker generates two files with memory allocation information.
8419 The first, with extension .map
8420 \begin_inset LatexCommand \index{<file>.map}
8424 shows all the variables and segments.
8425 The second with extension .mem
8426 \begin_inset LatexCommand \index{<file>.mem}
8430 shows the final memory layout.
8431 The linker will complain either if memory segments overlap, there is not
8432 enough memory, or there is not enough space for stack.
8433 If you get any linking warnings and/or errors related to stack or segments
8434 allocation, take a look at either the .map or .mem files to find out what
8436 The .mem file may even suggest a solution to the problem.
8439 Z80/Z180 Storage Class
8440 \begin_inset LatexCommand \index{Storage class}
8445 \layout Subsubsection
8448 \begin_inset LatexCommand \index{sfr}
8452 (in/out to 8-bit addresses)
8456 \begin_inset LatexCommand \index{Z80}
8460 family has separate address spaces for memory and
8470 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8474 is accessed with special instructions, e.g.:
8479 sfr at 0x78 IoPort;\SpecialChar ~
8481 /* define a var in I/O space at 78h called IoPort */
8485 Writing 0x01 to this variable generates the assembly code:
8505 \layout Subsubsection
8508 \begin_inset LatexCommand \index{sfr}
8512 (in/out to 16-bit addresses)
8519 is used to support 16 bit addresses in I/O memory e.g.:
8524 sfr banked at 0x123 IoPort;
8527 Writing 0x01 to this variable generates the assembly code:
8532 01 23 01\SpecialChar ~
8552 \layout Subsubsection
8555 \begin_inset LatexCommand \index{sfr}
8559 (in0/out0 to 8 bit addresses on Z180
8560 \begin_inset LatexCommand \index{Z180}
8565 \begin_inset LatexCommand \index{HD64180}
8572 The compiler option -
8582 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8584 \begin_inset LatexCommand \index{\#pragma portmode}
8588 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8598 If you include the file z180.h this will be set automatically.
8602 \begin_inset LatexCommand \index{Absolute addressing}
8609 Data items can be assigned an absolute address with the
8612 \begin_inset LatexCommand \index{at}
8618 keyword, in addition to a storage class, e.g.:
8624 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8629 \begin_inset LatexCommand \index{at}
8633 0x7ffe unsigned int chksum;
8636 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8637 of the external ram.
8642 reserve any space for variables declared in this way (they are implemented
8643 with an equate in the assembler).
8644 Thus it is left to the programmer to make sure there are no overlaps with
8645 other variables that are declared without the absolute address.
8646 The assembler listing file (.lst
8647 \begin_inset LatexCommand \index{<file>.lst}
8651 ) and the linker output files (.rst
8652 \begin_inset LatexCommand \index{<file>.rst}
8657 \begin_inset LatexCommand \index{<file>.map}
8661 ) are good places to look for such overlaps.
8662 Variables with an absolute address are
8667 \begin_inset LatexCommand \index{Variable initialization}
8674 In case of memory mapped I/O devices the keyword
8678 should be used to tell the compiler that accesses might not be optimized
8685 \begin_inset LatexCommand \index{volatile}
8690 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8695 \begin_inset LatexCommand \index{at}
8699 0x8000 unsigned char PORTA_8255;
8702 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
8703 r) array starts at a block (256 byte) boundary
8704 \begin_inset LatexCommand \index{block boundary}
8710 Absolute addresses can be specified for variables in all storage classes,
8717 \begin_inset LatexCommand \index{bit}
8722 \begin_inset LatexCommand \index{at}
8729 The above example will allocate the variable at offset 0x02 in the bit-addressab
8731 There is no real advantage to assigning absolute addresses to variables
8732 in this manner, unless you want strict control over all the variables allocated.
8733 One possible use would be to write hardware portable code.
8734 For example, if you have a routine that uses one or more of the microcontroller
8735 I/O pins, and such pins are different for two different hardwares, you
8736 can declare the I/O pins in your routine using:
8741 extern volatile bit SDI;
8743 extern volatile bit SCLK;
8745 extern volatile bit CPOL;
8749 void DS1306_put(unsigned char value)
8757 unsigned char mask=0x80;
8781 SDI=(value & mask)?1:0;
8822 Then, someplace in the code for the first hardware you would use
8827 bit at 0x80 SDI;\SpecialChar ~
8831 /* I/O port 0, bit 0 */
8833 bit at 0x81 SCLK;\SpecialChar ~
8836 /* I/O port 0, bit 1 */
8838 bit CPOL;\SpecialChar ~
8849 /* This is a variable, let the linker allocate this one */
8852 Similarly, for the second hardware you would use
8857 bit at 0x83 SDI;\SpecialChar ~
8861 /* I/O port 0, bit 3 */
8863 bit at 0x91 SCLK;\SpecialChar ~
8866 /* I/O port 1, bit 1 */
8869 \begin_inset LatexCommand \index{bit}
8884 /* This is a variable, let the linker allocate this one */
8887 and you can use the same hardware dependent routine without changes, as
8888 for example in a library.
8889 This is somehow similar to sbit, but only one absolute address has to be
8890 specified in the whole project.
8894 \begin_inset LatexCommand \index{Parameters}
8899 \begin_inset LatexCommand \index{function parameter}
8904 \begin_inset LatexCommand \index{local variables}
8911 Automatic (local) variables and parameters to functions can either be placed
8912 on the stack or in data-space.
8913 The default action of the compiler is to place these variables in the internal
8914 RAM (for small model) or external RAM (for large model).
8915 This in fact makes them similar to
8918 \begin_inset LatexCommand \index{static}
8924 so by default functions are non-reentrant
8925 \begin_inset LatexCommand \index{reentrant}
8934 They can be placed on the stack
8935 \begin_inset LatexCommand \index{stack}
8952 \begin_inset LatexCommand \index{-\/-stack-auto}
8958 option or by using the
8961 \begin_inset LatexCommand \index{reentrant}
8967 keyword in the function declaration, e.g.:
8972 unsigned char foo(char i) reentrant
8986 Since stack space on 8051 is limited, the
9004 option should be used sparingly.
9005 Note that the reentrant keyword just means that the parameters & local
9006 variables will be allocated to the stack, it
9010 mean that the function is register bank
9011 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9020 \begin_inset LatexCommand \index{local variables}
9024 can be assigned storage classes and absolute
9025 \begin_inset LatexCommand \index{Absolute addressing}
9042 xdata unsigned char i;
9054 data at 0x31 unsigned char j;
9066 In the above example the variable
9070 will be allocated in the external ram,
9074 in bit addressable space and
9093 or when a function is declared as
9097 this should only be done for static variables.
9101 \begin_inset LatexCommand \index{function parameter}
9105 however are not allowed any storage class
9106 \begin_inset LatexCommand \index{Storage class}
9110 , (storage classes for parameters will be ignored), their allocation is
9111 governed by the memory model in use, and the reentrancy options.
9115 \begin_inset LatexCommand \label{sub:Overlaying}
9120 \begin_inset LatexCommand \index{Overlaying}
9128 \begin_inset LatexCommand \index{reentrant}
9132 functions SDCC will try to reduce internal ram space usage by overlaying
9133 parameters and local variables of a function (if possible).
9134 Parameters and local variables
9135 \begin_inset LatexCommand \index{local variables}
9139 of a function will be allocated to an overlayable segment if the function
9142 no other function calls and the function is non-reentrant and the memory
9144 \begin_inset LatexCommand \index{Memory model}
9151 If an explicit storage class
9152 \begin_inset LatexCommand \index{Storage class}
9156 is specified for a local variable, it will NOT be overlayed.
9159 Note that the compiler (not the linkage editor) makes the decision for overlayin
9161 Functions that are called from an interrupt service routine should be preceded
9162 by a #pragma\SpecialChar ~
9164 \begin_inset LatexCommand \index{\#pragma nooverlay}
9168 if they are not reentrant.
9171 Also note that the compiler does not do any processing of inline assembler
9172 code, so the compiler might incorrectly assign local variables and parameters
9173 of a function into the overlay segment if the inline assembler code calls
9174 other c-functions that might use the overlay.
9175 In that case the #pragma\SpecialChar ~
9176 nooverlay should be used.
9179 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9181 \begin_inset LatexCommand \index{Multiplication}
9186 \begin_inset LatexCommand \index{Division}
9190 will NOT be overlayed since these are implemented using external functions,
9199 \begin_inset LatexCommand \index{\#pragma nooverlay}
9205 void set_error(unsigned char errcd)
9221 void some_isr () interrupt
9222 \begin_inset LatexCommand \index{interrupt}
9252 In the above example the parameter
9260 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9262 not present, this could cause unpredictable runtime behavior when called
9263 from an interrupt service routine.
9264 The #pragma\SpecialChar ~
9265 nooverlay ensures that the parameters and local variables for
9266 the function are NOT overlayed.
9269 Interrupt Service Routines
9270 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9289 outines to be coded in C, with some extended keywords.
9294 void timer_isr (void) interrupt 1 using 1
9308 The optional number following the
9311 \begin_inset LatexCommand \index{interrupt}
9317 keyword is the interrupt number this routine will service.
9318 When present, the compiler will insert a call to this routine in the interrupt
9319 vector table for the interrupt number specified.
9320 If you have multiple source files in your project, interrupt service routines
9321 can be present in any of them, but a prototype of the isr MUST be present
9322 or included in the file that contains the function
9331 keyword can be used to tell the compiler to use the specified register
9332 bank (8051 specific) when generating code for this function.
9338 Interrupt numbers and the corresponding address & descriptions for the Standard
9339 8051/8052 are listed below.
9340 SDCC will automatically adjust the interrupt vector table to the maximum
9341 interrupt number specified.
9347 \begin_inset Tabular
9348 <lyxtabular version="3" rows="7" columns="3">
9350 <column alignment="center" valignment="top" leftline="true" width="0in">
9351 <column alignment="center" valignment="top" leftline="true" width="0in">
9352 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
9353 <row topline="true" bottomline="true">
9354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9379 <row topline="true">
9380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9405 <row topline="true">
9406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9431 <row topline="true">
9432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9457 <row topline="true">
9458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9483 <row topline="true">
9484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9509 <row topline="true" bottomline="true">
9510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9544 If the interrupt service routine is defined without
9547 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9553 a register bank or with register bank 0 (
9557 0), the compiler will save the registers used by itself on the stack upon
9558 entry and restore them at exit, however if such an interrupt service routine
9559 calls another function then the entire register bank will be saved on the
9561 This scheme may be advantageous for small interrupt service routines which
9562 have low register usage.
9565 If the interrupt service routine is defined to be using a specific register
9570 & psw are save and restored, if such an interrupt service routine calls
9571 another function (using another register bank) then the entire register
9572 bank of the called function will be saved on the stack.
9573 This scheme is recommended for larger interrupt service routines.
9576 Interrupt service routines open the door for some very interesting bugs:
9580 If the interrupt service routines changes variables which are accessed by
9581 other functions these variables should be declared
9586 \begin_inset LatexCommand \index{volatile}
9594 If the access to these variables is not
9597 \begin_inset LatexCommand \index{atomic access}
9604 the processor needs more than one instruction for the access and could
9605 be interrupted while accessing the variable) the interrupt must disabled
9606 during the access to avoid inconsistent data.
9607 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9608 and should be protected by disabling interrupts.
9609 You're not automatically on the safe side if you use 8 bit variables though.
9610 We need an example here: f.e.
9611 on the 8051 the harmless looking
9612 \begin_inset Quotes srd
9622 \begin_inset Quotes sld
9631 \begin_inset Quotes srd
9641 \begin_inset Quotes sld
9644 from within an interrupt routine might get lost if the interrupt occurs
9647 \begin_inset Quotes sld
9652 counter\SpecialChar ~
9657 \begin_inset Quotes srd
9660 is not atomic on the 8051 even if
9664 is located in data memory.
9665 Bugs like these are hard to reproduce and can cause a lot of trouble.
9669 A special note here, int (16 bit) and long (32 bit) integer division
9670 \begin_inset LatexCommand \index{Division}
9675 \begin_inset LatexCommand \index{Multiplication}
9680 \begin_inset LatexCommand \index{Modulus}
9685 \begin_inset LatexCommand \index{Floating point support}
9689 operations are implemented using external support routines developed in
9691 If an interrupt service routine needs to do any of these operations then
9692 the support routines (as mentioned in a following section) will have to
9693 be recompiled using the
9706 \begin_inset LatexCommand \index{-\/-stack-auto}
9712 option and the source file will need to be compiled using the
9727 \begin_inset LatexCommand \index{-\/-int-long-reent}
9734 Calling other functions from an interrupt service routine is not recommended,
9735 avoid it if possible.
9736 Note that when some function is called from an interrupt service routine
9737 it should be preceded by a #pragma\SpecialChar ~
9739 \begin_inset LatexCommand \index{\#pragma nooverlay}
9743 if it is not reentrant.
9744 Furthermore nonreentrant functions should not be called from the main program
9745 while the interrupt service routine might be active.
9751 \begin_inset LatexCommand \ref{sub:Overlaying}
9756 about Overlaying and section
9757 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
9762 about Functions using private register banks.
9765 Enabling and Disabling Interrupts
9768 Critical Functions and Critical Statements
9771 A special keyword may be associated with a function declaring it as
9776 SDCC will generate code to disable all interrupts
9777 \begin_inset LatexCommand \index{interrupt}
9781 upon entry to a critical function and restore the interrupt enable to the
9782 previous state before returning.
9783 Nesting critical functions will need one additional byte on the stack
9784 \begin_inset LatexCommand \index{stack}
9794 \begin_inset LatexCommand \index{critical}
9819 The critical attribute maybe used with other attributes like
9829 may also be used to disable interrupts more locally:
9837 More than one statement could have been included in the block.
9840 Enabling and Disabling Interrupts directly
9844 \begin_inset LatexCommand \index{interrupt}
9848 can also be disabled and enabled directly (8051):
9853 EA = 0;\SpecialChar ~
9916 EA = 1;\SpecialChar ~
9983 On other architectures which have seperate opcodes for enabling and disabling
9984 interrupts you might want to make use of defines with inline assembly
9985 \begin_inset LatexCommand \index{Assembler routines}
9995 \begin_inset LatexCommand \index{\_asm}
10004 \begin_inset LatexCommand \index{\_endasm}
10013 #define SEI _asm\SpecialChar ~
10025 Note: it is sometimes sufficient to disable only a specific interrupt source
10027 a timer or serial interrupt by manipulating an
10030 \begin_inset LatexCommand \index{interrupt mask}
10040 Usually the time during which interrupts are disabled should be kept as
10042 This minimizes both
10047 \begin_inset LatexCommand \index{interrupt latency}
10051 (the time between the occurrence of the interrupt and the execution of
10052 the first code in the interrupt routine) and
10057 \begin_inset LatexCommand \index{interrupt jitter}
10061 (the difference between the shortest and the longest interrupt latency).
10062 These really are something different, f.e.
10063 a serial interrupt has to be served before its buffer overruns so it cares
10064 for the maximum interrupt latency, whereas it does not care about jitter.
10065 On a loudspeaker driven via a digital to analog converter which is fed
10066 by an interrupt a latency of a few milliseconds might be tolerable, whereas
10067 a much smaller jitter will be very audible.
10070 You can reenable interrupts within an interrupt routine and on some architecture
10071 s you can make use of two (or more) levels of
10073 interrupt priorities
10076 \begin_inset LatexCommand \index{interrupt priority}
10081 On some architectures which don't support interrupt priorities these can
10082 be implemented by manipulating the interrupt mask and reenabling interrupts
10083 within the interrupt routine.
10084 Don't add complexity unless you have to.
10088 Functions using private register banks
10089 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10096 Some architectures have support for quickly changing register sets.
10097 SDCC supports this feature with the
10100 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10106 attribute (which tells the compiler to use a register bank
10107 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10111 other than the default bank zero).
10112 It should only be applied to
10115 \begin_inset LatexCommand \index{interrupt}
10121 functions (see footnote below).
10122 This will in most circumstances make the generated ISR code more efficient
10123 since it will not have to save registers on the stack.
10130 attribute will have no effect on the generated code for a
10134 function (but may occasionally be useful anyway
10140 possible exception: if a function is called ONLY from 'interrupt' functions
10141 using a particular bank, it can be declared with the same 'using' attribute
10142 as the calling 'interrupt' functions.
10143 For instance, if you have several ISRs using bank one, and all of them
10144 call memcpy(), it might make sense to create a specialized version of memcpy()
10145 'using 1', since this would prevent the ISR from having to save bank zero
10146 to the stack on entry and switch to bank zero before calling the function
10153 (pending: I don't think this has been done yet)
10160 function using a non-zero bank will assume that it can trash that register
10161 bank, and will not save it.
10162 Since high-priority interrupts
10163 \begin_inset LatexCommand \index{interrupt priority}
10167 can interrupt low-priority ones on the 8051 and friends, this means that
10168 if a high-priority ISR
10172 a particular bank occurs while processing a low-priority ISR
10176 the same bank, terrible and bad things can happen.
10177 To prevent this, no single register bank should be
10181 by both a high priority and a low priority ISR.
10182 This is probably most easily done by having all high priority ISRs use
10183 one bank and all low priority ISRs use another.
10184 If you have an ISR which can change priority at runtime, you're on your
10185 own: I suggest using the default bank zero and taking the small performance
10189 It is most efficient if your ISR calls no other functions.
10190 If your ISR must call other functions, it is most efficient if those functions
10191 use the same bank as the ISR (see note 1 below); the next best is if the
10192 called functions use bank zero.
10193 It is very inefficient to call a function using a different, non-zero bank
10199 \begin_inset LatexCommand \label{sub:Startup-Code}
10204 \begin_inset LatexCommand \index{Startup code}
10211 MCS51/DS390 Startup Code
10214 The compiler inserts a call to the C routine
10216 _sdcc_external_startup()
10217 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10226 at the start of the CODE area.
10227 This routine is in the runtime library
10228 \begin_inset LatexCommand \index{Runtime library}
10233 By default this routine returns 0, if this routine returns a non-zero value,
10234 the static & global variable initialization will be skipped and the function
10235 main will be invoked.
10236 Otherwise static & global variables will be initialized before the function
10240 _sdcc_external_startup()
10242 routine to your program to override the default if you need to setup hardware
10243 or perform some other critical operation prior to static & global variable
10245 On some mcs51 variants xdata has to be explicitly enabled before it can
10246 be accessed, this is the place to do it.
10247 See also the compiler option
10266 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10271 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10276 about MCS51-variants.
10282 The HC08 startup code follows the same scheme as the MCS51 startup code.
10288 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10289 from sdcc/device/lib/z80/crt0.s.
10290 If you need a different startup code you can use the compiler option
10311 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10315 and provide your own crt0.o.
10319 Inline Assembler Code
10320 \begin_inset LatexCommand \index{Assembler routines}
10327 A Step by Step Introduction
10330 Starting from a small snippet of c-code this example shows for the MCS51
10331 how to use inline assembly, access variables, a function parameter and
10332 an array in xdata memory.
10333 The example uses an MCS51 here but is easily adapted for other architectures.
10334 This is a buffer routine which should be optimized:
10340 unsigned char xdata at 0x7f00 buf[0x100];
10342 unsigned char head,tail;
10346 void to_buffer( unsigned char c )
10354 if( head != tail-1 )
10369 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10370 then a corresponding buffer.asm file is generated.
10371 We define a new function
10375 in file buffer.c in which we cut and paste the generated code, removing
10376 unwanted comments and some ':'.
10378 \begin_inset Quotes sld
10382 \begin_inset Quotes srd
10386 \begin_inset Quotes sld
10390 \begin_inset Quotes srd
10393 to the beginning and the end of the function body:
10399 /* With a cut and paste from the .asm file, we have something to start with.
10404 The function is not yet OK! (registers aren't saved) */
10406 void to_buffer_asm( unsigned char c )
10415 \begin_inset LatexCommand \index{\_asm}
10429 ;buffer.c if( head != tail-1 )
10471 ;buffer.c buf[ head++ ] = c;
10567 The new file buffer.c should compile with only one warning about the unreferenced
10568 function argument 'c'.
10569 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
10576 unsigned char xdata at 0x7f00 buf[0x100];
10578 unsigned char head,tail;
10580 #define USE_ASSEMBLY
10584 #ifndef USE_ASSEMBLY
10586 void to_buffer( unsigned char c )
10594 if( head != tail-1 )
10614 void to_buffer( unsigned char c )
10622 c; // to avoid warning: unreferenced function argument
10629 \begin_inset LatexCommand \index{\_asm}
10643 ; save used registers here.
10654 ; If we were still using r2,r3 we would have to push them here.
10657 ; if( head != tail-1 )
10700 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
10724 ; buf[ head++ ] = c;
10735 a,dpl \SpecialChar ~
10742 ; dpl holds lower byte of function argument
10753 dpl,_head \SpecialChar ~
10756 ; buf is 0x100 byte aligned so head can be used directly
10798 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
10810 ; restore used registers here
10823 The inline assembler code can contain any valid code understood by the assembler
10824 , this includes any assembler directives and comment lines
10830 The assembler does not like some characters like ':' or ''' in comments.
10831 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
10835 The compiler does not do any validation of the code within the
10838 \begin_inset LatexCommand \index{\_asm}
10846 Specifically it will not know which registers are used and thus register
10848 \begin_inset LatexCommand \index{push/pop}
10852 has to be done manually.
10856 It is recommended that each assembly instruction (including labels) be placed
10857 in a separate line (as the example shows).
10871 \begin_inset LatexCommand \index{-\/-peep-asm}
10877 command line option is used, the inline assembler code will be passed through
10878 the peephole optimizer
10879 \begin_inset LatexCommand \index{Peephole optimizer}
10884 There are only a few (if any) cases where this option makes sense, it might
10885 cause some unexpected changes in the inline assembler code.
10886 Please go through the peephole optimizer rules defined in file
10890 before using this option.
10894 \begin_inset LatexCommand \label{sub:Naked-Functions}
10899 \begin_inset LatexCommand \index{Naked functions}
10906 A special keyword may be associated with a function declaring it as
10909 \begin_inset LatexCommand \index{\_naked}
10920 function modifier attribute prevents the compiler from generating prologue
10921 \begin_inset LatexCommand \index{function prologue}
10926 \begin_inset LatexCommand \index{function epilogue}
10930 code for that function.
10931 This means that the user is entirely responsible for such things as saving
10932 any registers that may need to be preserved, selecting the proper register
10933 bank, generating the
10937 instruction at the end, etc.
10938 Practically, this means that the contents of the function must be written
10939 in inline assembler.
10940 This is particularly useful for interrupt functions, which can have a large
10941 (and often unnecessary) prologue/epilogue.
10942 For example, compare the code generated by these two functions:
10948 \begin_inset LatexCommand \index{volatile}
10952 data unsigned char counter;
10956 void simpleInterrupt(void) interrupt
10957 \begin_inset LatexCommand \index{interrupt}
10975 void nakedInterrupt(void) interrupt 2 _naked
10984 \begin_inset LatexCommand \index{\_asm}
11001 _counter ; does not change flags, no need to save psw
11013 ; MUST explicitly include ret or reti in _naked function.
11020 \begin_inset LatexCommand \index{\_endasm}
11029 For an 8051 target, the generated simpleInterrupt looks like:
11170 whereas nakedInterrupt looks like:
11185 _counter ; does not change flags, no need to save psw
11203 ; MUST explicitly include ret or reti in _naked function
11206 The related directive #pragma exclude
11207 \begin_inset LatexCommand \index{\#pragma exclude}
11211 allows a more fine grained control over pushing & popping
11212 \begin_inset LatexCommand \index{push/pop}
11219 While there is nothing preventing you from writing C code inside a
11223 function, there are many ways to shoot yourself in the foot doing this,
11224 and it is recommended that you stick to inline assembler.
11227 Use of Labels within Inline Assembler
11230 SDCC allows the use of in-line assembler with a few restrictions regarding
11232 In older versions of the compiler all labels defined within inline assembler
11241 where nnnn is a number less than 100 (which implies a limit of utmost 100
11242 inline assembler labels
11256 \begin_inset LatexCommand \index{\_asm}
11286 \begin_inset LatexCommand \index{\_endasm}
11293 Inline assembler code cannot reference any C-Labels, however it can reference
11295 \begin_inset LatexCommand \index{Labels}
11299 defined by the inline assembler, e.g.:
11324 ; some assembler code
11344 /* some more c code */
11346 clabel:\SpecialChar ~
11348 /* inline assembler cannot reference this label */
11360 $0003: ;label (can be referenced by inline assembler only)
11372 /* some more c code */
11377 In other words inline assembly code can access labels defined in inline
11378 assembly within the scope of the function.
11379 The same goes the other way, i.e.
11380 labels defines in inline assembly can not be accessed by C statements.
11383 Interfacing with Assembler Code
11384 \begin_inset LatexCommand \index{Assembler routines}
11391 Global Registers used for Parameter Passing
11392 \begin_inset LatexCommand \index{Parameter passing}
11399 The compiler always uses the global registers
11402 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11407 \begin_inset LatexCommand \index{DPTR}
11412 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
11421 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
11427 to pass the first parameter to a routine.
11428 The second parameter onwards is either allocated on the stack (for reentrant
11439 -stack-auto is used) or in data / xdata memory (depending on the memory
11444 Assembler Routine (non-reentrant)
11447 In the following example
11448 \begin_inset LatexCommand \index{reentrant}
11453 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11457 the function c_func calls an assembler routine asm_func, which takes two
11459 \begin_inset LatexCommand \index{function parameter}
11468 extern int asm_func(unsigned char, unsigned char);
11472 int c_func (unsigned char i, unsigned char j)
11480 return asm_func(i,j);
11494 return c_func(10,9);
11499 The corresponding assembler function is:
11504 .globl _asm_func_PARM_2
11605 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11622 Note here that the return values
11623 \begin_inset LatexCommand \index{return value}
11627 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
11629 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
11630 b' & 'acc' for four byte values.
11633 The parameter naming convention is _<function_name>_PARM_<n>, where n is
11634 the parameter number starting from 1, and counting from the left.
11635 The first parameter is passed in
11636 \begin_inset Quotes eld
11640 \begin_inset Quotes erd
11643 for a one byte parameter,
11644 \begin_inset Quotes eld
11648 \begin_inset Quotes erd
11652 \begin_inset Quotes eld
11656 \begin_inset Quotes erd
11659 for three bytes and
11660 \begin_inset Quotes eld
11664 \begin_inset Quotes erd
11667 for a four bytes parameter.
11668 The variable name for the second parameter will be _<function_name>_PARM_2.
11672 Assemble the assembler routine with the following command:
11679 asx8051 -losg asmfunc.asm
11686 Then compile and link the assembler routine to the C source file with the
11694 sdcc cfunc.c asmfunc.rel
11697 Assembler Routine (reentrant)
11701 \begin_inset LatexCommand \index{reentrant}
11706 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
11710 the second parameter
11711 \begin_inset LatexCommand \index{function parameter}
11715 onwards will be passed on the stack, the parameters are pushed from right
11717 after the call the leftmost parameter will be on the top of the stack.
11718 Here is an example:
11723 extern int asm_func(unsigned char, unsigned char);
11727 int c_func (unsigned char i, unsigned char j) reentrant
11735 return asm_func(i,j);
11749 return c_func(10,9);
11754 The corresponding assembler routine is:
11854 The compiling and linking procedure remains the same, however note the extra
11855 entry & exit linkage required for the assembler code, _bp is the stack
11856 frame pointer and is used to compute the offset into the stack for parameters
11857 and local variables.
11861 \begin_inset LatexCommand \index{int (16 bit)}
11866 \begin_inset LatexCommand \index{long (32 bit)}
11873 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
11874 multiplication and modulus operations are implemented by support routines.
11875 These support routines are all developed in ANSI-C to facilitate porting
11876 to other MCUs, although some model specific assembler optimizations are
11878 The following files contain the described routines, all of them can be
11879 found in <installdir>/share/sdcc/lib.
11885 \begin_inset Tabular
11886 <lyxtabular version="3" rows="11" columns="2">
11888 <column alignment="center" valignment="top" leftline="true" width="0">
11889 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
11890 <row topline="true" bottomline="true">
11891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11912 <row topline="true">
11913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11926 16 bit multiplication
11930 <row topline="true">
11931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11944 signed 16 bit division (calls _divuint)
11948 <row topline="true">
11949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11962 unsigned 16 bit division
11966 <row topline="true">
11967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11980 signed 16 bit modulus (calls _moduint)
11984 <row topline="true">
11985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11998 unsigned 16 bit modulus
12002 <row topline="true">
12003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12016 32 bit multiplication
12020 <row topline="true">
12021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12034 signed 32 division (calls _divulong)
12038 <row topline="true">
12039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12052 unsigned 32 division
12056 <row topline="true">
12057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12070 signed 32 bit modulus (calls _modulong)
12074 <row topline="true" bottomline="true">
12075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12088 unsigned 32 bit modulus
12101 Since they are compiled as
12106 \begin_inset LatexCommand \index{reentrant}
12111 \begin_inset LatexCommand \index{interrupt}
12115 service routines should not do any of the above operations.
12116 If this is unavoidable then the above routines will need to be compiled
12130 \begin_inset LatexCommand \index{-\/-stack-auto}
12136 option, after which the source program will have to be compiled with
12149 \begin_inset LatexCommand \index{-\/-int-long-reent}
12156 Notice that you don't have to call these routines directly.
12157 The compiler will use them automatically every time an integer operation
12161 Floating Point Support
12162 \begin_inset LatexCommand \index{Floating point support}
12169 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12170 floating point support routines are derived from gcc's floatlib.c and consist
12171 of the following routines:
12179 \begin_inset Tabular
12180 <lyxtabular version="3" rows="17" columns="2">
12182 <column alignment="center" valignment="top" leftline="true" width="0">
12183 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12184 <row topline="true" bottomline="true">
12185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12211 <row topline="true">
12212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12243 add floating point numbers
12247 <row topline="true">
12248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12279 subtract floating point numbers
12283 <row topline="true">
12284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12315 divide floating point numbers
12319 <row topline="true">
12320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12351 multiply floating point numbers
12355 <row topline="true">
12356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12387 convert floating point to unsigned char
12391 <row topline="true">
12392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12423 convert floating point to signed char
12427 <row topline="true">
12428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12459 convert floating point to unsigned int
12463 <row topline="true">
12464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12495 convert floating point to signed int
12499 <row topline="true">
12500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12540 convert floating point to unsigned long
12544 <row topline="true">
12545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12576 convert floating point to signed long
12580 <row topline="true">
12581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12612 convert unsigned char to floating point
12616 <row topline="true">
12617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12648 convert char to floating point number
12652 <row topline="true">
12653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12684 convert unsigned int to floating point
12688 <row topline="true">
12689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12720 convert int to floating point numbers
12724 <row topline="true">
12725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12756 convert unsigned long to floating point number
12760 <row topline="true" bottomline="true">
12761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12792 convert long to floating point number
12805 These support routines are developed in ANSI-C so there is room for space
12806 and speed improvement.
12807 Note if all these routines are used simultaneously the data space might
12809 For serious floating point usage it is recommended that the large model
12811 Also notice that you don't have to call this routines directly.
12812 The compiler will use them automatically every time a floating point operation
12817 \begin_inset LatexCommand \index{Libraries}
12826 <pending: this is messy and incomplete - a little more information is in
12827 sdcc/doc/libdoc.txt
12832 Compiler support routines (_gptrget, _mulint etc.)
12835 Stdclib functions (puts, printf, strcat etc.)
12836 \layout Subsubsection
12842 \begin_inset LatexCommand \index{<stdio.h>}
12846 As usual on embedded systems you have to provide your own
12849 \begin_inset LatexCommand \index{getchar()}
12858 \begin_inset LatexCommand \index{putchar()}
12865 SDCC does not know whether the system connects to a serial line with or
12866 without handshake, LCD, keyboard or other device.
12867 You'll find examples for serial routines f.e.
12868 in sdcc/device/lib.
12871 If you're short on memory you might want to use
12882 \begin_inset LatexCommand \index{printf()}
12889 For the mcs51 there is an assembly version
12893 which should fit the requirements of many embedded systems.
12896 Math functions (sin, pow, sqrt etc.)
12903 \begin_inset LatexCommand \index{Libraries}
12907 included in SDCC should have a license at least as liberal as the GNU Lesser
12908 General Public License
12909 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
12920 license statements for the libraries are missing.
12921 sdcc/device/lib/ser_ir.c
12925 come with a GPL (as opposed to LGPL) License - this will not be liberal
12926 enough for many embedded programmers.
12929 If you have ported some library or want to share experience about some code
12931 falls into any of these categories Busses (I
12932 \begin_inset Formula $^{\textrm{2}}$
12935 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
12936 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
12937 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
12938 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
12943 would certainly like to hear about it.
12944 Programmers coding for embedded systems are not especially famous for being
12945 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
12946 e these references are very valuable.
12947 Let's help to create a climate where information is shared.
12953 MCS51 Memory Models
12954 \begin_inset LatexCommand \index{Memory model}
12959 \begin_inset LatexCommand \index{MCS51 memory model}
12964 \layout Subsubsection
12969 SDCC allows two memory models for MCS51 code,
12978 Modules compiled with different memory models should
12982 be combined together or the results would be unpredictable.
12983 The library routines supplied with the compiler are compiled as both small
12985 The compiled library modules are contained in separate directories as small
12986 and large so that you can link to either set.
12990 When the large model is used all variables declared without a storage class
12991 will be allocated into the external ram, this includes all parameters and
12992 local variables (for non-reentrant
12993 \begin_inset LatexCommand \index{reentrant}
12998 When the small model is used variables without storage class are allocated
12999 in the internal ram.
13002 Judicious usage of the processor specific storage classes
13003 \begin_inset LatexCommand \index{Storage class}
13007 and the 'reentrant' function type will yield much more efficient code,
13008 than using the large model.
13009 Several optimizations are disabled when the program is compiled using the
13010 large model, it is therefore recommended that the small model be used unless
13011 absolutely required.
13012 \layout Subsubsection
13015 \begin_inset LatexCommand \label{sub:External-Stack}
13020 \begin_inset LatexCommand \index{stack}
13025 \begin_inset LatexCommand \index{External stack (mcs51)}
13032 The external stack (-
13043 \begin_inset LatexCommand \index{-\/-xstack}
13047 ) is located in pdata
13048 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13052 memory (usually at the start of the external ram segment) and is 256 bytes
13064 -xstack option is used to compile the program, the parameters and local
13066 \begin_inset LatexCommand \index{local variables}
13070 of all reentrant functions are allocated in this area.
13071 This option is provided for programs with large stack space requirements.
13072 When used with the -
13083 \begin_inset LatexCommand \index{-\/-stack-auto}
13087 option, all parameters and local variables are allocated on the external
13088 stack (note: support libraries will need to be recompiled with the same
13092 The compiler outputs the higher order address byte of the external ram segment
13094 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13098 , therefore when using the External Stack option, this port
13102 be used by the application program.
13106 \begin_inset LatexCommand \index{Memory model}
13111 \begin_inset LatexCommand \index{DS390 memory model}
13118 The only model supported is Flat 24
13119 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13124 This generates code for the 24 bit contiguous addressing mode of the Dallas
13126 In this mode, up to four meg of external RAM or code space can be directly
13128 See the data sheets at www.dalsemi.com for further information on this part.
13132 Note that the compiler does not generate any code to place the processor
13133 into 24 bitmode (although
13137 in the ds390 libraries will do that for you).
13143 \begin_inset LatexCommand \index{Tinibios (DS390)}
13147 , the boot loader or similar code must ensure that the processor is in 24
13148 bit contiguous addressing mode before calling the SDCC startup code.
13166 option, variables will by default be placed into the XDATA segment.
13171 Segments may be placed anywhere in the 4 meg address space using the usual
13183 Note that if any segments are located above 64K, the -r flag must be passed
13184 to the linker to generate the proper segment relocations, and the Intel
13185 HEX output format must be used.
13186 The -r flag can be passed to the linker by using the option
13190 on the SDCC command line.
13191 However, currently the linker can not handle code segments > 64k.
13195 \begin_inset LatexCommand \index{Pragmas}
13202 SDCC supports the following #pragma directives:
13206 \begin_inset LatexCommand \index{\#pragma save}
13210 - this will save all current options to the save/restore stack.
13215 \begin_inset LatexCommand \index{\#pragma restore}
13219 - will restore saved options from the last save.
13220 saves & restores can be nested.
13221 SDCC uses a save/restore stack: save pushes current options to the stack,
13222 restore pulls current options from the stack.
13227 \begin_inset LatexCommand \index{\#pragma nogcse}
13231 - will stop global common subexpression elimination.
13235 \begin_inset LatexCommand \index{\#pragma noinduction}
13239 - will stop loop induction optimizations.
13243 \begin_inset LatexCommand \index{\#pragma nojtbound}
13247 - will not generate code for boundary value checking, when switch statements
13248 are turned into jump-tables (dangerous).
13249 For more details see section
13250 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
13258 \begin_inset LatexCommand \index{\#pragma nooverlay}
13262 - the compiler will not overlay the parameters and local variables of a
13267 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13271 - the compiler will not warn you anymore for obvious mistakes, you'r on
13276 \begin_inset LatexCommand \index{\#pragma noloopreverse}
13280 - Will not do loop reversal optimization
13284 \begin_inset LatexCommand \index{\#pragma exclude}
13288 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
13290 \begin_inset LatexCommand \index{push/pop}
13294 instruction in ISR function (using interrupt
13295 \begin_inset LatexCommand \index{interrupt}
13300 The directive should be placed immediately before the ISR function definition
13301 and it affects ALL ISR functions following it.
13302 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13303 exclude\SpecialChar ~
13305 \begin_inset LatexCommand \index{\#pragma exclude}
13313 \begin_inset LatexCommand \index{\#pragma noiv}
13317 - Do not generate interrupt
13318 \begin_inset LatexCommand \index{interrupt}
13322 vector table entries for all ISR functions defined after the pragma.
13323 This is useful in cases where the interrupt vector table must be defined
13324 manually, or when there is a secondary, manually defined interrupt vector
13326 for the autovector feature of the Cypress EZ-USB FX2).
13327 More elegantly this can be achieved by obmitting the optional interrupt
13328 number after the interrupt keyword, see section
13329 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13338 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13343 \begin_inset LatexCommand \index{function prologue}
13347 function1[,function2[,function3...]] - The compiler by default uses a caller
13348 saves convention for register saving across function calls, however this
13349 can cause unnecessary register pushing & popping
13350 \begin_inset LatexCommand \index{push/pop}
13354 when calling small functions from larger functions.
13355 This option can be used to switch off the register saving convention for
13356 the function names specified.
13357 The compiler will not save registers when calling these functions, extra
13358 code need to be manually inserted at the entry & exit for these functions
13359 to save & restore the registers used by these functions, this can SUBSTANTIALLY
13360 reduce code & improve run time performance of the generated code.
13361 In the future the compiler (with inter procedural analysis) may be able
13362 to determine the appropriate scheme to use for each function call.
13373 -callee-saves command line option is used, the function names specified
13374 in #pragma\SpecialChar ~
13376 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13380 is appended to the list of functions specified in the command line.
13383 SDCPP supports the following #pragma directives:
13387 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
13391 (+ | -) - switch _asm _endasm block preprocessing on / off.
13395 The pragma's are intended to be used to turn-on or off certain optimizations
13396 which might cause the compiler to generate extra stack / data space to
13397 store compiler generated temporary variables.
13398 This usually happens in large functions.
13399 Pragma directives should be used as shown in the following example, they
13400 are used to control options & optimizations for a given function; pragmas
13401 should be placed before and/or after a function, placing pragma's inside
13402 a function body could have unpredictable results.
13408 \begin_inset LatexCommand \index{\#pragma save}
13419 /* save the current settings */
13422 \begin_inset LatexCommand \index{\#pragma nogcse}
13431 /* turnoff global subexpression elimination */
13433 #pragma noinduction
13434 \begin_inset LatexCommand \index{\#pragma noinduction}
13438 /* turn off induction optimizations */
13461 \begin_inset LatexCommand \index{\#pragma restore}
13465 /* turn the optimizations back on */
13468 The compiler will generate a warning message when extra space is allocated.
13469 It is strongly recommended that the save and restore pragma's be used when
13470 changing options for a function.
13473 Defines Created by the Compiler
13476 The compiler creates the following #defines
13477 \begin_inset LatexCommand \index{\#defines}
13482 \begin_inset LatexCommand \index{Defines created by the compiler}
13492 \begin_inset Tabular
13493 <lyxtabular version="3" rows="10" columns="2">
13495 <column alignment="center" valignment="top" leftline="true" width="0">
13496 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13497 <row topline="true" bottomline="true">
13498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13519 <row topline="true">
13520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13526 \begin_inset LatexCommand \index{SDCC}
13533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13538 this Symbol is always defined
13542 <row topline="true">
13543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13549 \begin_inset LatexCommand \index{SDCC\_mcs51}
13554 \begin_inset LatexCommand \index{SDCC\_ds390}
13559 \begin_inset LatexCommand \index{SDCC\_z80}
13566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13571 depending on the model used (e.g.: -mds390
13575 <row topline="true">
13576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13582 \begin_inset LatexCommand \index{\_\_mcs51}
13587 \begin_inset LatexCommand \index{\_\_ds390}
13592 \begin_inset LatexCommand \index{\_\_hc08}
13597 \begin_inset LatexCommand \index{\_\_z80}
13604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13609 depending on the model used (e.g.
13614 <row topline="true">
13615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13621 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
13628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13651 <row topline="true">
13652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13658 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
13665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13688 <row topline="true">
13689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13695 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
13702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13725 <row topline="true">
13726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13732 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
13739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13762 <row topline="true">
13763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13769 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
13776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13789 <row topline="true" bottomline="true">
13790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13796 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
13803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13825 Debugging with SDCDB
13826 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
13831 \begin_inset LatexCommand \index{sdcdb (debugger)}
13838 SDCC is distributed with a source level debugger
13839 \begin_inset LatexCommand \index{Debugger}
13844 The debugger uses a command line interface, the command repertoire of the
13845 debugger has been kept as close to gdb
13846 \begin_inset LatexCommand \index{gdb}
13850 (the GNU debugger) as possible.
13851 The configuration and build process is part of the standard compiler installati
13852 on, which also builds and installs the debugger in the target directory
13853 specified during configuration.
13854 The debugger allows you debug BOTH at the C source and at the ASM source
13856 Sdcdb is available on Unix platforms only.
13859 Compiling for Debugging
13862 The \SpecialChar \-
13864 debug option must be specified for all files for which debug information
13865 is to be generated.
13866 The complier generates a .adb file for each of these files.
13867 The linker creates the .cdb file from the .adb files and the address information.
13868 This .cdb is used by the debugger.
13871 How the Debugger Works
13884 -debug option is specified the compiler generates extra symbol information
13885 some of which are put into the assembler source and some are put into the
13887 Then the linker creates the .cdb file from the individual .adb files with
13888 the address information for the symbols.
13889 The debugger reads the symbolic information generated by the compiler &
13890 the address information generated by the linker.
13891 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13892 execution is controlled by the debugger.
13893 When a command is issued for the debugger, it translates it into appropriate
13894 commands for the simulator.
13897 Starting the Debugger
13900 The debugger can be started using the following command line.
13901 (Assume the file you are debugging has the file name foo).
13915 The debugger will look for the following files.
13918 foo.c - the source file.
13921 foo.cdb - the debugger symbol information file.
13924 foo.ihx - the Intel hex format
13925 \begin_inset LatexCommand \index{Intel hex format}
13932 Command Line Options.
13945 -directory=<source file directory> this option can used to specify the directory
13947 The debugger will look into the directory list specified for source, cdb
13949 The items in the directory list must be separated by ':', e.g.
13950 if the source files can be in the directories /home/src1 and /home/src2,
13961 -directory option should be -
13971 -directory=/home/src1:/home/src2.
13972 Note there can be no spaces in the option.
13976 -cd <directory> - change to the <directory>.
13979 -fullname - used by GUI front ends.
13982 -cpu <cpu-type> - this argument is passed to the simulator please see the
13983 simulator docs for details.
13986 -X <Clock frequency > this options is passed to the simulator please see
13987 the simulator docs for details.
13990 -s <serial port file> passed to simulator see the simulator docs for details.
13993 -S <serial in,out> passed to simulator see the simulator docs for details.
13996 -k <port number> passed to simulator see the simulator docs for details.
14002 As mentioned earlier the command interface for the debugger has been deliberatel
14003 y kept as close the GNU debugger gdb, as possible.
14004 This will help the integration with existing graphical user interfaces
14005 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14006 If you use a graphical user interface for the debugger you can skip the
14008 \layout Subsubsection*
14010 break [line | file:line | function | file:function]
14013 Set breakpoint at specified line or function:
14022 sdcdb>break foo.c:100
14024 sdcdb>break funcfoo
14026 sdcdb>break foo.c:funcfoo
14027 \layout Subsubsection*
14029 clear [line | file:line | function | file:function ]
14032 Clear breakpoint at specified line or function:
14041 sdcdb>clear foo.c:100
14043 sdcdb>clear funcfoo
14045 sdcdb>clear foo.c:funcfoo
14046 \layout Subsubsection*
14051 Continue program being debugged, after breakpoint.
14052 \layout Subsubsection*
14057 Execute till the end of the current function.
14058 \layout Subsubsection*
14063 Delete breakpoint number 'n'.
14064 If used without any option clear ALL user defined break points.
14065 \layout Subsubsection*
14067 info [break | stack | frame | registers ]
14070 info break - list all breakpoints
14073 info stack - show the function call stack.
14076 info frame - show information about the current execution frame.
14079 info registers - show content of all registers.
14080 \layout Subsubsection*
14085 Step program until it reaches a different source line.
14086 Note: pressing <return> repeats the last command.
14087 \layout Subsubsection*
14092 Step program, proceeding through subroutine calls.
14093 \layout Subsubsection*
14098 Start debugged program.
14099 \layout Subsubsection*
14104 Print type information of the variable.
14105 \layout Subsubsection*
14110 print value of variable.
14111 \layout Subsubsection*
14116 load the given file name.
14117 Note this is an alternate method of loading file for debugging.
14118 \layout Subsubsection*
14123 print information about current frame.
14124 \layout Subsubsection*
14129 Toggle between C source & assembly source.
14130 \layout Subsubsection*
14132 ! simulator command
14135 Send the string following '!' to the simulator, the simulator response is
14137 Note the debugger does not interpret the command being sent to the simulator,
14138 so if a command like 'go' is sent the debugger can loose its execution
14139 context and may display incorrect values.
14140 \layout Subsubsection*
14147 My name is Bobby Brown"
14150 Interfacing with XEmacs
14151 \begin_inset LatexCommand \index{XEmacs}
14156 \begin_inset LatexCommand \index{Emacs}
14163 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14164 sdcdb.el and sdcdbsrc.el.
14165 These two files can be found in the $(prefix)/bin directory after the installat
14167 These files need to be loaded into XEmacs for the interface to work.
14168 This can be done at XEmacs startup time by inserting the following into
14169 your '.xemacs' file (which can be found in your HOME directory):
14175 (load-file sdcdbsrc.el)
14181 .xemacs is a lisp file so the () around the command is REQUIRED.
14182 The files can also be loaded dynamically while XEmacs is running, set the
14183 environment variable 'EMACSLOADPATH' to the installation bin directory
14184 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14185 To start the interface enter the following command:
14199 You will prompted to enter the file name to be debugged.
14204 The command line options that are passed to the simulator directly are bound
14205 to default values in the file sdcdbsrc.el.
14206 The variables are listed below, these values maybe changed as required.
14209 sdcdbsrc-cpu-type '51
14212 sdcdbsrc-frequency '11059200
14215 sdcdbsrc-serial nil
14218 The following is a list of key mapping for the debugger interface.
14226 ;; Current Listing ::
14228 ;;key\SpecialChar ~
14243 binding\SpecialChar ~
14267 ;;---\SpecialChar ~
14282 ------\SpecialChar ~
14322 sdcdb-next-from-src\SpecialChar ~
14348 sdcdb-back-from-src\SpecialChar ~
14374 sdcdb-cont-from-src\SpecialChar ~
14384 SDCDB continue command
14400 sdcdb-step-from-src\SpecialChar ~
14426 sdcdb-whatis-c-sexp\SpecialChar ~
14436 SDCDB ptypecommand for data at
14500 sdcdbsrc-delete\SpecialChar ~
14514 SDCDB Delete all breakpoints if no arg
14562 given or delete arg (C-u arg x)
14578 sdcdbsrc-frame\SpecialChar ~
14593 SDCDB Display current frame if no arg,
14642 given or display frame arg
14707 sdcdbsrc-goto-sdcdb\SpecialChar ~
14717 Goto the SDCDB output buffer
14733 sdcdb-print-c-sexp\SpecialChar ~
14744 SDCDB print command for data at
14808 sdcdbsrc-goto-sdcdb\SpecialChar ~
14818 Goto the SDCDB output buffer
14834 sdcdbsrc-mode\SpecialChar ~
14850 Toggles Sdcdbsrc mode (turns it off)
14854 ;; C-c C-f\SpecialChar ~
14862 sdcdb-finish-from-src\SpecialChar ~
14870 SDCDB finish command
14874 ;; C-x SPC\SpecialChar ~
14882 sdcdb-break\SpecialChar ~
14900 Set break for line with point
14902 ;; ESC t\SpecialChar ~
14912 sdcdbsrc-mode\SpecialChar ~
14928 Toggle Sdcdbsrc mode
14930 ;; ESC m\SpecialChar ~
14940 sdcdbsrc-srcmode\SpecialChar ~
14962 Here are a few guidelines that will help the compiler generate more efficient
14963 code, some of the tips are specific to this compiler others are generally
14964 good programming practice.
14967 Use the smallest data type to represent your data-value.
14968 If it is known in advance that the value is going to be less than 256 then
14969 use an 'unsigned char' instead of a 'short' or 'int'.
14970 Please note, that ANSI C requires both signed and unsigned chars to be
14971 promoted to 'signed int' before doing any operation.
14972 This promotion can be omitted, if the result is the same.
14973 The effect of the promotion rules together with the sign-extension is often
14980 unsigned char uc = 0xfe;
14982 if (uc * uc < 0) /* this is true! */
15001 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
15011 (unsigned char) -12 / (signed char) -3 = ...
15014 No, the result is not 4:
15019 (int) (unsigned char) -12 / (int) (signed char) -3 =
15021 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
15023 (int) 0x00f4 / (int) 0xfffd =
15025 (int) 0x00f4 / (int) 0xfffd =
15027 (int) 244 / (int) -3 =
15029 (int) -81 = (int) 0xffaf;
15032 Don't complain, that gcc gives you a different result.
15033 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
15034 Therefore the results are different.
15037 \begin_inset Quotes sld
15041 \begin_inset Quotes srd
15047 If well-defined overflow characteristics are important and negative values
15048 are not, or if you want to steer clear of sign-extension problems when
15049 manipulating bits or bytes, use one of the corresponding unsigned types.
15050 (Beware when mixing signed and unsigned values in expressions, though.)
15052 Although character types (especially unsigned char) can be used as "tiny"
15053 integers, doing so is sometimes more trouble than it's worth, due to unpredicta
15054 ble sign extension and increased code size.
15058 Use unsigned when it is known in advance that the value is not going to
15060 This helps especially if you are doing division or multiplication, bit-shifting
15061 or are using an array index.
15064 NEVER jump into a LOOP.
15067 Declare the variables to be local
15068 \begin_inset LatexCommand \index{local variables}
15072 whenever possible, especially loop control variables (induction).
15075 Since the compiler does not always do implicit integral promotion, the programme
15076 r should do an explicit cast when integral promotion is required.
15079 Reducing the size of division, multiplication & modulus operations can reduce
15080 code size substantially.
15081 Take the following code for example.
15087 foobar(unsigned int p1, unsigned char ch)
15095 unsigned char ch1 = p1 % ch ;
15106 For the modulus operation the variable ch will be promoted to unsigned int
15107 first then the modulus operation will be performed (this will lead to a
15108 call to support routine _moduint()), and the result will be casted to a
15110 If the code is changed to
15115 foobar(unsigned int p1, unsigned char ch)
15123 unsigned char ch1 = (unsigned char)p1 % ch ;
15134 It would substantially reduce the code generated (future versions of the
15135 compiler will be smart enough to detect such optimization opportunities).
15139 Have a look at the assembly listing to get a
15140 \begin_inset Quotes sld
15144 \begin_inset Quotes srd
15147 for the code generation.
15151 \begin_inset LatexCommand \index{Tools}
15155 included in the distribution
15159 \begin_inset Tabular
15160 <lyxtabular version="3" rows="12" columns="3">
15162 <column alignment="center" valignment="top" leftline="true" width="0pt">
15163 <column alignment="center" valignment="top" leftline="true" width="0pt">
15164 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
15165 <row topline="true" bottomline="true">
15166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15191 <row topline="true">
15192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15205 Simulator for various architectures
15208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15217 <row topline="true">
15218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15231 header file conversion
15234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15239 sdcc/support/scripts
15243 <row topline="true">
15244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15257 header file conversion
15260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15265 sdcc/support/scripts
15269 <row topline="true">
15270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15304 <row topline="true">
15305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15339 <row topline="true">
15340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15374 <row topline="true">
15375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15409 <row topline="true">
15410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15444 <row topline="true">
15445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15479 <row topline="true">
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15514 <row topline="true" bottomline="true">
15515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15559 \begin_inset LatexCommand \index{Documentation}
15563 included in the distribution
15567 \begin_inset Tabular
15568 <lyxtabular version="3" rows="10" columns="2">
15570 <column alignment="left" valignment="top" leftline="true" width="0">
15571 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
15572 <row topline="true" bottomline="true">
15573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15586 Where to get / filename
15590 <row topline="true">
15591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15596 SDCC Compiler User Guide
15599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15604 You're reading it right now
15608 <row topline="true">
15609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15626 <row topline="true">
15627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15632 ASXXXX Assemblers and ASLINK Relocating Linker
15635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15640 sdcc/as/doc/asxhtm.html
15644 <row topline="true">
15645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15650 SDCC regression test
15651 \begin_inset LatexCommand \index{Regression test}
15658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15663 sdcc/doc/test_suite_spec.pdf
15667 <row topline="true">
15668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15685 <row topline="true">
15686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15691 Notes on debugging with sdcdb
15692 \begin_inset LatexCommand \index{sdcdb (debugger)}
15699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15704 sdcc/debugger/README
15708 <row topline="true">
15709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15714 Software simulator for microcontrollers
15717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15744 <row topline="true">
15745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15750 Temporary notes on the pic16
15751 \begin_inset LatexCommand \index{PIC16}
15758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15763 sdcc/src/pic16/NOTES
15767 <row topline="true" bottomline="true">
15768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15773 SDCC internal documentation (debugging file format)
15776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15812 Related open source tools
15813 \begin_inset LatexCommand \index{Related tools}
15821 \begin_inset Tabular
15822 <lyxtabular version="3" rows="10" columns="3">
15824 <column alignment="center" valignment="top" leftline="true" width="0pt">
15825 <column alignment="block" valignment="top" leftline="true" width="30line%">
15826 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
15827 <row topline="true" bottomline="true">
15828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15853 <row topline="true">
15854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15860 \begin_inset LatexCommand \index{gpsim (PIC simulator)}
15867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15881 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
15889 <row topline="true">
15890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15912 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
15920 <row topline="true">
15921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15927 \begin_inset LatexCommand \index{indent (source formatting tool)}
15934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15939 Formats C source - Master of the white spaces
15942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15948 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
15956 <row topline="true">
15957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15963 \begin_inset LatexCommand \index{srecord (tool)}
15970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15975 Object file conversion, checksumming, ...
15978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15984 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
15992 <row topline="true">
15993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15999 \begin_inset LatexCommand \index{objdump (tool)}
16006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16011 Object file conversion, ...
16014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16019 Part of binutils (should be there anyway)
16023 <row topline="true">
16024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16030 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
16037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16042 Source code documentation system
16045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16051 \begin_inset LatexCommand \url{http://www.doxygen.org}
16059 <row topline="true">
16060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16073 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
16076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16082 \begin_inset LatexCommand \url{http://www.kdevelop.org}
16090 <row topline="true">
16091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16097 \begin_inset LatexCommand \index{splint (syntax checking tool)}
16104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16109 Statically checks c sources
16112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16118 \begin_inset LatexCommand \url{http://www.splint.org}
16126 <row topline="true" bottomline="true">
16127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16133 \begin_inset LatexCommand \index{ddd (debugger)}
16140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16145 Debugger, serves nicely as GUI to sdcdb
16146 \begin_inset LatexCommand \index{sdcdb (debugger)}
16153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16159 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
16176 Related documentation / recommended reading
16180 \begin_inset Tabular
16181 <lyxtabular version="3" rows="4" columns="3">
16183 <column alignment="center" valignment="top" leftline="true" width="0pt">
16184 <column alignment="block" valignment="top" leftline="true" width="30line%">
16185 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16186 <row topline="true" bottomline="true">
16187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16212 <row topline="true">
16213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16236 \begin_inset LatexCommand \index{C Reference card}
16243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16249 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
16257 <row topline="true">
16258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16280 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
16288 <row topline="true" bottomline="true">
16289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16304 Advanced Compiler Design and Implementation
16307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16312 bookstore (very dedicated, probably read other books first)
16328 Some questions answered, some pointers given - it might be time to in turn
16336 can you solve your project with the selected microcontroller? Would you
16337 find out early or rather late that your target is too small/slow/whatever?
16338 Can you switch to a slightly better device if it doesn't fit?
16341 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
16342 and/or another programming language be more adequate? Would an operating
16343 system on the target device help?
16346 if you solved the problem, will the marketing department be happy?
16349 if the marketing department is happy, will customers be happy?
16352 if you're the project manager, marketing department and maybe even the customer
16353 in one person, have you tried to see the project from the outside?
16356 is the project done if you think it is done? Or is just that other interface/pro
16357 tocol/feature/configuration/option missing? How about website, manual(s),
16358 internationalization, packaging, labels, electromagnetic compatability/interfer
16359 ence, documentation for production, production test software, update mechanism,
16363 is your project adequately positioned in that magic triangle: fame, fortune,
16367 Maybe not all answers to these questions are known and some answers may
16372 , nevertheless knowing these questions may help you to avoid burnout
16378 burnout is bad for electronic devices, programmers and motorcycle tyres
16382 Chances are you didn't want to hear some of them...
16386 \begin_inset LatexCommand \index{Support}
16393 SDCC has grown to be a large project.
16394 The compiler alone (without the preprocessor, assembler and linker) is
16395 well over 100,000 lines of code (blank stripped).
16396 The open source nature of this project is a key to its continued growth
16398 You gain the benefit and support of many active software developers and
16400 Is SDCC perfect? No, that's why we need your help.
16401 The developers take pride in fixing reported bugs.
16402 You can help by reporting the bugs and helping other SDCC users.
16403 There are lots of ways to contribute, and we encourage you to take part
16404 in making SDCC a great software package.
16408 The SDCC project is hosted on the SDCC sourceforge site at
16409 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
16414 You'll find the complete set of mailing lists
16415 \begin_inset LatexCommand \index{Mailing list}
16419 , forums, bug reporting system, patch submission
16420 \begin_inset LatexCommand \index{Patch submission}
16425 \begin_inset LatexCommand \index{download}
16429 area and cvs code repository
16430 \begin_inset LatexCommand \index{cvs code repository}
16438 \begin_inset LatexCommand \index{Bug reporting}
16443 \begin_inset LatexCommand \index{Reporting bugs}
16450 The recommended way of reporting bugs is using the infrastructure of the
16452 You can follow the status of bug reports there and have an overview about
16456 Bug reports are automatically forwarded to the developer mailing list and
16457 will be fixed ASAP.
16458 When reporting a bug, it is very useful to include a small test program
16459 (the smaller the better) which reproduces the problem.
16460 If you can isolate the problem by looking at the generated assembly code,
16461 this can be very helpful.
16462 Compiling your program with the -
16473 \begin_inset LatexCommand \index{-\/-dumpall}
16477 option can sometimes be useful in locating optimization problems.
16478 When reporting a bug please maker sure you:
16481 Attach the code you are compiling with SDCC.
16485 Specify the exact command you use to run SDCC, or attach your Makefile.
16489 Specify the SDCC version (type "sdcc -v"), your platform, and operating
16494 Provide an exact copy of any error message or incorrect output.
16498 Put something meaningful in the subject of your message.
16501 Please attempt to include these 5 important parts, as applicable, in all
16502 requests for support or when reporting any problems or bugs with SDCC.
16503 Though this will make your message lengthy, it will greatly improve your
16504 chance that SDCC users and developers will be able to help you.
16505 Some SDCC developers are frustrated by bug reports without code provided
16506 that they can use to reproduce and ultimately fix the problem, so please
16507 be sure to provide sample code if you are reporting a bug!
16510 Please have a short check that you are using a recent version of SDCC and
16511 the bug is not yet known.
16512 This is the link for reporting bugs:
16513 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
16520 Requesting Features
16521 \begin_inset LatexCommand \label{sub:Requesting-Features}
16526 \begin_inset LatexCommand \index{Feature request}
16531 \begin_inset LatexCommand \index{Requesting features}
16538 Like bug reports feature requests are forwarded to the developer mailing
16540 This is the link for requesting features:
16541 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
16551 These links should take you directly to the
16552 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
16562 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
16563 automated messages (mid 2003)
16567 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
16571 , lists and forums are archived and searchable so if you are lucky someone
16572 already had a similar problem.
16578 You can follow the status of the cvs version
16579 \begin_inset LatexCommand \index{version}
16583 of SDCC by watching the Changelog
16584 \begin_inset LatexCommand \index{Changelog}
16588 in the cvs-repository
16593 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
16601 \begin_inset LatexCommand \index{Release policy}
16608 Historically there often were long delays between official releases and
16609 the sourceforge download area tends to get not updated at all.
16610 Current excuses might refer to problems with live range analysis, but if
16611 this is fixed, the next problem rising is that another excuse will have
16613 Kidding aside, we have to get better there! On the other hand there are
16614 daily snapshots available at
16615 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
16619 , and you can always built the very last version (hopefully with many bugs
16620 fixed, and features added) from the source code available at
16621 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
16629 \begin_inset LatexCommand \index{Examples}
16636 You'll find some small examples in the directory
16638 sdcc/device/examples/.
16641 More examples and libraries are available at
16643 The SDCC Open Knowledge Resource
16644 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
16651 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
16658 I did insert a reference to Paul's web site here although it seems rather
16659 dedicated to a specific 8032 board (I think it's okay because it f.e.
16660 shows LCD/Harddisc interface and has a free 8051 monitor.
16661 Independent 8032 board vendors face hard competition of heavily subsidized
16662 development boards anyway).
16665 Maybe we should include some links to real world applications.
16666 Preferably pointer to pointers (one for each architecture) so this stays
16671 \begin_inset LatexCommand \index{Quality control}
16678 The compiler is passed through nightly compile and build checks.
16684 \begin_inset LatexCommand \index{Regression test}
16688 check that SDCC itself compiles flawlessly on several platforms and checks
16689 the quality of the code generated by SDCC by running the code through simulator
16691 There is a separate document
16694 \begin_inset LatexCommand \index{Test suite}
16703 You'll find the test code in the directory
16705 sdcc/support/regression
16708 You can run these tests manually by running
16712 in this directory (or f.e.
16717 if you don't want to run the complete tests).
16718 The test code might also be interesting if you want to look for examples
16719 \begin_inset LatexCommand \index{Examples}
16723 checking corner cases of SDCC or if you plan to submit patches
16724 \begin_inset LatexCommand \index{Patch submission}
16731 The pic port uses a different set of regression tests, you'll find them
16734 sdcc/src/regression
16739 SDCC Technical Data
16743 \begin_inset LatexCommand \index{Optimizations}
16750 SDCC performs a host of standard optimizations in addition to some MCU specific
16755 Sub-expression Elimination
16756 \begin_inset LatexCommand \index{Subexpression elimination}
16763 The compiler does local and
16789 will be translated to
16801 Some subexpressions are not as obvious as the above example, e.g.:
16811 In this case the address arithmetic a->b[i] will be computed only once;
16812 the equivalent code in C would be.
16824 The compiler will try to keep these temporary variables in registers.
16827 Dead-Code Elimination
16828 \begin_inset LatexCommand \index{Dead-code elimination}
16849 i = 1; \SpecialChar ~
16858 global = 1;\SpecialChar ~
16871 global = 3;\SpecialChar ~
16900 \begin_inset LatexCommand \index{Copy propagation}
16956 Note: the dead stores created by this copy propagation will be eliminated
16957 by dead-code elimination.
16961 \begin_inset LatexCommand \index{Loop optimization}
16968 Two types of loop optimizations are done by SDCC loop invariant lifting
16969 and strength reduction of loop induction variables.
16970 In addition to the strength reduction the optimizer marks the induction
16971 variables and the register allocator tries to keep the induction variables
16972 in registers for the duration of the loop.
16973 Because of this preference of the register allocator
16974 \begin_inset LatexCommand \index{Register allocation}
16978 , loop induction optimization causes an increase in register pressure, which
16979 may cause unwanted spilling of other temporary variables into the stack
16980 \begin_inset LatexCommand \index{stack}
16985 The compiler will generate a warning message when it is forced to allocate
16986 extra space either on the stack or data space.
16987 If this extra space allocation is undesirable then induction optimization
16988 can be eliminated either for the entire source file (with -
16998 -noinduction option) or for a given function only using #pragma\SpecialChar ~
17000 \begin_inset LatexCommand \index{\#pragma noinduction}
17013 for (i = 0 ; i < 100 ; i ++)
17029 for (i = 0; i < 100; i++)
17038 As mentioned previously some loop invariants are not as apparent, all static
17039 address computations are also moved out of the loop.
17044 \begin_inset LatexCommand \index{Strength reduction}
17048 , this optimization substitutes an expression by a cheaper expression:
17053 for (i=0;i < 100; i++)
17071 for (i=0;i< 100;i++) {
17077 ar[itemp1] = itemp2;
17094 The more expensive multiplication
17095 \begin_inset LatexCommand \index{Multiplication}
17099 is changed to a less expensive addition.
17103 \begin_inset LatexCommand \index{Loop reversing}
17110 This optimization is done to reduce the overhead of checking loop boundaries
17111 for every iteration.
17112 Some simple loops can be reversed and implemented using a
17113 \begin_inset Quotes eld
17116 decrement and jump if not zero
17117 \begin_inset Quotes erd
17121 SDCC checks for the following criterion to determine if a loop is reversible
17122 (note: more sophisticated compilers use data-dependency analysis to make
17123 this determination, SDCC uses a more simple minded analysis).
17126 The 'for' loop is of the form
17132 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
17142 The <for body> does not contain
17143 \begin_inset Quotes eld
17147 \begin_inset Quotes erd
17151 \begin_inset Quotes erd
17157 All goto's are contained within the loop.
17160 No function calls within the loop.
17163 The loop control variable <sym> is not assigned any value within the loop
17166 The loop control variable does NOT participate in any arithmetic operation
17170 There are NO switch statements in the loop.
17173 Algebraic Simplifications
17176 SDCC does numerous algebraic simplifications, the following is a small sub-set
17177 of these optimizations.
17182 i = j + 0;\SpecialChar ~
17186 /* changed to: */\SpecialChar ~
17192 i /= 2;\SpecialChar ~
17199 /* changed to: */\SpecialChar ~
17205 i = j - j;\SpecialChar ~
17209 /* changed to: */\SpecialChar ~
17215 i = j / 1;\SpecialChar ~
17219 /* changed to: */\SpecialChar ~
17226 Note the subexpressions
17227 \begin_inset LatexCommand \index{Subexpression}
17231 given above are generally introduced by macro expansions or as a result
17232 of copy/constant propagation.
17235 'switch' Statements
17236 \begin_inset LatexCommand \label{sub:'switch'-Statements}
17241 \begin_inset LatexCommand \index{switch statement}
17248 SDCC changes switch statements to jump tables
17249 \begin_inset LatexCommand \index{jump tables}
17253 when the following conditions are true.
17257 The case labels are in numerical sequence, the labels need not be in order,
17258 and the starting number need not be one or zero.
17264 switch(i) {\SpecialChar ~
17295 case 4: ...\SpecialChar ~
17327 case 5: ...\SpecialChar ~
17359 case 3: ...\SpecialChar ~
17391 case 6: ...\SpecialChar ~
17459 Both the above switch statements will be implemented using a jump-table.
17460 The example to the right side is slightly more efficient as the check for
17461 the lower boundary of the jump-table is not needed.
17465 The number of case labels is at least three, since it takes two conditional
17466 statements to handle the boundary conditions.
17469 The number of case labels is less than 84, since each label takes 3 bytes
17470 and a jump-table can be utmost 256 bytes long.
17473 Switch statements which have gaps in the numeric sequence or those that
17474 have more that 84 case labels can be split into more than one switch statement
17475 for efficient code generation, e.g.:
17525 If the above switch statement is broken down into two switch statements
17564 case 9:\SpecialChar ~
17571 case 10:\SpecialChar ~
17577 case 11:\SpecialChar ~
17583 case 12:\SpecialChar ~
17590 then both the switch statements will be implemented using jump-tables whereas
17591 the unmodified switch statement will not be.
17592 You might also consider inserting dummy cases 0 and 5 to 8 in this example.
17595 The pragma nojtbound
17596 \begin_inset LatexCommand \index{\#pragma nojtbound}
17600 can be used to turn off checking the
17613 It has no effect if a default label is supplied.
17614 Use of this pragma is dangerous: if the switch argument is not matched
17615 by a case statement the processor will happily jump into Nirvana.
17618 Bit-shifting Operations
17619 \begin_inset LatexCommand \index{Bit shifting}
17626 Bit shifting is one of the most frequently used operation in embedded programmin
17628 SDCC tries to implement bit-shift operations in the most efficient way
17644 generates the following code:
17661 In general SDCC will never setup a loop if the shift count is known.
17704 \begin_inset LatexCommand \index{Bit rotation}
17711 A special case of the bit-shift operation is bit rotation
17712 \begin_inset LatexCommand \index{rotating bits}
17716 , SDCC recognizes the following expression to be a left bit-rotation:
17726 char i;\SpecialChar ~
17737 /* unsigned is needed for rotation */
17742 i = ((i << 1) | (i >> 7));
17751 will generate the following code:
17770 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
17771 ns of this case will also be recognized as bit-rotation, i.e.:
17776 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
17779 Nibble and Byte Swapping
17782 Other special cases of the bit-shift operations are nibble or byte swapping
17783 \begin_inset LatexCommand \index{swapping nibbles/bytes}
17787 , SDCC recognizes the following expressions:
17810 i = ((i << 4) | (i >> 4));
17816 j = ((j << 8) | (j >> 8));
17819 and generates a swap instruction for the nibble swapping
17820 \begin_inset LatexCommand \index{Nibble swapping}
17824 or move instructions for the byte swapping
17825 \begin_inset LatexCommand \index{Byte swapping}
17831 \begin_inset Quotes sld
17835 \begin_inset Quotes srd
17838 example can be used to convert from little to big-endian or vice versa.
17839 If you want to change the endianness of a
17843 integer you have to cast to
17850 Note that SDCC stores numbers in little-endian
17856 Usually 8-bit processors don't care much about endianness.
17857 This is not the case for the standard 8051 which only has an instruction
17863 \begin_inset LatexCommand \index{DPTR}
17871 so little-endian is the more efficient byte order.
17875 \begin_inset LatexCommand \index{little-endian}
17880 \begin_inset LatexCommand \index{Endianness}
17885 lowest order first).
17889 \begin_inset LatexCommand \index{Highest Order Bit}
17896 It is frequently required to obtain the highest order bit of an integral
17897 type (long, int, short or char types).
17898 SDCC recognizes the following expression to yield the highest order bit
17899 and generates optimized code for it, e.g.:
17921 hob = (gint >> 15) & 1;
17931 will generate the following code:
17964 000A E5*01\SpecialChar ~
17991 000C 23\SpecialChar ~
18022 000D 54 01\SpecialChar ~
18049 000F F5*02\SpecialChar ~
18077 Variations of this case however will
18082 It is a standard C expression, so I heartily recommend this be the only
18083 way to get the highest order bit, (it is portable).
18084 Of course it will be recognized even if it is embedded in other expressions,
18090 xyz = gint + ((gint >> 15) & 1);
18093 will still be recognized.
18097 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
18102 \begin_inset LatexCommand \index{Peephole optimizer}
18109 The compiler uses a rule based, pattern matching and re-writing mechanism
18110 for peep-hole optimization.
18115 a peep-hole optimizer by Christopher W.
18116 Fraser (cwfraser@microsoft.com).
18117 A default set of rules are compiled into the compiler, additional rules
18118 may be added with the
18131 \begin_inset LatexCommand \index{-\/-peep-file}
18138 The rule language is best illustrated with examples.
18162 The above rule will change the following assembly
18163 \begin_inset LatexCommand \index{Assembler routines}
18185 Note: All occurrences of a
18189 (pattern variable) must denote the same string.
18190 With the above rule, the assembly sequence:
18200 will remain unmodified.
18204 Other special case optimizations may be added by the user (via
18220 some variants of the 8051 MCU allow only
18229 The following two rules will change all
18248 replace { lcall %1 } by { acall %1 }
18250 replace { ljmp %1 } by { ajmp %1 }
18255 inline-assembler code
18257 is also passed through the peep hole optimizer, thus the peephole optimizer
18258 can also be used as an assembly level macro expander.
18259 The rules themselves are MCU dependent whereas the rule language infra-structur
18260 e is MCU independent.
18261 Peephole optimization rules for other MCU can be easily programmed using
18266 The syntax for a rule is as follows:
18271 rule := replace [ restart ] '{' <assembly sequence> '
18309 <assembly sequence> '
18327 '}' [if <functionName> ] '
18332 <assembly sequence> := assembly instruction (each instruction including
18333 labels must be on a separate line).
18337 The optimizer will apply to the rules one by one from the top in the sequence
18338 of their appearance, it will terminate when all rules are exhausted.
18339 If the 'restart' option is specified, then the optimizer will start matching
18340 the rules again from the top, this option for a rule is expensive (performance)
18341 , it is intended to be used in situations where a transformation will trigger
18342 the same rule again.
18343 An example of this (not a good one, it has side effects) is the following
18366 Note that the replace pattern cannot be a blank, but can be a comment line.
18367 Without the 'restart' option only the innermost 'pop' 'push' pair would
18368 be eliminated, i.e.:
18398 the restart option the rule will be applied again to the resulting code
18399 and then all the pop-push pairs will be eliminated to yield:
18409 A conditional function can be attached to a rule.
18410 Attaching rules are somewhat more involved, let me illustrate this with
18437 The optimizer does a look-up of a function name table defined in function
18442 in the source file SDCCpeeph.c, with the name
18447 If it finds a corresponding entry the function is called.
18448 Note there can be no parameters specified for these functions, in this
18453 is crucial, since the function
18457 expects to find the label in that particular variable (the hash table containin
18458 g the variable bindings is passed as a parameter).
18459 If you want to code more such functions, take a close look at the function
18460 labelInRange and the calling mechanism in source file SDCCpeeph.c.
18461 Currently implemented are
18463 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
18464 24bitMode, portIsDS390, 24bitModeAndPortDS390
18473 I know this whole thing is a little kludgey, but maybe some day we will
18474 have some better means.
18475 If you are looking at this file, you will see the default rules that are
18476 compiled into the compiler, you can add your own rules in the default set
18477 there if you get tired of specifying the -
18491 \begin_inset LatexCommand \index{ANSI-compliance}
18496 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
18503 Deviations from the compliance:
18506 functions are not always reentrant
18507 \begin_inset LatexCommand \index{reentrant}
18514 structures cannot be assigned values directly, cannot be passed as function
18515 parameters or assigned to each other and cannot be a return value from
18542 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
18553 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
18575 return rets;/* is invalid in SDCC although allowed in ANSI */
18582 \begin_inset LatexCommand \index{long long (not supported)}
18587 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
18595 \begin_inset LatexCommand \index{double (not supported)}
18599 ' precision floating point
18600 \begin_inset LatexCommand \index{Floating point support}
18607 No support for setjmp
18608 \begin_inset LatexCommand \index{setjmp (not supported)}
18613 \begin_inset LatexCommand \index{longjmp (not supported)}
18621 \begin_inset LatexCommand \index{K\&R style}
18625 function declarations are NOT allowed.
18631 foo(i,j) /* this old style of function declarations */
18633 int i,j; /* are valid in ANSI but not valid in SDCC */
18648 functions declared as pointers
18649 \begin_inset LatexCommand \index{Pointer (to function)}
18654 \begin_inset LatexCommand \index{function pointers}
18658 must be dereferenced during the call.
18669 /* has to be called like this */
18671 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
18675 Cyclomatic Complexity
18676 \begin_inset LatexCommand \index{Cyclomatic complexity}
18683 Cyclomatic complexity of a function is defined as the number of independent
18684 paths the program can take during execution of the function.
18685 This is an important number since it defines the number test cases you
18686 have to generate to validate the function.
18687 The accepted industry standard for complexity number is 10, if the cyclomatic
18688 complexity reported by SDCC exceeds 10 you should think about simplification
18689 of the function logic.
18690 Note that the complexity level is not related to the number of lines of
18691 code in a function.
18692 Large functions can have low complexity, and small functions can have large
18698 SDCC uses the following formula to compute the complexity:
18703 complexity = (number of edges in control flow graph) - (number of nodes
18704 in control flow graph) + 2;
18708 Having said that the industry standard is 10, you should be aware that in
18709 some cases it be may unavoidable to have a complexity level of less than
18711 For example if you have switch statement with more than 10 case labels,
18712 each case label adds one to the complexity level.
18713 The complexity level is by no means an absolute measure of the algorithmic
18714 complexity of the function, it does however provide a good starting point
18715 for which functions you might look at for further optimization.
18718 Notes on supported Processors
18722 \begin_inset LatexCommand \label{sub:MCS51-variants}
18727 \begin_inset LatexCommand \index{MCS51 variants}
18734 MCS51 processors are available from many vendors and come in many different
18736 While they might differ considerably in respect to Special Function Registers
18737 the core MCS51 is usually not modified or is kept compatible.
18739 \layout Subsubsection*
18741 pdata access by SFR
18744 With the upcome of devices with internal xdata and flash memory devices
18746 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18750 as dedicated I/O port is becoming more popular.
18751 Switching the high byte for pdata
18752 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18756 access which was formerly done by port P2 is then achieved by a Special
18758 \begin_inset LatexCommand \index{sfr}
18763 In well-established MCS51 tradition the address of this
18767 is where the chip designers decided to put it.
18768 Needless to say that they didn't agree on a common name either.
18769 As pdata addressing is used in the startup code for the initialization
18770 of xdata variables a separate startup code should be used as described
18772 \begin_inset LatexCommand \ref{sub:Startup-Code}
18777 \layout Subsubsection*
18779 Other Features available by SFR
18782 Some MCS51 variants offer features like Double DPTR
18783 \begin_inset LatexCommand \index{DPTR}
18787 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
18788 These are currently not used for the MCS51 port.
18789 If you absolutely need them you can fall back to inline assembly or submit
18793 The Z80 and gbz80 port
18796 SDCC can target both the Zilog
18797 \begin_inset LatexCommand \index{Z80}
18801 and the Nintendo Gameboy's Z80-like gbz80
18802 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
18807 The Z80 port is passed through the same
18810 \begin_inset LatexCommand \index{Regression test}
18816 as the MCS51 and DS390 ports, so floating point support, support for long
18817 variables and bitfield support is fine.
18818 See mailing lists and forums about interrupt routines.
18821 As always, the code is the authoritative reference - see z80/ralloc.c and
18824 \begin_inset LatexCommand \index{stack}
18828 frame is similar to that generated by the IAR Z80 compiler.
18829 IX is used as the base pointer, HL is used as a temporary register, and
18830 BC and DE are available for holding variables.
18831 IY is currently unused.
18833 \begin_inset LatexCommand \index{return value}
18838 One bad side effect of using IX as the base pointer is that a functions
18839 stack frame is limited to 127 bytes - this will be fixed in a later version.
18845 The port to the Motorola HC08
18846 \begin_inset LatexCommand \index{HC08}
18850 family has been added in October 2003, thank you Erik!
18856 The 14bit PIC port still requires a major effort from the development community.
18857 However it can work for very simple code.
18863 C code and 14bit PIC code page and RAM banks
18867 The linker organizes allocation for the code page and RAM banks.
18868 It does not have intimate knowledge of the code flow.
18869 It will put all the code section of a single asm file into a single code
18871 In order to make use of multiple code pages, separate asm files must be
18873 The compiler treats all functions of a single C file as being in the same
18874 code page unless it is non static.
18875 The compiler treats all local variables of a single C file as being in
18876 the same RAM bank unless it is an extern.
18880 To get the best follow these guide lines:
18883 make local functions static, as non static functions require code page selection
18887 Make local variables static as extern variables require RAM bank selection
18891 For devices that have multiple code pages it is more efficient to use the
18892 same number of files as pages, i.e.
18893 for the 16F877 use 4 separate files and i.e.
18894 for the 16F874 use 2 separate files.
18895 This way the linker can put the code for each file into different code
18896 pages and the compiler can allocate reusable variables more efficiently
18897 and there's less page selection overhead.
18898 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
18899 instruction set) use 'unsigned char' whereever possible instead of 'int'.
18904 Creating a device include file
18908 For generating a device include file use the support pearl script inc2h.pl
18909 kept in directory support/script.
18919 For the interrupt function, use the keyword 'interrupt' with level number
18920 of 0 (PIC14 only has 1 interrupt so this number is only there to avoid
18921 a syntax error - it ought to be fixed).
18927 void Intr(void) interrupt 0
18933 T0IF = 0; /* Clear timer interrupt */
18940 Linking and assembling
18944 For assembling you can use either GPUTILS' gpasm.exe or MPLAB's mpasmwin.exe.
18945 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
18946 If you use MPLAB and an interrupt function then the linker script file
18947 vectors section will need to be enlarged to link with mplink.
18951 Here is a makefile using GPUTILS:
18966 sdcc -S -V -mpic14 -p16F877 $<
18980 $(PRJ).hex: $(OBJS)
18990 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
18993 Here is a makefile using MPLAB:
19008 sdcc -S -V -mpic14 -p16F877 $<
19018 mpasmwin /q /o $*.asm
19022 $(PRJ).hex: $(OBJS)
19032 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
19038 You'll find some additional notes about this port in the file src/pic16/NOTES.
19041 Retargetting for other Processors
19044 The issues for retargetting the compiler are far too numerous to be covered
19046 What follows is a brief description of each of the seven phases of the
19047 compiler and its MCU dependency.
19050 Parsing the source and building the annotated parse tree.
19051 This phase is largely MCU independent (except for the language extensions).
19052 Syntax & semantic checks are also done in this phase, along with some initial
19053 optimizations like back patching labels and the pattern matching optimizations
19054 like bit-rotation etc.
19057 The second phase involves generating an intermediate code which can be easy
19058 manipulated during the later phases.
19059 This phase is entirely MCU independent.
19060 The intermediate code generation assumes the target machine has unlimited
19061 number of registers, and designates them with the name iTemp.
19062 The compiler can be made to dump a human readable form of the code generated
19076 This phase does the bulk of the standard optimizations and is also MCU independe
19078 This phase can be broken down into several sub-phases:
19082 Break down intermediate code (iCode) into basic blocks.
19084 Do control flow & data flow analysis on the basic blocks.
19086 Do local common subexpression elimination, then global subexpression elimination
19088 Dead code elimination
19092 If loop optimizations caused any changes then do 'global subexpression eliminati
19093 on' and 'dead code elimination' again.
19096 This phase determines the live-ranges; by live range I mean those iTemp
19097 variables defined by the compiler that still survive after all the optimization
19099 Live range analysis
19100 \begin_inset LatexCommand \index{Live range analysis}
19104 is essential for register allocation, since these computation determines
19105 which of these iTemps will be assigned to registers, and for how long.
19108 Phase five is register allocation.
19109 There are two parts to this process.
19113 The first part I call 'register packing' (for lack of a better term).
19114 In this case several MCU specific expression folding is done to reduce
19119 The second part is more MCU independent and deals with allocating registers
19120 to the remaining live ranges.
19121 A lot of MCU specific code does creep into this phase because of the limited
19122 number of index registers available in the 8051.
19125 The Code generation phase is (unhappily), entirely MCU dependent and very
19126 little (if any at all) of this code can be reused for other MCU.
19127 However the scheme for allocating a homogenized assembler operand for each
19128 iCode operand may be reused.
19131 As mentioned in the optimization section the peep-hole optimizer is rule
19132 based system, which can reprogrammed for other MCUs.
19136 \begin_inset LatexCommand \index{Compiler internals}
19143 The anatomy of the compiler
19144 \begin_inset LatexCommand \label{sub:The-anatomy-of}
19153 This is an excerpt from an article published in Circuit Cellar Magazine
19155 It's a little outdated (the compiler is much more efficient now and user/develo
19156 per friendly), but pretty well exposes the guts of it all.
19162 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
19163 It is fairly easy to retarget for other 8-bit MCU.
19164 Here we take a look at some of the internals of the compiler.
19169 \begin_inset LatexCommand \index{Parsing}
19176 Parsing the input source file and creating an AST (Annotated Syntax Tree
19177 \begin_inset LatexCommand \index{Annotated syntax tree}
19182 This phase also involves propagating types (annotating each node of the
19183 parse tree with type information) and semantic analysis.
19184 There are some MCU specific parsing rules.
19185 For example the storage classes, the extended storage classes are MCU specific
19186 while there may be a xdata storage class for 8051 there is no such storage
19187 class for z80 or Atmel AVR.
19188 SDCC allows MCU specific storage class extensions, i.e.
19189 xdata will be treated as a storage class specifier when parsing 8051 C
19190 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
19195 \begin_inset LatexCommand \index{iCode}
19202 Intermediate code generation.
19203 In this phase the AST is broken down into three-operand form (iCode).
19204 These three operand forms are represented as doubly linked lists.
19205 ICode is the term given to the intermediate form generated by the compiler.
19206 ICode example section shows some examples of iCode generated for some simple
19207 C source functions.
19211 \begin_inset LatexCommand \index{Optimizations}
19218 Bulk of the target independent optimizations is performed in this phase.
19219 The optimizations include constant propagation, common sub-expression eliminati
19220 on, loop invariant code movement, strength reduction of loop induction variables
19221 and dead-code elimination.
19224 Live range analysis
19225 \begin_inset LatexCommand \index{Live range analysis}
19232 During intermediate code generation phase, the compiler assumes the target
19233 machine has infinite number of registers and generates a lot of temporary
19235 The live range computation determines the lifetime of each of these compiler-ge
19236 nerated temporaries.
19237 A picture speaks a thousand words.
19238 ICode example sections show the live range annotations for each of the
19240 It is important to note here, each iCode is assigned a number in the order
19241 of its execution in the function.
19242 The live ranges are computed in terms of these numbers.
19243 The from number is the number of the iCode which first defines the operand
19244 and the to number signifies the iCode which uses this operand last.
19247 Register Allocation
19248 \begin_inset LatexCommand \index{Register allocation}
19255 The register allocation determines the type and number of registers needed
19257 In most MCUs only a few registers can be used for indirect addressing.
19258 In case of 8051 for example the registers R0 & R1 can be used to indirectly
19259 address the internal ram and DPTR to indirectly address the external ram.
19260 The compiler will try to allocate the appropriate register to pointer variables
19262 ICode example section shows the operands annotated with the registers assigned
19264 The compiler will try to keep operands in registers as much as possible;
19265 there are several schemes the compiler uses to do achieve this.
19266 When the compiler runs out of registers the compiler will check to see
19267 if there are any live operands which is not used or defined in the current
19268 basic block being processed, if there are any found then it will push that
19269 operand and use the registers in this block, the operand will then be popped
19270 at the end of the basic block.
19274 There are other MCU specific considerations in this phase.
19275 Some MCUs have an accumulator; very short-lived operands could be assigned
19276 to the accumulator instead of a general-purpose register.
19282 Figure II gives a table of iCode operations supported by the compiler.
19283 The code generation involves translating these operations into corresponding
19284 assembly code for the processor.
19285 This sounds overly simple but that is the essence of code generation.
19286 Some of the iCode operations are generated on a MCU specific manner for
19287 example, the z80 port does not use registers to pass parameters so the
19288 SEND and RECV iCode operations will not be generated, and it also does
19289 not support JUMPTABLES.
19296 <Where is Figure II ?>
19300 \begin_inset LatexCommand \index{iCode}
19307 This section shows some details of iCode.
19308 The example C code does not do anything useful; it is used as an example
19309 to illustrate the intermediate code generated by the compiler.
19321 /* This function does nothing useful.
19328 for the purpose of explaining iCode */
19331 short function (data int *x)
19339 short i=10; \SpecialChar ~
19341 /* dead initialization eliminated */
19346 short sum=10; /* dead initialization eliminated */
19359 while (*x) *x++ = *p++;
19373 /* compiler detects i,j to be induction variables */
19377 for (i = 0, j = 10 ; i < 10 ; i++, j
19403 mul += i * 3; \SpecialChar ~
19405 /* this multiplication remains */
19411 gint += j * 3;\SpecialChar ~
19413 /* this multiplication changed to addition */
19427 In addition to the operands each iCode contains information about the filename
19428 and line it corresponds to in the source file.
19429 The first field in the listing should be interpreted as follows:
19434 Filename(linenumber: iCode Execution sequence number : ICode hash table
19435 key : loop depth of the iCode).
19440 Then follows the human readable form of the ICode operation.
19441 Each operand of this triplet form can be of three basic types a) compiler
19442 generated temporary b) user defined variable c) a constant value.
19443 Note that local variables and parameters are replaced by compiler generated
19446 \begin_inset LatexCommand \index{Live range analysis}
19450 are computed only for temporaries (i.e.
19451 live ranges are not computed for global variables).
19453 \begin_inset LatexCommand \index{Register allocation}
19457 are allocated for temporaries only.
19458 Operands are formatted in the following manner:
19463 Operand Name [lr live-from : live-to ] { type information } [ registers
19469 As mentioned earlier the live ranges are computed in terms of the execution
19470 sequence number of the iCodes, for example
19472 the iTemp0 is live from (i.e.
19473 first defined in iCode with execution sequence number 3, and is last used
19474 in the iCode with sequence number 5).
19475 For induction variables such as iTemp21 the live range computation extends
19476 the lifetime from the start to the end of the loop.
19478 The register allocator used the live range information to allocate registers,
19479 the same registers may be used for different temporaries if their live
19480 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
19481 iTemp17 since their live ranges do not overlap.
19482 In addition the allocator also takes into consideration the type and usage
19483 of a temporary, for example itemp6 is a pointer to near space and is used
19484 as to fetch data from (i.e.
19485 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
19486 Some short lived temporaries are allocated to special registers which have
19487 meaning to the code generator e.g.
19488 iTemp13 is allocated to a pseudo register CC which tells the back end that
19489 the temporary is used only for a conditional jump the code generation makes
19490 use of this information to optimize a compare and jump ICode.
19492 There are several loop optimizations
19493 \begin_inset LatexCommand \index{Loop optimization}
19497 performed by the compiler.
19498 It can detect induction variables iTemp21(i) and iTemp23(j).
19499 Also note the compiler does selective strength reduction
19500 \begin_inset LatexCommand \index{Strength reduction}
19505 the multiplication of an induction variable in line 18 (gint = j * 3) is
19506 changed to addition, a new temporary iTemp17 is allocated and assigned
19507 a initial value, a constant 3 is then added for each iteration of the loop.
19508 The compiler does not change the multiplication
19509 \begin_inset LatexCommand \index{Multiplication}
19513 in line 17 however since the processor does support an 8 * 8 bit multiplication.
19515 Note the dead code elimination
19516 \begin_inset LatexCommand \index{Dead-code elimination}
19520 optimization eliminated the dead assignments in line 7 & 8 to I and sum
19528 Sample.c (5:1:0:0) _entry($9) :
19533 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
19538 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
19543 Sample.c(11:4:53:0) preHeaderLbl0($11) :
19548 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
19554 Sample.c(11:6:5:1) _whilecontinue_0($1) :
19559 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
19565 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
19570 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
19576 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
19582 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
19588 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
19594 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
19595 * int}[r0] + 0x2 {short}
19600 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
19605 Sample.c(11:17:21:0)_whilebreak_0($3) :
19610 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
19615 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
19620 Sample.c(15:20:54:0)preHeaderLbl1($13) :
19625 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
19630 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
19635 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
19640 Sample.c(15:24:26:1)_forcond_0($4) :
19645 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
19651 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
19656 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
19657 + ITemp21 [lr21:38]{short}[r4]
19662 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
19668 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
19669 + iTemp15 [lr29:30]{short}[r1]
19674 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
19680 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
19686 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
19692 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
19698 Sample.c(19:38:47:1) goto _forcond_0($4)
19703 Sample.c(19:39:48:0)_forbreak_0($7) :
19708 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
19709 + ITemp11 [lr19:40]{short}[r3]
19714 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
19719 Sample.c(20:42:51:0)_return($8) :
19724 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
19730 Finally the code generated for this function:
19771 ; ----------------------------------------------
19776 ; function function
19781 ; ----------------------------------------------
19791 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
19803 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
19815 ;_whilecontinue_0($1) :
19825 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
19830 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
19889 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
19908 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
19955 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
19995 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
20021 ; iTemp6 [lr5:16]{_near * int}[r0] =
20026 ; iTemp6 [lr5:16]{_near * int}[r0] +
20043 ; goto _whilecontinue_0($1)
20055 ; _whilebreak_0($3) :
20065 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
20077 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
20089 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
20101 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
20120 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
20149 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
20154 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
20199 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
20204 ; iTemp21 [lr21:38]{short}[r4]
20230 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
20263 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
20268 ; iTemp15 [lr29:30]{short}[r1]
20287 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
20334 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
20381 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
20393 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
20407 cjne r5,#0xff,00104$
20419 ; goto _forcond_0($4)
20431 ; _forbreak_0($7) :
20441 ; ret iTemp24 [lr40:41]{short}
20484 A few words about basic block successors, predecessors and dominators
20487 Successors are basic blocks
20488 \begin_inset LatexCommand \index{Basic blocks}
20492 that might execute after this basic block.
20494 Predecessors are basic blocks that might execute before reaching this basic
20497 Dominators are basic blocks that WILL execute before reaching this basic
20531 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
20534 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
20537 c) domVect of [BB4] = BB1 ...
20538 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
20546 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
20556 Thanks to all the other volunteer developers who have helped with coding,
20557 testing, web-page creation, distribution sets, etc.
20558 You know who you are :-)
20565 This document was initially written by Sandeep Dutta
20568 All product names mentioned herein may be trademarks
20569 \begin_inset LatexCommand \index{Trademarks}
20573 of their respective companies.
20580 To avoid confusion, the installation and building options for SDCC itself
20581 (chapter 2) are not part of the index.
20585 \begin_inset LatexCommand \printindex{}