1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
5 \pdfoptionpdfminorversion=3
7 pdftitle={SDCC Compiler User Guide},
8 pdfauthor={SDCC development team},
9 pdfsubject={installation, user manual},
10 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
11 pdfpagemode=UseOutlines,
13 linkcolor=blue] {hyperref}
17 \emergencystretch=30pt
22 \inputencoding default
25 \paperfontsize default
27 \papersize letterpaper
32 \use_numerical_citations 0
33 \paperorientation portrait
40 \paragraph_separation indent
42 \quotes_language swedish
50 Please note: double dashed longoptions (e.g.
51 --version) are written this way: -
65 three consecutive dashes simply result in a long resp.
69 Architecture specific stuff (like memory models, code examples) should maybe
73 into seperate sections/chapters/appendices (it is hard to document PIC or
77 a 8051 centered document) - for now simply add.
80 SDCC Compiler User Guide
94 The above strings enclosed in $ are automatically updated by Subversion
98 \begin_inset LatexCommand \tableofcontents{}
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
136 designed for 8 bit Microprocessors.
137 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144 Zilog Z80 based MCUs.
145 It can be retargeted for other microprocessors, support for Microchip PIC,
146 Atmel AVR is under development.
147 The entire source code for the compiler is distributed under GPL.
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
154 \begin_inset LatexCommand \index{aslink}
158 , an open source retargetable assembler & linker.
159 SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
165 In addition to the MCU specific optimizations SDCC also does a host of standard
169 global sub expression elimination,
172 loop optimizations (loop invariant, strength reduction of induction variables
176 constant folding & propagation,
182 dead code elimination
192 For the back-end SDCC uses a global register allocation scheme which should
193 be well suited for other 8 bit MCUs.
198 The peep hole optimizer uses a rule based substitution mechanism which is
204 Supported data-types are:
209 <lyxtabular version="3" rows="8" columns="5">
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
456 -2.147.483.648, +2.147.483.647
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
518 <row topline="true" bottomline="true">
519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
564 The compiler also allows
566 inline assembler code
568 to be embedded anywhere in a function.
569 In addition, routines developed in assembly can also be called.
573 SDCC also provides an option (-
583 -cyclomatic) to report the relative complexity of a function.
584 These functions can then be further optimized, or hand coded in assembly
590 SDCC also comes with a companion source level debugger SDCDB, the debugger
591 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
595 The latest version can be downloaded from
596 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
606 Please note: the compiler will probably always be some steps ahead of this
611 \begin_inset LatexCommand \index{Status of documentation}
621 Obviously this has pros and cons
630 All packages used in this compiler system are
638 ; source code for all the sub-packages (pre-processor, assemblers, linkers
639 etc) is distributed with the package.
640 This documentation is maintained using a freeware word processor (LyX).
642 This program is free software; you can redistribute it and/or modify it
643 under the terms of the GNU General Public License
644 \begin_inset LatexCommand \index{GNU General Public License, GPL}
648 as published by the Free Software Foundation; either version 2, or (at
649 your option) any later version.
650 This program is distributed in the hope that it will be useful, but WITHOUT
651 ANY WARRANTY; without even the implied warranty
652 \begin_inset LatexCommand \index{warranty}
656 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
657 See the GNU General Public License for more details.
658 You should have received a copy of the GNU General Public License along
659 with this program; if not, write to the Free Software Foundation, 59 Temple
660 Place - Suite 330, Boston, MA 02111-1307, USA.
661 In other words, you are welcome to use, share and improve this program.
662 You are forbidden to forbid anyone else to use, share and improve what
664 Help stamp out software-hoarding!
667 Typographic conventions
668 \begin_inset LatexCommand \index{Typographic conventions}
675 Throughout this manual, we will use the following convention.
676 Commands you have to type in are printed in
684 Code samples are printed in
689 Interesting items and new terms are printed in
695 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
699 with previous versions
700 \begin_inset LatexCommand \index{Compatibility with previous versions}
707 This version has numerous bug fixes compared with the previous version.
708 But we also introduced some incompatibilities with older versions.
709 Not just for the fun of it, but to make the compiler more stable, efficient
711 \begin_inset LatexCommand \index{ANSI-compliance}
716 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
720 for ANSI-Compliance).
726 short is now equivalent to int (16 bits), it used to be equivalent to char
727 (8 bits) which is not ANSI compliant.
730 the default directory for gcc-builds where include, library and documentation
731 files are stored is now in /usr/local/share.
734 char type parameters to vararg
735 \begin_inset LatexCommand \index{vararg, va\_arg}
739 functions are casted to int unless explicitly casted
740 \begin_inset Marginal
767 will push a as an int and as a char resp.
780 -regextend has been removed.
793 -noregparms has been removed.
806 -stack-after-data has been removed.
810 \begin_inset LatexCommand \index{bit}
815 \begin_inset LatexCommand \index{sbit}
820 \begin_inset LatexCommand \index{\_\_sbit}
824 types now consistently behave like the C99 _Bool type with respect to type
826 \begin_inset LatexCommand \index{type conversion}
831 \begin_inset LatexCommand \index{type promotion}
836 The most common incompatibility resulting from this change is related to
838 \begin_inset LatexCommand \index{Bit toggling}
853 \begin_inset LatexCommand \index{\~\/ Operator}
857 b; /* equivalent to b=1 instead of toggling b */
858 \begin_inset Marginal
873 b = !b; /* toggles b */
877 In previous versions, both forms would have toggled the bit.
882 <pending: more incompatibilities?>
888 What do you need before you start installation of SDCC? A computer, and
890 The preferred method of installation is to compile SDCC from source using
892 For Windows some pre-compiled binary distributions are available for your
894 You should have some experience with command line tools and compiler use.
900 The SDCC home page at
901 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
905 is a great place to find distribution sets.
906 You can also find links to the user mailing lists that offer help or discuss
907 SDCC with other SDCC users.
908 Web links to other SDCC related sites can also be found here.
909 This document can be found in the DOC directory of the source package as
911 A pdf version of this document is available at
912 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
917 Some of the other tools (simulator and assembler) included with SDCC contain
918 their own documentation and can be found in the source distribution.
919 If you want the latest unreleased software, the complete source package
920 is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
924 Wishes for the future
927 There are (and always will be) some things that could be done.
928 Here are some I can think of:
935 char KernelFunction3(char p) at 0x340;
943 \begin_inset LatexCommand \index{code banking (limited support)}
953 If you can think of some more, please see the section
954 \begin_inset LatexCommand \ref{sub:Requesting-Features}
958 about filing feature requests
959 \begin_inset LatexCommand \index{Requesting features}
964 \begin_inset LatexCommand \index{Feature request}
974 \begin_inset LatexCommand \index{Installation}
981 For most users it is sufficient to skip to either section
982 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
987 \begin_inset LatexCommand \ref{sub:Windows-Install}
992 More detailed instructions follow below.
996 \begin_inset LatexCommand \index{Options SDCC configuration}
1003 The install paths, search paths and other options are defined when running
1005 The defaults can be overridden by:
1007 \labelwidthstring 00.00.0000
1019 -prefix see table below
1021 \labelwidthstring 00.00.0000
1033 -exec_prefix see table below
1035 \labelwidthstring 00.00.0000
1047 -bindir see table below
1049 \labelwidthstring 00.00.0000
1061 -datadir see table below
1065 \labelwidthstring 00.00.0000
1069 docdir environment variable, see table below
1071 \labelwidthstring 00.00.0000
1075 include_dir_suffix environment variable, see table below
1077 \labelwidthstring 00.00.0000
1081 lib_dir_suffix environment variable, see table below
1083 \labelwidthstring 00.00.0000
1087 sdccconf_h_dir_separator environment variable, either / or
1092 This character will only be used in sdccconf.h; don't forget it's a C-header,
1093 therefore a double-backslash is needed there.
1097 \labelwidthstring 00.00.0000
1109 -disable-mcs51-port Excludes the Intel mcs51 port
1111 \labelwidthstring 00.00.0000
1123 -disable-gbz80-port Excludes the Gameboy gbz80 port
1125 \labelwidthstring 00.00.0000
1137 -disable-z80-port Excludes the z80 port
1139 \labelwidthstring 00.00.0000
1151 -disable-avr-port Excludes the AVR port
1153 \labelwidthstring 00.00.0000
1165 -disable-ds390-port Excludes the DS390 port
1167 \labelwidthstring 00.00.0000
1179 -disable-hc08-port Excludes the HC08 port
1181 \labelwidthstring 00.00.0000
1193 -disable-pic-port Excludes the PIC port
1195 \labelwidthstring 00.00.0000
1207 -disable-xa51-port Excludes the XA51 port
1209 \labelwidthstring 00.00.0000
1221 -disable-ucsim Disables configuring and building of ucsim
1223 \labelwidthstring 00.00.0000
1235 -disable-device-lib Disables automatically building device libraries
1237 \labelwidthstring 00.00.0000
1249 -disable-packihx Disables building packihx
1253 \labelwidthstring 00.00.0000
1265 -enable-doc Build pdf, html and txt files from the lyx sources
1267 \labelwidthstring 00.00.0000
1279 -enable-libgc Use the Bohem memory allocator.
1280 Lower runtime footprint.
1283 Furthermore the environment variables CC, CFLAGS, ...
1284 the tools and their arguments can be influenced.
1285 Please see `configure -
1295 -help` and the man/info pages of `configure` for details.
1299 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1300 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1301 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1302 At the moment it's not possible to change the default settings (it was
1303 simply never required).
1307 These configure options are compiled into the binaries, and can only be
1308 changed by rerunning 'configure' and recompiling SDCC.
1309 The configure options are written in
1313 to distinguish them from run time environment variables (see section search
1319 \begin_inset Quotes sld
1323 \begin_inset Quotes srd
1326 are used by the SDCC team to build the official Win32 binaries.
1327 The SDCC team uses Mingw32 to build the official Windows binaries, because
1334 a gcc compiler and last but not least
1337 the binaries can be built by cross compiling on Sourceforge's compile farm.
1340 See the examples, how to pass the Win32 settings to 'configure'.
1341 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1342 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1353 \begin_inset Tabular
1354 <lyxtabular version="3" rows="8" columns="3">
1356 <column alignment="block" valignment="top" leftline="true" width="0in">
1357 <column alignment="block" valignment="top" leftline="true" width="0in">
1358 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1359 <row topline="true" bottomline="true">
1360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1385 <row topline="true">
1386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1415 <row topline="true">
1416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1447 <row topline="true">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1485 <row topline="true">
1486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1519 <row topline="true">
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1557 <row topline="true">
1558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1585 <row topline="true" bottomline="true">
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1622 'configure' also computes relative paths.
1623 This is needed for full relocatability of a binary package and to complete
1624 search paths (see section search paths below):
1630 \begin_inset Tabular
1631 <lyxtabular version="3" rows="4" columns="3">
1633 <column alignment="block" valignment="top" leftline="true" width="0in">
1634 <column alignment="block" valignment="top" leftline="true" width="0in">
1635 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1636 <row topline="true" bottomline="true">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1662 <row topline="true" bottomline="true">
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1690 <row bottomline="true">
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1718 <row bottomline="true">
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1770 \begin_inset Quotes srd
1774 \begin_inset Quotes srd
1788 \begin_inset Quotes srd
1792 \begin_inset Quotes srd
1820 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1829 \begin_inset Quotes srd
1832 i586-mingw32msvc-gcc
1833 \begin_inset Quotes srd
1837 \begin_inset Quotes srd
1840 i586-mingw32msvc-g++
1841 \begin_inset Quotes srd
1849 \begin_inset Quotes srd
1852 i586-mingw32msvc-ranlib
1853 \begin_inset Quotes srd
1861 \begin_inset Quotes srd
1864 i586-mingw32msvc-strip
1865 \begin_inset Quotes srd
1883 \begin_inset Quotes srd
1887 \begin_inset Quotes srd
1905 \begin_inset Quotes srd
1909 \begin_inset Quotes srd
1917 \begin_inset Quotes srd
1921 \begin_inset Quotes srd
1929 \begin_inset Quotes srd
1933 \begin_inset Quotes srd
1941 \begin_inset Quotes srd
1945 \begin_inset Quotes srd
1952 sdccconf_h_dir_separator=
1953 \begin_inset Quotes srd
1965 \begin_inset Quotes srd
1996 -host=i586-mingw32msvc
2010 -build=unknown-unknown-linux-gnu
2014 \begin_inset Quotes sld
2018 \begin_inset Quotes srd
2021 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2040 \begin_inset Quotes srd
2044 \begin_inset Quotes srd
2062 \begin_inset Quotes srd
2066 \begin_inset Quotes srd
2074 \begin_inset Quotes srd
2078 \begin_inset Quotes srd
2086 \begin_inset Quotes srd
2090 \begin_inset Quotes srd
2098 \begin_inset Quotes srd
2102 \begin_inset Quotes srd
2109 sdccconf_h_dir_separator=
2110 \begin_inset Quotes srd
2122 \begin_inset Quotes srd
2130 \begin_inset Quotes srd
2134 \begin_inset Quotes srd
2142 \begin_inset Quotes srd
2146 \begin_inset Quotes srd
2152 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2163 -C' turns on caching, which gives a little bit extra speed.
2164 However if options are changed, it can be necessary to delete the config.cache
2169 \begin_inset LatexCommand \label{sub:Install-paths}
2174 \begin_inset LatexCommand \index{Install paths}
2180 \added_space_top medskip \align center
2182 \begin_inset Tabular
2183 <lyxtabular version="3" rows="5" columns="4">
2185 <column alignment="left" valignment="top" leftline="true" width="0">
2186 <column alignment="left" valignment="top" leftline="true" width="0">
2187 <column alignment="left" valignment="top" leftline="true" width="0">
2188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2189 <row topline="true" bottomline="true">
2190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2231 <row topline="true">
2232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2271 <row topline="true">
2272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2287 $DATADIR/ $INCLUDE_DIR_SUFFIX
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2295 /usr/local/share/sdcc/include
2298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2311 <row topline="true">
2312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2327 $DATADIR/$LIB_DIR_SUFFIX
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2335 /usr/local/share/sdcc/lib
2338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2351 <row topline="true" bottomline="true">
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2375 /usr/local/share/sdcc/doc
2378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2400 *compiler, preprocessor, assembler, and linker
2406 is auto-appended by the compiler, e.g.
2407 small, large, z80, ds390 etc
2410 The install paths can still be changed during `make install` with e.g.:
2413 make install prefix=$(HOME)/local/sdcc
2416 Of course this doesn't change the search paths compiled into the binaries.
2420 Moreover the install path can be changed by defining DESTDIR
2421 \begin_inset LatexCommand \index{DESTDIR}
2428 make install DESTDIR=$(HOME)/sdcc.rpm/
2431 Please note that DESTDIR must have a trailing slash!
2435 \begin_inset LatexCommand \label{sub:Search-Paths}
2440 \begin_inset LatexCommand \index{Search path}
2447 Some search paths or parts of them are determined by configure variables
2452 , see section above).
2453 Further search paths are determined by environment variables during runtime.
2456 The paths searched when running the compiler are as follows (the first catch
2462 Binary files (preprocessor, assembler and linker)
2468 \begin_inset Tabular
2469 <lyxtabular version="3" rows="4" columns="3">
2471 <column alignment="block" valignment="top" leftline="true" width="0in">
2472 <column alignment="block" valignment="top" leftline="true" width="0in">
2473 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2474 <row topline="true" bottomline="true">
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2500 <row topline="true">
2501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2530 <row topline="true">
2531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2536 Path of argv[0] (if available)
2539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2556 <row topline="true" bottomline="true">
2557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2598 \begin_inset Tabular
2599 <lyxtabular version="3" rows="6" columns="3">
2601 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2602 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2603 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2604 <row topline="true" bottomline="true">
2605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2630 <row topline="true">
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2686 <row topline="true">
2687 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2712 <row topline="true">
2713 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2727 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2750 <row topline="true">
2751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2832 <row topline="true" bottomline="true">
2833 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2849 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2854 /usr/local/share/sdcc/
2859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2887 -nostdinc disables the last two search paths.
2897 With the exception of
2898 \begin_inset Quotes sld
2912 \begin_inset Quotes srd
2919 is auto-appended by the compiler (e.g.
2920 small, large, z80, ds390 etc.).
2927 \begin_inset Tabular
2928 <lyxtabular version="3" rows="6" columns="3">
2930 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2931 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2932 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2933 <row topline="true" bottomline="true">
2934 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2942 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2959 <row topline="true">
2960 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3015 <row topline="true">
3016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3028 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3055 <row topline="true">
3056 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3067 $LIB_DIR_SUFFIX/<model>
3070 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3084 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3101 <row topline="true">
3102 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3117 $LIB_DIR_SUFFIX/<model>
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3229 <row topline="true" bottomline="true">
3230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3239 $LIB_DIR_SUFFIX/<model>
3242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3247 /usr/local/share/sdcc/
3254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3272 Don't delete any of the stray spaces in the table above without checking
3273 the HTML output (last line)!
3289 -nostdlib disables the last two search paths.
3293 \begin_inset LatexCommand \index{Building SDCC}
3300 Building SDCC on Linux
3301 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3310 Download the source package
3312 either from the SDCC Subversion repository or from the nightly snapshots
3314 , it will be named something like sdcc
3325 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3334 Bring up a command line terminal, such as xterm.
3339 Unpack the file using a command like:
3342 "tar -xvzf sdcc.src.tar.gz
3347 , this will create a sub-directory called sdcc with all of the sources.
3350 Change directory into the main SDCC directory, for example type:
3367 This configures the package for compilation on your system.
3383 All of the source packages will compile, this can take a while.
3399 This copies the binary executables, the include files, the libraries and
3400 the documentation to the install directories.
3401 Proceed with section
3402 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3409 Building SDCC on OSX 2.x
3412 Follow the instruction for Linux.
3416 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3417 )) fails to compile SDCC.
3418 Fortunately there's also gcc 2.9.x installed, which works fine.
3419 This compiler can be selected by running 'configure' with:
3422 ./configure CC=gcc2 CXX=g++2
3425 Cross compiling SDCC on Linux for Windows
3428 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3429 See section 'Configure Options'.
3432 Building SDCC using Cygwin and Mingw32
3435 For building and installing a Cygwin executable follow the instructions
3441 \begin_inset Quotes sld
3445 \begin_inset Quotes srd
3448 Win32-binary can be built, which will not need the Cygwin-DLL.
3449 For the necessary 'configure' options see section 'configure options' or
3450 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3454 In order to install Cygwin on Windows download setup.exe from
3455 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3461 \begin_inset Quotes sld
3464 default text file type
3465 \begin_inset Quotes srd
3469 \begin_inset Quotes sld
3473 \begin_inset Quotes srd
3476 and download/install at least the following packages.
3477 Some packages are selected by default, others will be automatically selected
3478 because of dependencies with the manually selected packages.
3479 Never deselect these packages!
3488 gcc ; version 3.x is fine, no need to use the old 2.9x
3491 binutils ; selected with gcc
3497 rxvt ; a nice console, which makes life much easier under windoze (see below)
3500 man ; not really needed for building SDCC, but you'll miss it sooner or
3504 less ; not really needed for building SDCC, but you'll miss it sooner or
3508 svn ; only if you use Subversion access
3511 If you want to develop something you'll need:
3514 python ; for the regression tests
3517 gdb ; the gnu debugger, together with the nice GUI
3518 \begin_inset Quotes sld
3522 \begin_inset Quotes srd
3528 openssh ; to access the CF or commit changes
3531 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3532 use autoconf-stable!
3535 rxvt is a nice console with history.
3536 Replace in your cygwin.bat the line
3555 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3558 -bg black -fg white -geometry 100x65 -e bash -
3571 Text selected with the mouse is automatically copied to the clipboard, pasting
3572 works with shift-insert.
3576 The other good tip is to make sure you have no //c/-style paths anywhere,
3577 use /cygdrive/c/ instead.
3578 Using // invokes a network lookup which is very slow.
3580 \begin_inset Quotes sld
3584 \begin_inset Quotes srd
3587 is too long, you can change it with e.g.
3593 SDCC sources use the unix line ending LF.
3594 Life is much easier, if you store the source tree on a drive which is mounted
3596 And use an editor which can handle LF-only line endings.
3597 Make sure not to commit files with windows line endings.
3598 The tabulator spacing
3599 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3603 used in the project is 8.
3604 Although a tabulator spacing of 8 is a sensible choice for programmers
3605 (it's a power of 2 and allows to display 8/16 bit signed variables without
3606 loosing columns) the plan is to move towards using only spaces in the source.
3609 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3614 Download the source package
3616 either from the SDCC Subversion repository or from the
3617 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3623 , it will be named something like sdcc
3630 SDCC is distributed with all the projects, workspaces, and files you need
3631 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3632 The workspace name is 'sdcc.dsw'.
3633 Please note that as it is now, all the executables are created in a folder
3637 Once built you need to copy the executables from sdcc
3641 bin before running SDCC.
3646 WARNING: Visual studio is very picky with line terminations; it expects
3647 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3648 When using the Subversion repository it's easiest to configure the svn
3649 client to convert automatically for you.
3650 If however you are getting a message such as "This makefile was not generated
3651 by Developer Studio etc.
3653 \begin_inset Quotes srd
3656 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3657 need to convert the Unix style line endings to DOS style line endings.
3658 To do so you can use the
3659 \begin_inset Quotes sld
3663 \begin_inset Quotes srd
3666 utility freely available on the internet.
3667 Doug Hawkins reported in the sdcc-user list that this works:
3675 SDCC> unix2dos sdcc.dsw
3681 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3685 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3686 flex.exe, and gawk.exe.
3687 One good place to get them is
3688 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3696 Download the file UnxUtils
3697 \begin_inset LatexCommand \index{UnxUtils}
3702 Now you have to install the utilities and setup MSVC so it can locate the
3704 Here there are two alternatives (choose one!):
3711 a) Extract UnxUtils.zip to your C:
3713 hard disk PRESERVING the original paths, otherwise bison won't work.
3714 (If you are using WinZip make certain that 'Use folder names' is selected)
3718 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3719 in 'Show directories for:' select 'Executable files', and in the directories
3720 window add a new path: 'C:
3730 (As a side effect, you get a bunch of Unix utilities that could be useful,
3731 such as diff and patch.)
3738 This one avoids extracting a bunch of files you may not use, but requires
3743 a) Create a directory were to put the tools needed, or use a directory already
3751 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3752 to such directory WITHOUT preserving the original paths.
3753 (If you are using WinZip make certain that 'Use folder names' is not selected)
3757 c) Rename bison.exe to '_bison.exe'.
3761 d) Create a batch file 'bison.bat' in 'C:
3765 ' and add these lines:
3785 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3789 Steps 'c' and 'd' are needed because bison requires by default that the
3790 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3791 '/usr/local/share/' I think.
3792 So it is necessary to tell bison where those files are located if they
3793 are not in such directory.
3794 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3798 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3799 in 'Show directories for:' select 'Executable files', and in the directories
3800 window add a new path: 'c:
3803 Note that you can use any other path instead of 'c:
3805 util', even the path where the Visual C++ tools are, probably: 'C:
3809 Microsoft Visual Studio
3814 So you don't have to execute step 'e' :)
3818 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3819 the executables from sdcc
3823 bin, and you can compile using SDCC.
3826 Building SDCC Using Borland
3829 From the sdcc directory, run the command "make -f Makefile.bcc".
3830 This should regenerate all the .exe files in the bin directory except for
3834 If you modify any source files and need to rebuild, be aware that the dependenci
3835 es may not be correctly calculated.
3836 The safest option is to delete all .obj files and run the build again.
3837 From a Cygwin BASH prompt, this can easily be done with the command (be
3838 sure you are in the sdcc directory):
3848 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3850 ) -print -exec rm {}
3859 or on Windows NT/2000/XP from the command prompt with the command:
3866 del /s *.obj *.lib *.rul
3869 from the sdcc directory.
3872 Windows Install Using a ZIP Package
3875 Download the binary zip package from
3876 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3880 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3881 This should unpack to a group of sub-directories.
3882 An example directory structure after unpacking the mingw32 package is:
3887 bin for the executables, c:
3895 lib for the include and libraries.
3898 Adjust your environment variable PATH to include the location of the bin
3899 directory or start sdcc using the full path.
3902 Windows Install Using the Setup Program
3903 \begin_inset LatexCommand \label{sub:Windows-Install}
3910 Download the setup program
3912 sdcc-x.y.z-setup.exe
3914 for an official release from
3917 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3921 or a setup program for one of the snapshots
3923 sdcc-yyyymmdd-xxxx-setup.exe
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3931 A windows typical installer will guide you through the installation process.
3935 \begin_inset LatexCommand \index{VPATH}
3942 SDCC supports the VPATH feature provided by configure and make.
3943 It allows to separate the source and build trees.
3975 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3976 # extract source to directory sdcc
3981 mkdir sdcc.build\SpecialChar ~
3990 # put output in sdcc.build
4000 ../sdcc/configure\SpecialChar ~
4008 # configure is doing all the magic!
4020 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4021 It automagically computes the variables srcdir, top_srcdir and top_buildir
4027 the generated files will be in ~/sdcc.build, while the source files stay
4030 This is not only usefull for building different binaries, e.g.
4031 when cross compiling.
4032 It also gives you a much better overview in the source tree when all the
4033 generated files are not scattered between the source files.
4034 And the best thing is: if you want to change a file you can leave the original
4035 file untouched in the source directory.
4036 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4037 Makefile.dep` and `make`.
4042 will do the rest for you!
4045 Building the Documentation
4058 -enable-doc to the configure arguments to build the documentation together
4059 with all the other stuff.
4060 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4061 dvips and makeindex) to get the job done.
4062 Another possibility is to change to the doc directory and to type
4066 \begin_inset Quotes srd
4070 \begin_inset Quotes srd
4077 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4080 \begin_inset LatexCommand \url{http://www.lyx.org}
4084 as editor is straightforward.
4085 Prebuilt documentation in html and pdf format is available from
4086 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4093 Reading the Documentation
4094 \begin_inset LatexCommand \index{Documentation}
4101 Currently reading the document in pdf format is recommended, as for unknown
4102 reason the hyperlinks are working there whereas in the html version they
4109 If you should know why please drop us a note
4115 You'll find the pdf version
4116 \begin_inset LatexCommand \index{PDF version of this document}
4121 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4129 \begin_inset LatexCommand \index{HTML version of this document}
4134 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4140 This documentation is in some aspects different from a commercial documentation:
4144 It tries to document SDCC for several processor architectures in one document
4145 (commercially these probably would be separate documents/products).
4147 \begin_inset LatexCommand \index{Status of documentation}
4151 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4153 Z80, PIC14, PIC16 and HC08.
4156 There are many references pointing away from this documentation.
4157 Don't let this distract you.
4159 was a reference like
4160 \begin_inset LatexCommand \url{http://www.opencores.org}
4164 together with a statement
4165 \begin_inset Quotes sld
4168 some processors which are targetted by SDCC can be implemented in a
4185 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4190 \begin_inset Quotes srd
4194 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4199 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4204 \begin_inset Quotes sld
4207 have you ever heard of an open source compiler that compiles a subset of
4209 \begin_inset Quotes srd
4212 we expect you to have a quick look there and come back.
4213 If you read this you are on the right track.
4216 Some sections attribute more space to problems, restrictions and warnings
4217 than to the solution.
4220 The installation section and the section about the debugger is intimidating.
4223 There are still lots of typos and there are more different writing styles
4227 Testing the SDCC Compiler
4228 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4235 The first thing you should do after installing your SDCC compiler is to
4251 \begin_inset LatexCommand \index{version}
4258 at the prompt, and the program should run and output its version like:
4263 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4267 If it doesn't run, or gives a message about not finding sdcc program, then
4268 you need to check over your installation.
4269 Make sure that the sdcc bin directory is in your executable search path
4270 defined by the PATH environment setting (
4275 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4282 Install trouble-shooting for suggestions
4285 Make sure that the sdcc program is in the bin folder, if not perhaps something
4286 did not install correctly.
4294 is commonly installed as described in section
4295 \begin_inset Quotes sld
4298 Install and search paths
4299 \begin_inset Quotes srd
4308 Make sure the compiler works on a very simple example.
4309 Type in the following test.c program using your favorite
4335 Compile this using the following command:
4344 If all goes well, the compiler will generate a test.asm and test.rel file.
4345 Congratulations, you've just compiled your first program with SDCC.
4346 We used the -c option to tell SDCC not to link the generated code, just
4347 to keep things simple for this step.
4355 The next step is to try it with the linker.
4365 If all goes well the compiler will link with the libraries and produce
4366 a test.ihx output file.
4371 (no test.ihx, and the linker generates warnings), then the problem is most
4380 usr/local/share/sdcc/lib directory
4387 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4394 Install trouble-shooting for suggestions).
4402 The final test is to ensure
4410 header files and libraries.
4411 Edit test.c and change it to the following:
4428 strcpy(str1, "testing");
4435 Compile this by typing
4442 This should generate a test.ihx output file, and it should give no warnings
4443 such as not finding the string.h file.
4444 If it cannot find the string.h file, then the problem is that
4448 cannot find the /usr/local/share/sdcc/include directory
4455 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4462 Install trouble-shooting section for suggestions).
4480 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4484 to find exactly where SDCC is looking for the include and lib files.
4487 Install Trouble-shooting
4488 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4493 \begin_inset LatexCommand \index{Install trouble-shooting}
4500 If SDCC does not build correctly
4503 A thing to try is starting from scratch by unpacking the .tgz source package
4504 again in an empty directory.
4512 ./configure 2>&1 | tee configure.log
4526 make 2>&1 | tee make.log
4533 If anything goes wrong, you can review the log files to locate the problem.
4534 Or a relevant part of this can be attached to an email that could be helpful
4535 when requesting help from the mailing list.
4539 \begin_inset Quotes sld
4543 \begin_inset Quotes srd
4550 \begin_inset Quotes sld
4554 \begin_inset Quotes srd
4557 command is a script that analyzes your system and performs some configuration
4558 to ensure the source package compiles on your system.
4559 It will take a few minutes to run, and will compile a few tests to determine
4560 what compiler features are installed.
4564 \begin_inset Quotes sld
4568 \begin_inset Quotes srd
4574 This runs the GNU make tool, which automatically compiles all the source
4575 packages into the final installed binary executables.
4579 \begin_inset Quotes sld
4583 \begin_inset Quotes erd
4589 This will install the compiler, other executables libraries and include
4590 files into the appropriate directories.
4592 \begin_inset LatexCommand \ref{sub:Install-paths}
4598 \begin_inset LatexCommand \ref{sub:Search-Paths}
4603 about install and search paths.
4605 On most systems you will need super-user privileges to do this.
4611 SDCC is not just a compiler, but a collection of tools by various developers.
4612 These include linkers, assemblers, simulators and other components.
4613 Here is a summary of some of the components.
4614 Note that the included simulator and assembler have separate documentation
4615 which you can find in the source package in their respective directories.
4616 As SDCC grows to include support for other processors, other packages from
4617 various developers are included and may have their own sets of documentation.
4621 You might want to look at the files which are installed in <installdir>.
4622 At the time of this writing, we find the following programs for gcc-builds:
4626 In <installdir>/bin:
4629 sdcc - The compiler.
4632 sdcpp - The C preprocessor.
4635 asx8051 - The assembler for 8051 type processors.
4642 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4645 aslink -The linker for 8051 type processors.
4652 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4655 s51 - The ucSim 8051 simulator.
4658 sdcdb - The source debugger.
4661 packihx - A tool to pack (compress) Intel hex files.
4664 In <installdir>/share/sdcc/include
4670 In <installdir>/share/sdcc/lib
4673 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4677 In <installdir>/share/sdcc/doc
4683 As development for other processors proceeds, this list will expand to include
4684 executables to support processors like AVR, PIC, etc.
4690 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4691 the assembler and linkage editor.
4694 sdcpp - The C-Preprocessor
4698 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4702 is a modified version of the GNU cpp
4703 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4708 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4713 The C preprocessor is used to pull in #include sources, process #ifdef
4714 statements, #defines and so on.
4725 - The Assemblers and Linkage Editors
4728 This is retargettable assembler & linkage editor, it was developed by Alan
4730 John Hartman created the version for 8051, and I (Sandeep) have made some
4731 enhancements and bug fixes for it to work properly with SDCC.
4738 \begin_inset LatexCommand \index{s51}
4742 is a freeware, opensource simulator developed by Daniel Drotos.
4743 The simulator is built as part of the build process.
4744 For more information visit Daniel's web site at:
4745 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4750 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4754 sdcdb - Source Level Debugger
4758 \begin_inset LatexCommand \index{SDCDB (debugger)}
4762 is the companion source level debugger.
4763 More about SDCDB in section
4764 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4769 The current version of the debugger uses Daniel's Simulator S51
4770 \begin_inset LatexCommand \index{s51}
4774 , but can be easily changed to use other simulators.
4783 Single Source File Projects
4786 For single source file 8051 projects the process is very simple.
4787 Compile your programs with the following command
4790 "sdcc sourcefile.c".
4794 This will compile, assemble and link your source file.
4795 Output files are as follows:
4799 \begin_inset LatexCommand \index{<file>.asm}
4804 \begin_inset LatexCommand \index{Assembler source}
4808 file created by the compiler
4812 \begin_inset LatexCommand \index{<file>.lst}
4817 \begin_inset LatexCommand \index{Assembler listing}
4821 file created by the Assembler
4825 \begin_inset LatexCommand \index{<file>.rst}
4830 \begin_inset LatexCommand \index{Assembler listing}
4834 file updated with linkedit information, created by linkage editor
4838 \begin_inset LatexCommand \index{<file>.sym}
4843 \begin_inset LatexCommand \index{Symbol listing}
4847 for the sourcefile, created by the assembler
4851 \begin_inset LatexCommand \index{<file>.rel}
4856 \begin_inset LatexCommand \index{<file>.o}
4861 \begin_inset LatexCommand \index{Object file}
4865 created by the assembler, input to Linkage editor
4869 \begin_inset LatexCommand \index{<file>.map}
4874 \begin_inset LatexCommand \index{Memory map}
4878 for the load module, created by the Linker
4882 \begin_inset LatexCommand \index{<file>.mem}
4886 - A file with a summary of the memory usage
4890 \begin_inset LatexCommand \index{<file>.ihx}
4894 - The load module in Intel hex format
4895 \begin_inset LatexCommand \index{Intel hex format}
4899 (you can select the Motorola S19 format
4900 \begin_inset LatexCommand \index{Motorola S19 format}
4915 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4920 If you need another format you might want to use
4927 \begin_inset LatexCommand \index{objdump (tool)}
4938 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4943 Both formats are documented in the documentation of srecord
4944 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4952 \begin_inset LatexCommand \index{<file>.adb}
4956 - An intermediate file containing debug information needed to create the
4968 \begin_inset LatexCommand \index{-\/-debug}
4976 \begin_inset LatexCommand \index{<file>.cdb}
4980 - An optional file (with -
4990 -debug) containing debug information.
4991 The format is documented in cdbfileformat.pdf
4996 \begin_inset LatexCommand \index{<file> (no extension)}
5000 An optional AOMF or AOMF51
5001 \begin_inset LatexCommand \index{AOMF, AOMF51}
5006 \begin_inset LatexCommand \label{OMF file}
5010 file containing debug information (generated with option -
5037 ormat is commonly used by third party tools (debuggers
5038 \begin_inset LatexCommand \index{Debugger}
5042 , simulators, emulators)
5046 \begin_inset LatexCommand \index{<file>.dump*}
5050 - Dump file to debug the compiler it self (generated with option -
5060 -dumpall) (see section
5061 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5067 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5073 \begin_inset Quotes sld
5076 Anatomy of the compiler
5077 \begin_inset Quotes srd
5083 Postprocessing the Intel Hex
5084 \begin_inset LatexCommand \index{Intel hex format}
5091 In most cases this won't be needed but the Intel Hex file
5092 \begin_inset LatexCommand \index{<file>.ihx}
5096 which is generated by SDCC might include lines of varying length and the
5097 addresses within the file are not guaranteed to be strictly ascending.
5098 If your toolchain or a bootloader does not like this you can use the tool
5104 \begin_inset LatexCommand \index{packihx (tool)}
5108 which is part of the SDCC distribution:
5115 packihx sourcefile.ihx >sourcefile.hex
5122 The separately available
5127 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5131 package additionally allows to set undefined locations to a predefined
5132 value, to insert checksums
5133 \begin_inset LatexCommand \index{checksum}
5137 of various flavours (crc, add, xor) and to perform other manipulations
5138 (convert, split, crop, offset, ...).
5146 srec_cat\SpecialChar ~
5148 sourcefile.ihx -intel\SpecialChar ~
5150 -o sourcefile.hex -intel
5157 An example for a more complex command line
5163 the command backfills
5164 \begin_inset LatexCommand \index{backfill unused memory}
5168 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5170 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5171 will be interpreted as an
5179 (where an emergency routine could sit).
5190 srec_cat\SpecialChar ~
5191 sourcefile.ihx -intel\SpecialChar ~
5193 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5194 -little-endian-checksum-nega
5195 tive 0xfffe 0x02 0x02\SpecialChar ~
5197 -o sourcefile.hex -intel
5206 The srecord package is available at
5207 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5214 Projects with Multiple Source Files
5217 SDCC can compile only ONE file at a time.
5218 Let us for example assume that you have a project containing the following
5223 foo1.c (contains some functions)
5225 foo2.c (contains some more functions)
5227 foomain.c (contains more functions and the function main)
5235 The first two files will need to be compiled separately with the commands:
5267 Then compile the source file containing the
5272 \begin_inset LatexCommand \index{Linker}
5276 the files together with the following command:
5284 foomain.c\SpecialChar ~
5285 foo1.rel\SpecialChar ~
5290 \begin_inset LatexCommand \index{<file>.rel}
5302 can be separately compiled as well:
5313 sdcc foomain.rel foo1.rel foo2.rel
5320 The file containing the
5335 file specified in the command line, since the linkage editor processes
5336 file in the order they are presented to it.
5337 The linker is invoked from SDCC using a script file with extension .lnk
5338 \begin_inset LatexCommand \index{<file>.lnk}
5343 You can view this file to troubleshoot linking problems such as those arising
5344 from missing libraries.
5347 Projects with Additional Libraries
5348 \begin_inset LatexCommand \index{Libraries}
5355 Some reusable routines may be compiled into a library, see the documentation
5356 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5360 \begin_inset LatexCommand \index{<file>.lib}
5367 Libraries created in this manner can be included in the command line.
5368 Make sure you include the -L <library-path> option to tell the linker where
5369 to look for these files if they are not in the current directory.
5370 Here is an example, assuming you have the source file
5382 (if that is not the same as your current project):
5389 sdcc foomain.c foolib.lib -L mylib
5400 must be an absolute path name.
5404 The most efficient way to use libraries is to keep separate modules in separate
5406 The lib file now should name all the modules.rel
5407 \begin_inset LatexCommand \index{<file>.rel}
5412 For an example see the standard library file
5416 in the directory <installdir>/share/lib/small.
5419 Using sdcclib to Create and Manage Libraries
5420 \begin_inset LatexCommand \index{sdcclib}
5427 Alternatively, instead of having a .rel file for each entry on the library
5428 file as described in the preceding section, sdcclib can be used to embed
5429 all the modules belonging to such library in the library file itself.
5430 This results in a larger library file, but it greatly reduces the number
5431 of disk files accessed by the linker.
5432 Additionally, the packed library file contains an index of all include
5433 modules and symbols that significantly speeds up the linking process.
5434 To display a list of options supported by sdcclib type:
5443 \begin_inset LatexCommand \index{sdcclib}
5454 To create a new library file, start by compiling all the required modules.
5492 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5494 The next step is to add the .rel files to the library file:
5502 sdcclib libint.lib _divsint.rel
5505 \begin_inset LatexCommand \index{sdcclib}
5515 sdcclib libint.lib _divuint.rel
5521 sdcclib libint.lib _modsint.rel
5527 sdcclib libint.lib _moduint.rel
5533 sdcclib libint.lib _mulint.rel
5540 If the file already exists in the library, it will be replaced.
5541 To see what modules and symbols are included in the library, options -s
5542 and -m are available.
5550 sdcclib -s libint.lib
5553 \begin_inset LatexCommand \index{sdcclib}
5662 \added_space_bottom bigskip
5663 If the source files are compiled using -
5674 \begin_inset LatexCommand \index{-\/-debug}
5678 , the corresponding debug information file .adb will be include in the library
5680 The library files created with sdcclib are plain text files, so they can
5681 be viewed with a text editor.
5682 It is not recomended to modify a library file created with sdcclib using
5683 a text editor, as there are file indexes numbers located accross the file
5684 used by the linker to quickly locate the required module to link.
5685 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5686 it can be safely deleted, since all the information required for linking
5687 is embedded in the library file itself.
5688 Library files created using sdcclib are used as described in the preceding
5692 Command Line Options
5693 \begin_inset LatexCommand \index{Command Line Options}
5700 Processor Selection Options
5701 \begin_inset LatexCommand \index{Options processor selection}
5706 \begin_inset LatexCommand \index{Processor selection options}
5712 \labelwidthstring 00.00.0000
5717 \begin_inset LatexCommand \index{-mmcs51}
5723 Generate code for the Intel MCS51
5724 \begin_inset LatexCommand \index{MCS51}
5728 family of processors.
5729 This is the default processor target.
5731 \labelwidthstring 00.00.0000
5736 \begin_inset LatexCommand \index{-mds390}
5742 Generate code for the Dallas DS80C390
5743 \begin_inset LatexCommand \index{DS80C390}
5749 \labelwidthstring 00.00.0000
5754 \begin_inset LatexCommand \index{-mds400}
5760 Generate code for the Dallas DS80C400
5761 \begin_inset LatexCommand \index{DS80C400}
5767 \labelwidthstring 00.00.0000
5772 \begin_inset LatexCommand \index{-mhc08}
5778 Generate code for the Freescale/Motorola HC08
5779 \begin_inset LatexCommand \index{HC08}
5783 family of processors.
5785 \labelwidthstring 00.00.0000
5790 \begin_inset LatexCommand \index{-mz80}
5796 Generate code for the Zilog Z80
5797 \begin_inset LatexCommand \index{Z80}
5801 family of processors.
5803 \labelwidthstring 00.00.0000
5808 \begin_inset LatexCommand \index{-mgbz80}
5814 Generate code for the GameBoy Z80
5815 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5819 processor (Not actively maintained).
5821 \labelwidthstring 00.00.0000
5826 \begin_inset LatexCommand \index{-mavr}
5832 Generate code for the Atmel AVR
5833 \begin_inset LatexCommand \index{AVR}
5837 processor (Not maintained, not complete).
5838 AVR users should probably have a look at winavr
5839 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5844 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5851 I think it is fair to direct users there for now.
5852 Open source is also about avoiding unnecessary work .
5853 But I didn't find the 'official' link.
5855 \labelwidthstring 00.00.0000
5860 \begin_inset LatexCommand \index{-mpic14}
5866 Generate code for the Microchip PIC 14
5867 \begin_inset LatexCommand \index{PIC14}
5871 -bit processors (p16f84 and variants.
5872 In development, not complete).
5875 p16f627 p16f628 p16f84 p16f873 p16f877?
5877 \labelwidthstring 00.00.0000
5882 \begin_inset LatexCommand \index{-mpic16}
5888 Generate code for the Microchip PIC 16
5889 \begin_inset LatexCommand \index{PIC16}
5893 -bit processors (p18f452 and variants.
5894 In development, not complete).
5896 \labelwidthstring 00.00.0000
5902 Generate code for the Toshiba TLCS-900H
5903 \begin_inset LatexCommand \index{TLCS-900H}
5907 processor (Not maintained, not complete).
5909 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5914 \begin_inset LatexCommand \index{-mxa51}
5920 Generate code for the Phillips XA51
5921 \begin_inset LatexCommand \index{XA51}
5925 processor (Not maintained, not complete).
5928 Preprocessor Options
5929 \begin_inset LatexCommand \index{Options preprocessor}
5934 \begin_inset LatexCommand \index{Preprocessor options}
5939 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5945 \labelwidthstring 00.00.0000
5950 \begin_inset LatexCommand \index{-I<path>}
5956 The additional location where the pre processor will look for <..h> or
5957 \begin_inset Quotes eld
5961 \begin_inset Quotes erd
5966 \labelwidthstring 00.00.0000
5971 \begin_inset LatexCommand \index{-D<macro[=value]>}
5977 Command line definition of macros.
5978 Passed to the preprocessor.
5980 \labelwidthstring 00.00.0000
5985 \begin_inset LatexCommand \index{-M}
5991 Tell the preprocessor to output a rule suitable for make describing the
5992 dependencies of each object file.
5993 For each source file, the preprocessor outputs one make-rule whose target
5994 is the object file name for that source file and whose dependencies are
5995 all the files `#include'd in it.
5996 This rule may be a single line or may be continued with `
5998 '-newline if it is long.
5999 The list of rules is printed on standard output instead of the preprocessed
6002 \begin_inset LatexCommand \index{-E}
6008 \labelwidthstring 00.00.0000
6013 \begin_inset LatexCommand \index{-C}
6019 Tell the preprocessor not to discard comments.
6020 Used with the `-E' option.
6022 \labelwidthstring 00.00.0000
6027 \begin_inset LatexCommand \index{-MM}
6038 Like `-M' but the output mentions only the user header files included with
6040 \begin_inset Quotes eld
6044 System header files included with `#include <file>' are omitted.
6046 \labelwidthstring 00.00.0000
6051 \begin_inset LatexCommand \index{-Aquestion(answer)}
6057 Assert the answer answer for question, in case it is tested with a preprocessor
6058 conditional such as `#if #question(answer)'.
6059 `-A-' disables the standard assertions that normally describe the target
6062 \labelwidthstring 00.00.0000
6067 \begin_inset LatexCommand \index{-Umacro}
6073 Undefine macro macro.
6074 `-U' options are evaluated after all `-D' options, but before any `-include'
6075 and `-imacros' options.
6077 \labelwidthstring 00.00.0000
6082 \begin_inset LatexCommand \index{-dM}
6088 Tell the preprocessor to output only a list of the macro definitions that
6089 are in effect at the end of preprocessing.
6090 Used with the `-E' option.
6092 \labelwidthstring 00.00.0000
6097 \begin_inset LatexCommand \index{-dD}
6103 Tell the preprocessor to pass all macro definitions into the output, in
6104 their proper sequence in the rest of the output.
6106 \labelwidthstring 00.00.0000
6111 \begin_inset LatexCommand \index{-dN}
6122 Like `-dD' except that the macro arguments and contents are omitted.
6123 Only `#define name' is included in the output.
6125 \labelwidthstring 00.00.0000
6129 -pedantic-parse-number
6130 \begin_inset LatexCommand \index{-pedantic-parse-number}
6141 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6142 and the macro LO_B(3) gets expanded.
6143 See also #pragma pedantic_parse_number in section
6144 \begin_inset LatexCommand \ref{sec:Pragmas}
6150 Note: this functionality is not in conformance with standard!
6153 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6158 preprocessorOption[,preprocessorOption]
6161 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6166 Pass the preprocessorOption to the preprocessor
6171 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6176 SDCC uses an adapted version of the preprocessor
6180 of the GNU Compiler Collection
6181 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6190 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6194 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6199 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6207 \begin_inset LatexCommand \index{Options linker}
6212 \begin_inset LatexCommand \index{Linker options}
6218 \labelwidthstring 00.00.0000
6238 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6243 \begin_inset LatexCommand \index{-L -\/-lib-path}
6250 <absolute path to additional libraries> This option is passed to the linkage
6251 editor's additional libraries
6252 \begin_inset LatexCommand \index{Libraries}
6257 The path name must be absolute.
6258 Additional library files may be specified in the command line.
6259 See section Compiling programs for more details.
6261 \labelwidthstring 00.00.0000
6278 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6283 <Value> The start location of the external ram
6284 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6288 , default value is 0.
6289 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6299 -xram-loc 0x8000 or -
6311 \labelwidthstring 00.00.0000
6328 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6333 <Value> The start location of the code
6334 \begin_inset LatexCommand \index{code}
6338 segment, default value 0.
6339 Note when this option is used the interrupt vector table
6340 \begin_inset LatexCommand \index{interrupt vector table}
6344 is also relocated to the given address.
6345 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6355 -code-loc 0x8000 or -
6367 \labelwidthstring 00.00.0000
6384 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6389 <Value> By default the stack
6390 \begin_inset LatexCommand \index{stack}
6394 is placed after the data segment.
6395 Using this option the stack can be placed anywhere in the internal memory
6397 The value entered can be in Hexadecimal or Decimal format, e.g.
6408 -stack-loc 0x20 or -
6419 Since the sp register is incremented before a push or call, the initial
6420 sp will be set to one byte prior the provided value.
6421 The provided value should not overlap any other memory areas such as used
6422 register banks or the data segment and with enough space for the current
6440 \begin_inset LatexCommand \index{-\/-pack-iram}
6444 option (which is now a default setting) will override this setting, so
6445 you should also specify the
6461 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6465 option if you need to manually place the stack.
6467 \labelwidthstring 00.00.0000
6484 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6489 <Value> By default the external stack
6490 \begin_inset LatexCommand \index{xstack}
6494 is placed after the pdata
6495 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6500 Using this option the xstack can be placed anywhere in the external memory
6502 The value entered can be in Hexadecimal or Decimal format, e.g.
6513 -xstack-loc 0x8000 or -
6524 The provided value should not overlap any other memory areas such as the
6525 pdata or xdata segment and with enough space for the current application.
6527 \labelwidthstring 00.00.0000
6544 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6549 <Value> The start location of the internal ram data
6550 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6555 The value entered can be in Hexadecimal or Decimal format, eg.
6577 (By default, the start location of the internal ram data segment is set
6578 as low as possible in memory, taking into account the used register banks
6579 and the bit segment at address 0x20.
6580 For example if register banks 0 and 1 are used without bit variables, the
6581 data segment will be set, if -
6591 -data-loc is not used, to location 0x10.)
6593 \labelwidthstring 00.00.0000
6610 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6615 <Value> The start location of the indirectly addressable internal ram
6616 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6620 of the 8051, default value is 0x80.
6621 The value entered can be in Hexadecimal or Decimal format, eg.
6632 -idata-loc 0x88 or -
6644 \labelwidthstring 00.00.0000
6661 <Value> The start location of the bit
6662 \begin_inset LatexCommand \index{bit}
6666 addressable internal ram of the 8051.
6672 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6675 \labelwidthstring 00.00.0000
6690 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6699 The linker output (final object code) is in Intel Hex format.
6700 \begin_inset LatexCommand \index{Intel hex format}
6704 This is the default option.
6705 The format itself is documented in the documentation of srecord
6706 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6712 \labelwidthstring 00.00.0000
6727 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6736 The linker output (final object code) is in Motorola S19 format
6737 \begin_inset LatexCommand \index{Motorola S19 format}
6742 The format itself is documented in the documentation of srecord.
6744 \labelwidthstring 00.00.0000
6759 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6764 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6773 The linker output (final object code) is in ELF format
6774 \begin_inset LatexCommand \index{ELF format}
6779 (Currently only supported for the HC08
6780 \begin_inset LatexCommand \index{HC08}
6786 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6791 linkOption[,linkOption]
6794 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6799 Pass the linkOption to the linker.
6800 If a bootloader is used an option like
6801 \begin_inset Quotes sld
6806 \begin_inset Quotes srd
6809 would be typical to set the start of the code segment.
6810 See also #pragma constseg and #pragma codeseg in section
6811 \begin_inset LatexCommand \ref{sec:Pragmas}
6816 File sdcc/as/doc/asxhtm.html has more on linker options.
6820 \begin_inset LatexCommand \index{Options MCS51}
6825 \begin_inset LatexCommand \index{MCS51 options}
6831 \labelwidthstring 00.00.0000
6846 \begin_inset LatexCommand \index{-\/-model-small}
6857 Generate code for Small Model programs, see section Memory Models for more
6859 This is the default model.
6861 \labelwidthstring 00.00.0000
6876 \begin_inset LatexCommand \index{-\/-model-medium}
6882 Generate code for Medium model programs, see section Memory Models for
6884 If this option is used all source files in the project have to be compiled
6886 It must also be used when invoking the linker.
6888 \labelwidthstring 00.00.0000
6903 \begin_inset LatexCommand \index{-\/-model-large}
6909 Generate code for Large model programs, see section Memory Models for more
6911 If this option is used all source files in the project have to be compiled
6913 It must also be used when invoking the linker.
6915 \labelwidthstring 00.00.0000
6930 \begin_inset LatexCommand \index{-\/-xstack}
6936 Uses a pseudo stack in the pdata
6937 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6941 area (usually the first 256 bytes in the external ram) for allocating variables
6942 and passing parameters.
6944 \begin_inset LatexCommand \ref{sub:External-Stack}
6949 External Stack for more details.
6951 \labelwidthstring 00.00.0000
6969 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6973 Causes the linker to check if the internal ram usage is within limits of
6976 \labelwidthstring 00.00.0000
6994 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6998 Causes the linker to check if the external ram usage is within limits of
7001 \labelwidthstring 00.00.0000
7019 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7023 Causes the linker to check if the code memory usage is within limits of
7026 \labelwidthstring 00.00.0000
7044 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7048 Causes the linker to check if there is at minimum <Value> bytes for stack.
7050 \labelwidthstring 00.00.0000
7068 \begin_inset LatexCommand \index{-\/-pack-iram}
7072 Causes the linker to use unused register banks for data variables and pack
7073 data, idata and stack together.
7074 This is the default now.
7076 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7094 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7098 Causes the linker to use old style for allocating memory areas.
7101 DS390 / DS400 Options
7102 \begin_inset LatexCommand \index{Options DS390}
7107 \begin_inset LatexCommand \index{DS390}
7113 \labelwidthstring 00.00.0000
7130 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7140 Generate 24-bit flat mode code.
7141 This is the one and only that the ds390 code generator supports right now
7142 and is default when using
7147 See section Memory Models for more details.
7149 \labelwidthstring 00.00.0000
7164 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7170 disable interrupts during ESP:SP updates.
7172 \labelwidthstring 00.00.0000
7189 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7193 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7194 This is the one and only that the ds390 code generator supports right now
7195 and is default when using
7200 In this mode, the stack is located in the lower 1K of the internal RAM,
7201 which is mapped to 0x400000.
7202 Note that the support is incomplete, since it still uses a single byte
7203 as the stack pointer.
7204 This means that only the lower 256 bytes of the potential 1K stack space
7205 will actually be used.
7206 However, this does allow you to reclaim the precious 256 bytes of low RAM
7207 for use for the DATA and IDATA segments.
7208 The compiler will not generate any code to put the processor into 10 bit
7210 It is important to ensure that the processor is in this mode before calling
7211 any re-entrant functions compiled with this option.
7212 In principle, this should work with the
7225 \begin_inset LatexCommand \index{-\/-stack-auto}
7231 option, but that has not been tested.
7232 It is incompatible with the
7245 \begin_inset LatexCommand \index{-\/-xstack}
7252 It also only makes sense if the processor is in 24 bit contiguous addressing
7265 -model-flat24 option
7269 \labelwidthstring 00.00.0000
7284 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7290 insert call to function __stack_probe at each function prologue.
7292 \labelwidthstring 00.00.0000
7307 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7313 <nnnn> LibraryID used in -mTININative.
7316 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7331 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7337 generate code for DS390 Arithmetic Accelerator.
7342 \begin_inset LatexCommand \index{Options Z80}
7347 \begin_inset LatexCommand \index{Z80}
7353 \labelwidthstring 00.00.0000
7370 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7380 Force a called function to always save BC.
7382 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7399 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7403 When linking, skip the standard crt0.o object file.
7404 You must provide your own crt0.o for your system when linking.
7408 Optimization Options
7409 \begin_inset LatexCommand \index{Options optimization}
7414 \begin_inset LatexCommand \index{Optimization options}
7420 \labelwidthstring 00.00.0000
7435 \begin_inset LatexCommand \index{-\/-nogcse}
7441 Will not do global subexpression elimination, this option may be used when
7442 the compiler creates undesirably large stack/data spaces to store compiler
7452 \begin_inset LatexCommand \index{sloc (spill location)}
7457 A warning message will be generated when this happens and the compiler
7458 will indicate the number of extra bytes it allocated.
7459 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7461 \begin_inset LatexCommand \index{\#pragma nogcse}
7465 can be used to turn off global subexpression elimination
7466 \begin_inset LatexCommand \index{Subexpression elimination}
7470 for a given function only.
7472 \labelwidthstring 00.00.0000
7487 \begin_inset LatexCommand \index{-\/-noinvariant}
7493 Will not do loop invariant optimizations, this may be turned off for reasons
7494 explained for the previous option.
7495 For more details of loop optimizations performed see Loop Invariants in
7497 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7502 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7504 \begin_inset LatexCommand \index{\#pragma noinvariant}
7508 can be used to turn off invariant optimizations for a given function only.
7510 \labelwidthstring 00.00.0000
7525 \begin_inset LatexCommand \index{-\/-noinduction}
7531 Will not do loop induction optimizations, see section strength reduction
7533 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7535 \begin_inset LatexCommand \index{\#pragma noinduction}
7539 can be used to turn off induction optimizations for a given function only.
7541 \labelwidthstring 00.00.0000
7556 \begin_inset LatexCommand \index{-\/-nojtbound}
7567 Will not generate boundary condition check when switch statements
7568 \begin_inset LatexCommand \index{switch statement}
7572 are implemented using jump-tables.
7574 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7579 Switch Statements for more details.
7580 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7582 \begin_inset LatexCommand \index{\#pragma nojtbound}
7586 can be used to turn off boundary checking for jump tables for a given function
7589 \labelwidthstring 00.00.0000
7604 \begin_inset LatexCommand \index{-\/-noloopreverse}
7613 Will not do loop reversal
7614 \begin_inset LatexCommand \index{Loop reversing}
7620 \labelwidthstring 00.00.0000
7637 \begin_inset LatexCommand \index{-\/-nolabelopt }
7641 Will not optimize labels (makes the dumpfiles more readable).
7643 \labelwidthstring 00.00.0000
7658 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7664 Will not memcpy initialized data from code space into xdata space.
7665 This saves a few bytes in code space if you don't have initialized data
7666 \begin_inset LatexCommand \index{Variable initialization}
7672 \labelwidthstring 00.00.0000
7687 \begin_inset LatexCommand \index{-\/-nooverlay}
7693 The compiler will not overlay parameters and local variables of any function,
7694 see section Parameters and local variables for more details.
7696 \labelwidthstring 00.00.0000
7711 \begin_inset LatexCommand \index{-\/-no-peep}
7717 Disable peep-hole optimization with built-in rules.
7719 \labelwidthstring 00.00.0000
7736 \begin_inset LatexCommand \index{-\/-peep-file}
7741 <filename> This option can be used to use additional rules to be used by
7742 the peep hole optimizer.
7744 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7749 Peep Hole optimizations for details on how to write these rules.
7751 \labelwidthstring 00.00.0000
7766 \begin_inset LatexCommand \index{-\/-peep-asm}
7772 Pass the inline assembler code through the peep hole optimizer.
7773 This can cause unexpected changes to inline assembler code, please go through
7774 the peephole optimizer
7775 \begin_inset LatexCommand \index{Peephole optimizer}
7779 rules defined in the source file tree '<target>/peeph.def' before using
7782 \labelwidthstring 00.00.0000
7797 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7803 The compiler will optimize code generation towards fast code, possibly
7804 at the expense of code size.
7806 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7821 \begin_inset LatexCommand \index{-\/-opt-code-size}
7827 The compiler will optimize code generation towards compact code, possibly
7828 at the expense of code speed.
7832 \begin_inset LatexCommand \index{Options other}
7838 \labelwidthstring 00.00.0000
7854 \begin_inset LatexCommand \index{-\/-compile-only}
7859 \begin_inset LatexCommand \index{-c -\/-compile-only}
7865 will compile and assemble the source, but will not call the linkage editor.
7867 \labelwidthstring 00.00.0000
7886 \begin_inset LatexCommand \index{-\/-c1mode}
7892 reads the preprocessed source from standard input and compiles it.
7893 The file name for the assembler output must be specified using the -o option.
7895 \labelwidthstring 00.00.0000
7900 \begin_inset LatexCommand \index{-E}
7906 Run only the C preprocessor.
7907 Preprocess all the C source files specified and output the results to standard
7910 \labelwidthstring 00.00.0000
7916 \begin_inset LatexCommand \index{-o <path/file>}
7922 The output path resp.
7923 file where everything will be placed.
7924 If the parameter is a path, it must have a trailing slash (or backslash
7925 for the Windows binaries) to be recognized as a path.
7928 \labelwidthstring 00.00.0000
7943 \begin_inset LatexCommand \index{-\/-stack-auto}
7954 All functions in the source file will be compiled as
7959 \begin_inset LatexCommand \index{reentrant}
7964 the parameters and local variables will be allocated on the stack
7965 \begin_inset LatexCommand \index{stack}
7971 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7975 Parameters and Local Variables for more details.
7976 If this option is used all source files in the project should be compiled
7978 It automatically implies --int-long-reent and --float-reent.
7981 \labelwidthstring 00.00.0000
7996 \begin_inset LatexCommand \index{-\/-callee-saves}
8000 function1[,function2][,function3]....
8003 The compiler by default uses a caller saves convention for register saving
8004 across function calls, however this can cause unnecessary register pushing
8005 & popping when calling small functions from larger functions.
8006 This option can be used to switch the register saving convention for the
8007 function names specified.
8008 The compiler will not save registers when calling these functions, no extra
8009 code will be generated at the entry & exit (function prologue
8012 \begin_inset LatexCommand \index{function prologue}
8021 \begin_inset LatexCommand \index{function epilogue}
8027 ) for these functions to save & restore the registers used by these functions,
8028 this can SUBSTANTIALLY reduce code & improve run time performance of the
8030 In the future the compiler (with inter procedural analysis) will be able
8031 to determine the appropriate scheme to use for each function call.
8032 DO NOT use this option for built-in functions such as _mulint..., if this
8033 option is used for a library function the appropriate library function
8034 needs to be recompiled with the same option.
8035 If the project consists of multiple source files then all the source file
8036 should be compiled with the same -
8046 -callee-saves option string.
8047 Also see #pragma\SpecialChar ~
8049 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8055 \labelwidthstring 00.00.0000
8070 \begin_inset LatexCommand \index{-\/-debug}
8079 When this option is used the compiler will generate debug information.
8080 The debug information collected in a file with .cdb extension can be used
8082 For more information see documentation for SDCDB.
8083 Another file with no extension contains debug information in AOMF or AOMF51
8084 \begin_inset LatexCommand \index{AOMF, AOMF51}
8088 format which is commonly used by third party tools.
8090 \labelwidthstring 00.00.0000
8095 \begin_inset LatexCommand \index{-S}
8106 Stop after the stage of compilation proper; do not assemble.
8107 The output is an assembler code file for the input file specified.
8109 \labelwidthstring 00.00.0000
8124 \begin_inset LatexCommand \index{-\/-int-long-reent}
8130 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8131 Note by default these libraries are compiled as non-reentrant.
8132 See section Installation for more details.
8134 \labelwidthstring 00.00.0000
8149 \begin_inset LatexCommand \index{-\/-cyclomatic}
8158 This option will cause the compiler to generate an information message for
8159 each function in the source file.
8160 The message contains some
8164 information about the function.
8165 The number of edges and nodes the compiler detected in the control flow
8166 graph of the function, and most importantly the
8168 cyclomatic complexity
8169 \begin_inset LatexCommand \index{Cyclomatic complexity}
8175 see section on Cyclomatic Complexity for more details.
8177 \labelwidthstring 00.00.0000
8192 \begin_inset LatexCommand \index{-\/-float-reent}
8198 Floating point library is compiled as reentrant
8199 \begin_inset LatexCommand \index{reentrant}
8204 See section Installation for more details.
8206 \labelwidthstring 00.00.0000
8221 \begin_inset LatexCommand \index{-\/-main-return}
8227 This option can be used if the code generated is called by a monitor program
8228 or if the main routine includes an endless loop.
8229 This option results in slightly smaller code and saves two bytes of stack
8231 The return from the 'main'
8232 \begin_inset LatexCommand \index{main return}
8236 function will return to the function calling main.
8237 The default setting is to lock up i.e.
8244 \labelwidthstring 00.00.0000
8259 \begin_inset LatexCommand \index{-\/-nostdinc}
8265 This will prevent the compiler from passing on the default include path
8266 to the preprocessor.
8268 \labelwidthstring 00.00.0000
8283 \begin_inset LatexCommand \index{-\/-nostdlib}
8289 This will prevent the compiler from passing on the default library
8290 \begin_inset LatexCommand \index{Libraries}
8296 \labelwidthstring 00.00.0000
8311 \begin_inset LatexCommand \index{-\/-verbose}
8317 Shows the various actions the compiler is performing.
8319 \labelwidthstring 00.00.0000
8324 \begin_inset LatexCommand \index{-V}
8330 Shows the actual commands the compiler is executing.
8332 \labelwidthstring 00.00.0000
8347 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8353 Hides your ugly and inefficient c-code from the asm file, so you can always
8354 blame the compiler :)
8356 \labelwidthstring 00.00.0000
8371 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8377 Will not include peep-hole comments in the generated files.
8379 \labelwidthstring 00.00.0000
8394 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8400 Include i-codes in the asm file.
8401 Sounds like noise but is most helpful for debugging the compiler itself.
8403 \labelwidthstring 00.00.0000
8418 \begin_inset LatexCommand \index{-\/-less-pedantic}
8424 Disable some of the more pedantic warnings
8425 \begin_inset LatexCommand \index{Warnings}
8429 (jwk burps: please be more specific here, please!).
8431 \labelwidthstring 00.00.0000
8445 -disable-warning\SpecialChar ~
8447 \begin_inset LatexCommand \index{-\/-disable-warning}
8453 Disable specific warning with number <nnnn>.
8455 \labelwidthstring 00.00.0000
8470 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8476 Display the directories in the compiler's search path
8478 \labelwidthstring 00.00.0000
8493 \begin_inset LatexCommand \index{-\/-vc}
8499 Display errors and warnings using MSVC style, so you can use SDCC with
8500 the visual studio IDE
8501 \begin_inset LatexCommand \index{IDE}
8506 With SDCC both offering a GCC-like (the default) and a MSVC-like
8507 \begin_inset LatexCommand \index{MSVC output style}
8511 output style, integration into most programming editors should be straightforwa
8514 \labelwidthstring 00.00.0000
8529 \begin_inset LatexCommand \index{-\/-use-stdout}
8535 Send errors and warnings to stdout instead of stderr.
8537 \labelwidthstring 00.00.0000
8542 asmOption[,asmOption]
8545 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8550 Pass the asmOption to the assembler
8551 \begin_inset LatexCommand \index{Options assembler}
8556 \begin_inset LatexCommand \index{Assembler options}
8561 See file sdcc/as/doc/asxhtm.html for assembler options.cd
8563 \labelwidthstring 00.00.0000
8578 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8584 Generally follow the C89 standard, but allow SDCC features that conflict
8585 with the standard (default).
8587 \labelwidthstring 00.00.0000
8602 \begin_inset LatexCommand \index{-\/-std-c89}
8608 Follow the C89 standard and disable SDCC features that conflict with the
8611 \labelwidthstring 00.00.0000
8626 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8632 Generally follow the C99 standard, but allow SDCC features that conflict
8633 with the standard (incomplete support).
8635 \labelwidthstring 00.00.0000
8650 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8656 Follow the C99 standard and disable SDCC features that conflict with the
8657 standard (incomplete support).
8659 \labelwidthstring 00.00.0000
8676 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8681 <Name> The name to be used for the code
8682 \begin_inset LatexCommand \index{code}
8686 segment, default CSEG.
8687 This is useful if you need to tell the compiler to put the code in a special
8688 segment so you can later on tell the linker to put this segment in a special
8690 Can be used for instance when using bank switching to put the code in a
8693 \labelwidthstring 00.00.0000
8710 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8715 <Name> The name to be used for the const
8716 \begin_inset LatexCommand \index{code}
8720 segment, default CONST.
8721 This is useful if you need to tell the compiler to put the const data in
8722 a special segment so you can later on tell the linker to put this segment
8723 in a special place in memory.
8724 Can be used for instance when using bank switching to put the const data
8727 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8739 a SDCC compiler option but if you want
8743 warnings you can use a separate tool dedicated to syntax checking like
8745 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8750 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8755 \begin_inset LatexCommand \url{http://www.splint.org}
8760 To make your source files parseable by splint you will have to include
8766 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8770 in your source file and add brackets around extended keywords (like
8773 \begin_inset Quotes sld
8786 \begin_inset Quotes srd
8794 \begin_inset Quotes sld
8797 __interrupt\SpecialChar ~
8799 \begin_inset Quotes srd
8807 Splint has an excellent on line manual at
8808 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8812 and it's capabilities go beyond pure syntax checking.
8813 You'll need to tell splint the location of SDCC's include files so a typical
8814 command line could look like this:
8818 splint\SpecialChar ~
8820 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8825 Intermediate Dump Options
8826 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8831 \begin_inset LatexCommand \index{Options intermediate dump}
8836 \begin_inset LatexCommand \index{Intermediate dump options}
8843 The following options are provided for the purpose of retargetting and debugging
8845 They provide a means to dump the intermediate code (iCode
8846 \begin_inset LatexCommand \index{iCode}
8850 ) generated by the compiler in human readable form at various stages of
8851 the compilation process.
8852 More on iCodes see chapter
8853 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8858 \begin_inset Quotes srd
8861 The anatomy of the compiler
8862 \begin_inset Quotes srd
8867 \labelwidthstring 00.00.0000
8882 \begin_inset LatexCommand \index{-\/-dumpraw}
8888 This option will cause the compiler to dump the intermediate code into
8891 <source filename>.dumpraw
8893 just after the intermediate code has been generated for a function, i.e.
8894 before any optimizations are done.
8896 \begin_inset LatexCommand \index{Basic blocks}
8900 at this stage ordered in the depth first number, so they may not be in
8901 sequence of execution.
8903 \labelwidthstring 00.00.0000
8918 \begin_inset LatexCommand \index{-\/-dumpgcse}
8924 Will create a dump of iCode's, after global subexpression elimination
8925 \begin_inset LatexCommand \index{Global subexpression elimination}
8931 <source filename>.dumpgcse.
8933 \labelwidthstring 00.00.0000
8948 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8954 Will create a dump of iCode's, after deadcode elimination
8955 \begin_inset LatexCommand \index{Dead-code elimination}
8961 <source filename>.dumpdeadcode.
8963 \labelwidthstring 00.00.0000
8978 \begin_inset LatexCommand \index{-\/-dumploop}
8987 Will create a dump of iCode's, after loop optimizations
8988 \begin_inset LatexCommand \index{Loop optimization}
8994 <source filename>.dumploop.
8996 \labelwidthstring 00.00.0000
9011 \begin_inset LatexCommand \index{-\/-dumprange}
9020 Will create a dump of iCode's, after live range analysis
9021 \begin_inset LatexCommand \index{Live range analysis}
9027 <source filename>.dumprange.
9029 \labelwidthstring 00.00.0000
9044 \begin_inset LatexCommand \index{-\/-dumlrange}
9050 Will dump the life ranges
9051 \begin_inset LatexCommand \index{Live range analysis}
9057 \labelwidthstring 00.00.0000
9072 \begin_inset LatexCommand \index{-\/-dumpregassign}
9081 Will create a dump of iCode's, after register assignment
9082 \begin_inset LatexCommand \index{Register assignment}
9088 <source filename>.dumprassgn.
9090 \labelwidthstring 00.00.0000
9105 \begin_inset LatexCommand \index{-\/-dumplrange}
9111 Will create a dump of the live ranges of iTemp's
9113 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9128 \begin_inset LatexCommand \index{-\/-dumpall}
9139 Will cause all the above mentioned dumps to be created.
9142 Redirecting output on Windows Shells
9144 \added_space_bottom bigskip
9145 By default SDCC writes it's error messages to
9146 \begin_inset Quotes sld
9150 \begin_inset Quotes srd
9154 To force all messages to
9155 \begin_inset Quotes sld
9159 \begin_inset Quotes srd
9183 \begin_inset LatexCommand \index{-\/-use-stdout}
9188 Additionally, if you happen to have visual studio installed in your windows
9189 machine, you can use it to compile your sources using a custom build and
9205 \begin_inset LatexCommand \index{-\/-vc}
9210 Something like this should work:
9254 -model-large -c $(InputPath)
9257 Environment variables
9258 \begin_inset LatexCommand \index{Environment variables}
9265 SDCC recognizes the following environment variables:
9267 \labelwidthstring 00.00.0000
9272 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9278 SDCC installs a signal handler
9279 \begin_inset LatexCommand \index{signal handler}
9283 to be able to delete temporary files after an user break (^C) or an exception.
9284 If this environment variable is set, SDCC won't install the signal handler
9285 in order to be able to debug SDCC.
9287 \labelwidthstring 00.00.0000
9294 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9300 Path, where temporary files will be created.
9301 The order of the variables is the search order.
9302 In a standard *nix environment these variables are not set, and there's
9303 no need to set them.
9304 On Windows it's recommended to set one of them.
9306 \labelwidthstring 00.00.0000
9311 \begin_inset LatexCommand \index{SDCC\_HOME}
9318 \begin_inset LatexCommand \ref{sub:Install-paths}
9324 \begin_inset Quotes sld
9328 \begin_inset Quotes srd
9333 \labelwidthstring 00.00.0000
9338 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9345 \begin_inset LatexCommand \ref{sub:Search-Paths}
9351 \begin_inset Quotes sld
9355 \begin_inset Quotes srd
9360 \labelwidthstring 00.00.0000
9365 \begin_inset LatexCommand \index{SDCC\_LIB}
9372 \begin_inset LatexCommand \ref{sub:Search-Paths}
9378 \begin_inset Quotes sld
9382 \begin_inset Quotes srd
9387 \added_space_bottom bigskip
9388 There are some more environment variables recognized by SDCC, but these
9389 are solely used for debugging purposes.
9390 They can change or disappear very quickly, and will never be documented.
9393 Storage Class Language Extensions
9396 MCS51/DS390 Storage Class
9397 \begin_inset LatexCommand \index{Storage class}
9404 In addition to the ANSI storage classes SDCC allows the following MCS51
9405 specific storage classes:
9406 \layout Subsubsection
9409 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9414 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9419 \begin_inset LatexCommand \index{near (storage class)}
9424 \begin_inset LatexCommand \index{\_\_near (storage class)}
9435 storage class for the Small Memory model (
9443 or the more ANSI-C compliant forms
9451 can be used synonymously).
9452 Variables declared with this storage class will be allocated in the directly
9453 addressable portion of the internal RAM of a 8051, e.g.:
9458 __data unsigned char test_data;
9461 Writing 0x01 to this variable generates the assembly code:
9466 75*00 01\SpecialChar ~
9472 \layout Subsubsection
9475 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9480 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9485 \begin_inset LatexCommand \index{far (storage class)}
9490 \begin_inset LatexCommand \index{\_\_far (storage class)}
9497 Variables declared with this storage class will be placed in the external
9503 storage class for the Large Memory model, e.g.:
9508 __xdata unsigned char test_xdata;
9511 Writing 0x01 to this variable generates the assembly code:
9516 90s00r00\SpecialChar ~
9545 \layout Subsubsection
9548 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9553 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9560 Variables declared with this storage class will be allocated into the indirectly
9561 addressable portion of the internal ram of a 8051, e.g.:
9566 __idata unsigned char test_idata;
9569 Writing 0x01 to this variable generates the assembly code:
9598 Please note, the first 128 byte of idata physically access the same RAM
9600 The original 8051 had 128 byte idata memory, nowadays most devices have
9601 256 byte idata memory.
9603 \begin_inset LatexCommand \index{stack}
9607 is located in idata memory.
9608 \layout Subsubsection
9611 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9616 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9623 Paged xdata access is just as straightforward as using the other addressing
9625 It is typically located at the start of xdata and has a maximum size of
9627 The following example writes 0x01 to the pdata variable.
9628 Please note, pdata access physically accesses xdata memory.
9629 The high byte of the address is determined by port P2
9630 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9634 (or in case of some 8051 variants by a separate Special Function Register,
9636 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9645 storage class for the Medium Memory model, e.g.:
9650 __pdata unsigned char test_pdata;
9653 Writing 0x01 to this variable generates the assembly code:
9697 \begin_inset LatexCommand \index{-\/-xstack}
9701 option is used the pdata memory area is followed by the xstack memory area
9702 and the sum of their sizes is limited to 256 bytes.
9703 \layout Subsubsection
9706 \begin_inset LatexCommand \index{code}
9711 \begin_inset LatexCommand \index{\_\_code}
9718 'Variables' declared with this storage class will be placed in the code
9724 __code unsigned char test_code;
9727 Read access to this variable generates the assembly code:
9732 90s00r6F\SpecialChar ~
9735 mov dptr,#_test_code
9764 indexed arrays of characters in code memory can be accessed efficiently:
9769 __code char test_array[] = {'c','h','e','a','p'};
9772 Read access to this array using an 8-bit unsigned index generates the assembly
9789 90s00r41\SpecialChar ~
9792 mov dptr,#_test_array
9807 \layout Subsubsection
9810 \begin_inset LatexCommand \index{bit}
9815 \begin_inset LatexCommand \index{\_\_bit}
9822 This is a data-type and a storage class specifier.
9823 When a variable is declared as a bit, it is allocated into the bit addressable
9824 memory of 8051, e.g.:
9832 Writing 1 to this variable generates the assembly code:
9848 The bit addressable memory consists of 128 bits which are located from 0x20
9849 to 0x2f in data memory.
9852 Apart from this 8051 specific storage class most architectures support ANSI-C
9854 \begin_inset LatexCommand \index{bitfields}
9864 Not really meant as examples, but nevertheless showing what bitfields are
9865 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9869 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9870 signed modifier are implemented as unsigned.
9871 \layout Subsubsection
9874 \begin_inset LatexCommand \index{sfr}
9879 \begin_inset LatexCommand \index{\_\_sfr}
9884 \begin_inset LatexCommand \index{sfr16}
9889 \begin_inset LatexCommand \index{\_\_sfr16}
9894 \begin_inset LatexCommand \index{sfr32}
9899 \begin_inset LatexCommand \index{\_\_sfr32}
9904 \begin_inset LatexCommand \index{\_\_sbit}
9909 \begin_inset LatexCommand \index{sbit}
9916 Like the bit keyword,
9918 sfr / sfr16 / sfr32 / sbit
9920 signify both a data-type and storage class, they are used to describe the
9941 variables of a 8051, eg:
9947 \begin_inset LatexCommand \index{at}
9952 \begin_inset LatexCommand \index{\_\_at}
9956 (0x80) P0;\SpecialChar ~
9957 /* special function register P0 at location 0x80 */
9961 /* 16 bit special function register combination for timer 0
9965 with the high byte at location 0x8C and the low byte at location 0x8A */
9967 __sfr16 __at (0x8C8A) TMR0;
9972 \begin_inset LatexCommand \index{at}
9977 \begin_inset LatexCommand \index{\_\_at}
9981 (0xd7) CY;\SpecialChar ~
9983 \begin_inset LatexCommand \index{Flags}
9988 \begin_inset LatexCommand \index{Carry flag}
9995 Special function registers which are located on an address dividable by
9996 8 are bit-addressable, an
10000 addresses a specific bit within these sfr.
10002 16 Bit and 32 bit special function register combinations which require a
10003 certain access order are better not declared using
10012 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10013 this is not guaranteed.
10018 Please note, if you use a header file which was written for another compiler
10019 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10025 Specifically the syntax
10028 sfr P0 = 0x80;\SpecialChar ~
10035 by SDCC to an assignment of 0x80 to a variable called P0
10038 \begin_inset Marginal
10052 Nevertheless it is possible to write header files
10053 \begin_inset LatexCommand \index{Header files}
10058 \begin_inset LatexCommand \index{Include files}
10062 which can be shared among different compilers (see section
10063 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10069 \layout Subsubsection
10072 \begin_inset LatexCommand \index{Pointer}
10076 to MCS51/DS390 specific memory spaces
10079 SDCC allows (via language extensions) pointers to explicitly point to any
10080 of the memory spaces
10081 \begin_inset LatexCommand \index{Memory model}
10086 In addition to the explicit pointers, the compiler uses (by default) generic
10087 pointers which can be used to point to any of the memory spaces.
10091 Pointer declaration examples:
10096 /* pointer physically in internal ram pointing to object in external ram
10099 __xdata unsigned char * __data p;
10103 /* pointer physically in external ram pointing to object in internal ram
10106 __data unsigned char * __xdata p;
10110 /* pointer physically in code rom pointing to data in xdata space */
10112 __xdata unsigned char * __code p;
10116 /* pointer physically in code space pointing to data in code space */
10118 __code unsigned char * __code p;
10122 /* generic pointer physically located in xdata space */
10124 unsigned char * __xdata p;
10128 /* generic pointer physically located in default memory space */
10134 /* the following is a function pointer
10135 \begin_inset LatexCommand \index{function pointer}
10139 physically located in data space */
10141 char (* __data fp)(void);
10144 Well you get the idea.
10149 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10162 The highest order byte of the
10166 pointers contains the data space information.
10167 Assembler support routines are called whenever data is stored or retrieved
10173 These are useful for developing reusable library
10174 \begin_inset LatexCommand \index{Libraries}
10179 Explicitly specifying the pointer
10180 \begin_inset LatexCommand \index{pointer}
10184 type will generate the most efficient code.
10185 \layout Subsubsection
10187 Notes on MCS51 memory
10188 \begin_inset LatexCommand \index{MCS51 memory}
10195 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10196 RAM memory which is structured as follows:
10200 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10203 - Bytes 20-2F - 16 bytes to hold 128 bit
10204 \begin_inset LatexCommand \index{bit}
10210 - Bytes 30-7F - 80 bytes for general purpose use.
10215 Additionally some members of the MCS51 family may have up to 128 bytes of
10216 additional, indirectly addressable, internal RAM memory (
10221 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10226 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10231 Furthermore, some chips may have some built in external memory (
10236 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10241 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10245 ) which should not be confused with the internal, directly addressable RAM
10251 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10256 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10261 Sometimes this built in
10265 memory has to be activated before using it (you can probably find this
10266 information on the datasheet of the microcontroller your are using, see
10268 \begin_inset LatexCommand \ref{sub:Startup-Code}
10276 Normally SDCC will only use the first bank
10277 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10281 of registers (register bank 0), but it is possible to specify that other
10282 banks of registers (keyword
10289 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10294 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10300 ) should be used in interrupt
10301 \begin_inset LatexCommand \index{interrupt}
10306 \begin_inset LatexCommand \index{\_\_interrupt}
10311 By default, the compiler will place the stack after the last byte of allocated
10312 memory for variables.
10313 For example, if the first 2 banks of registers are used, and only four
10318 variables, it will position the base of the internal stack at address 20
10320 This implies that as the stack
10321 \begin_inset LatexCommand \index{stack}
10325 grows, it will use up the remaining register banks, and the 16 bytes used
10326 by the 128 bit variables, and 80 bytes for general purpose use.
10327 If any bit variables are used, the data variables will be placed in unused
10328 register banks and after the byte holding the last bit variable.
10329 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10334 variables will be placed starting from address 0x10 to 0x20 and continue
10347 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10351 to specify the start address of the
10366 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10370 to specify the size of the total internal RAM (
10384 By default the 8051 linker will place the stack after the last byte of (i)data
10397 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10401 allows you to specify the start of the stack, i.e.
10402 you could start it after any data in the general purpose area.
10403 If your microcontroller has additional indirectly addressable internal
10408 ) you can place the stack on it.
10409 You may also need to use -
10420 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10424 to set the start address of the external RAM (
10439 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10443 to specify its size.
10444 Same goes for the code memory, using -
10455 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10470 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10475 If in doubt, don't specify any options and see if the resulting memory
10476 layout is appropriate, then you can adjust it.
10478 \added_space_bottom bigskip
10479 The linker generates two files with memory allocation information.
10480 The first, with extension .map
10481 \begin_inset LatexCommand \index{<file>.map}
10485 shows all the variables and segments.
10486 The second with extension .mem
10487 \begin_inset LatexCommand \index{<file>.mem}
10491 shows the final memory layout.
10492 The linker will complain either if memory segments overlap, there is not
10493 enough memory, or there is not enough space for stack.
10494 If you get any linking warnings and/or errors related to stack or segments
10495 allocation, take a look at either the .map or .mem files to find out what
10497 The .mem file may even suggest a solution to the problem.
10500 Z80/Z180 Storage Class
10501 \begin_inset LatexCommand \index{Z80!Storage class}
10505 Language Extensions
10506 \layout Subsubsection
10509 \begin_inset LatexCommand \index{sfr}
10514 \begin_inset LatexCommand \index{\_\_sfr}
10518 (in/out to 8-bit addresses)
10522 \begin_inset LatexCommand \index{Z80}
10526 family has separate address spaces for memory and
10536 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10541 \begin_inset LatexCommand \index{Z80!I/O memory}
10546 \begin_inset LatexCommand \index{Z180!I/O memory}
10550 is accessed with special instructions, e.g.:
10555 sfr at 0x78 IoPort;\SpecialChar ~
10557 /* define a var in I/O space at 78h called IoPort */
10561 Writing 0x01 to this variable generates the assembly code:
10566 3E 01\SpecialChar ~
10574 D3 78\SpecialChar ~
10581 \layout Subsubsection
10584 \begin_inset LatexCommand \index{sfr}
10589 \begin_inset LatexCommand \index{\_\_sfr}
10593 (in/out to 16-bit addresses)
10600 is used to support 16 bit addresses in I/O memory e.g.:
10606 \begin_inset LatexCommand \index{at}
10611 \begin_inset LatexCommand \index{\_\_at}
10618 Writing 0x01 to this variable generates the assembly code:
10623 01 23 01\SpecialChar ~
10628 3E 01\SpecialChar ~
10636 ED 79\SpecialChar ~
10643 \layout Subsubsection
10646 \begin_inset LatexCommand \index{sfr}
10651 \begin_inset LatexCommand \index{\_\_sfr}
10655 (in0/out0 to 8 bit addresses on Z180
10656 \begin_inset LatexCommand \index{Z180}
10661 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10667 \added_space_bottom bigskip
10668 The compiler option -
10679 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10683 =180 (80) and a compiler #pragma\SpecialChar ~
10685 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10689 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10699 If you include the file z180.h this will be set automatically.
10703 \begin_inset LatexCommand \index{HC08!Storage class}
10707 Language Extensions
10708 \layout Subsubsection
10711 \begin_inset LatexCommand \index{data (hc08 storage class)}
10716 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10723 The data storage class declares a variable that resides in the first 256
10724 bytes of memory (the direct page).
10726 \begin_inset LatexCommand \index{HC08}
10730 is most efficient at accessing variables (especially pointers) stored here.
10731 \layout Subsubsection
10734 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10739 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10745 \added_space_bottom bigskip
10746 The xdata storage class declares a variable that can reside anywhere in
10748 This is the default if no storage class is specified.
10752 Absolute Addressing
10753 \begin_inset LatexCommand \index{Absolute addressing}
10760 Data items can be assigned an absolute address with the
10763 \begin_inset LatexCommand \index{at}
10768 \begin_inset LatexCommand \index{\_\_at}
10774 keyword, in addition to a storage class, e.g.:
10780 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10785 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10790 \begin_inset LatexCommand \index{at}
10795 \begin_inset LatexCommand \index{\_\_at}
10799 0x7ffe unsigned int chksum;
10802 or, better conforming to ISO/IEC 9899 C:
10807 __xdata __at (0x7ffe) unsigned int chksum;
10810 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10811 of the external ram.
10816 reserve any space for variables declared in this way
10817 \begin_inset Marginal
10828 (they are implemented with an equate in the assembler).
10829 Thus it is left to the programmer to make sure there are no overlaps with
10830 other variables that are declared without the absolute address.
10831 The assembler listing file (.lst
10832 \begin_inset LatexCommand \index{<file>.lst}
10836 ) and the linker output files (.rst
10837 \begin_inset LatexCommand \index{<file>.rst}
10842 \begin_inset LatexCommand \index{<file>.map}
10846 ) are good places to look for such overlaps.
10847 Variables with an absolute address are
10850 \begin_inset Marginal
10864 \begin_inset LatexCommand \index{Variable initialization}
10871 In case of memory mapped I/O devices the keyword
10875 has to be used to tell the compiler that accesses might not be removed:
10881 \begin_inset LatexCommand \index{volatile}
10886 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10891 \begin_inset LatexCommand \index{at}
10895 (0x8000) unsigned char PORTA_8255;
10898 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10903 \begin_inset LatexCommand \index{Aligned array}
10910 starts at a block (256 byte) boundary
10911 \begin_inset LatexCommand \index{block boundary}
10916 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10922 Absolute addresses can be specified for variables in all storage classes,
10929 \begin_inset LatexCommand \index{bit}
10934 \begin_inset LatexCommand \index{at}
10941 The above example will allocate the variable at offset 0x02 in the bit-addressab
10943 There is no real advantage to assigning absolute addresses to variables
10944 in this manner, unless you want strict control over all the variables allocated.
10945 One possible use would be to write hardware portable code.
10946 For example, if you have a routine that uses one or more of the microcontroller
10947 I/O pins, and such pins are different for two different hardwares, you
10948 can declare the I/O pins in your routine using:
10954 \begin_inset LatexCommand \index{volatile}
10958 __bit MOSI;\SpecialChar ~
10962 /* master out, slave in */
10964 extern volatile __bit MISO;\SpecialChar ~
10968 /* master in, slave out */
10970 extern volatile __bit MCLK;\SpecialChar ~
10978 /* Input and Output of a byte on a 3-wire serial bus.
10983 If needed adapt polarity of clock, polarity of data and bit order
10988 unsigned char spi_io(unsigned char out_byte)
11012 MOSI = out_byte & 0x80;
11042 /* _asm nop _endasm; */\SpecialChar ~
11050 /* for slow peripherals */
11101 Then, someplace in the code for the first hardware you would use
11107 \begin_inset LatexCommand \index{at}
11112 \begin_inset LatexCommand \index{\_\_at}
11116 (0x80) MOSI;\SpecialChar ~
11120 /* I/O port 0, bit 0 */
11122 __bit __at (0x81) MISO;\SpecialChar ~
11126 /* I/O port 0, bit 1 */
11128 __bit __at (0x82) MCLK;\SpecialChar ~
11132 /* I/O port 0, bit 2 */
11135 Similarly, for the second hardware you would use
11140 __bit __at (0x83) MOSI;\SpecialChar ~
11144 /* I/O port 0, bit 3 */
11146 __bit __at (0x91) MISO;\SpecialChar ~
11150 /* I/O port 1, bit 1 */
11153 \begin_inset LatexCommand \index{bit}
11157 __at (0x92) MCLK;\SpecialChar ~
11161 /* I/O port 1, bit 2 */
11163 \added_space_bottom bigskip
11164 and you can use the same hardware dependent routine without changes, as
11165 for example in a library.
11166 This is somehow similar to sbit, but only one absolute address has to be
11167 specified in the whole project.
11171 \begin_inset LatexCommand \index{Parameters}
11176 \begin_inset LatexCommand \index{function parameter}
11181 \begin_inset LatexCommand \index{local variables}
11186 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11193 Automatic (local) variables and parameters to functions can either be placed
11194 on the stack or in data-space.
11195 The default action of the compiler is to place these variables in the internal
11196 RAM (for small model) or external RAM (for large model).
11197 This in fact makes them similar to
11200 \begin_inset LatexCommand \index{static}
11206 so by default functions are non-reentrant
11207 \begin_inset LatexCommand \index{reentrant}
11216 They can be placed on the stack
11217 \begin_inset LatexCommand \index{stack}
11234 \begin_inset LatexCommand \index{-\/-stack-auto}
11242 #pragma\SpecialChar ~
11246 \begin_inset LatexCommand \index{\#pragma stackauto}
11253 \begin_inset LatexCommand \index{reentrant}
11259 keyword in the function declaration, e.g.:
11264 unsigned char foo(char i) __reentrant
11278 Since stack space on 8051 is limited, the
11296 option should be used sparingly.
11297 Note that the reentrant keyword just means that the parameters & local
11298 variables will be allocated to the stack, it
11302 mean that the function is register bank
11303 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11312 \begin_inset LatexCommand \index{local variables}
11316 can be assigned storage classes and absolute
11317 \begin_inset LatexCommand \index{Absolute addressing}
11326 unsigned char foo()
11334 __xdata unsigned char i;
11347 \begin_inset LatexCommand \index{at}
11351 (0x31) unsigned char j;
11363 In the above example the variable
11367 will be allocated in the external ram,
11371 in bit addressable space and
11390 or when a function is declared as
11394 this should only be done for static variables.
11398 \begin_inset LatexCommand \index{function parameter}
11402 however are not allowed any storage class
11403 \begin_inset LatexCommand \index{Storage class}
11407 , (storage classes for parameters will be ignored), their allocation is
11408 governed by the memory model in use, and the reentrancy options.
11411 It is however allowed to use bit parameters in reentrant functions and also
11412 non-static local bit variables are supported.
11413 Efficient use is limited to 8 semi-bitregisters in bit space.
11414 They are pushed and popped to stack
11415 \begin_inset LatexCommand \index{stack}
11419 as a single byte just like the normal registers.
11423 \begin_inset LatexCommand \label{sub:Overlaying}
11428 \begin_inset LatexCommand \index{Overlaying}
11436 \begin_inset LatexCommand \index{reentrant}
11440 functions SDCC will try to reduce internal ram space usage by overlaying
11441 parameters and local variables of a function (if possible).
11442 Parameters and local variables
11443 \begin_inset LatexCommand \index{local variables}
11447 of a function will be allocated to an overlayable segment if the function
11450 no other function calls and the function is non-reentrant and the memory
11452 \begin_inset LatexCommand \index{Memory model}
11459 If an explicit storage class
11460 \begin_inset LatexCommand \index{Storage class}
11464 is specified for a local variable, it will NOT be overlayed.
11467 Note that the compiler (not the linkage editor) makes the decision for overlayin
11469 Functions that are called from an interrupt service routine
11470 \begin_inset Marginal
11480 should be preceded by a #pragma\SpecialChar ~
11482 \begin_inset LatexCommand \index{\#pragma nooverlay}
11486 if they are not reentrant.
11489 Also note that the compiler does not do any processing of inline assembler
11490 code, so the compiler might incorrectly assign local variables and parameters
11491 of a function into the overlay segment if the inline assembler code calls
11492 other c-functions that might use the overlay.
11493 In that case the #pragma\SpecialChar ~
11494 nooverlay should be used.
11497 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11499 \begin_inset LatexCommand \index{Multiplication}
11504 \begin_inset LatexCommand \index{Division}
11508 will NOT be overlayed since these are implemented using external functions,
11517 \begin_inset LatexCommand \index{\#pragma nooverlay}
11523 void set_error(unsigned char errcd)
11539 void some_isr () __interrupt
11540 \begin_inset LatexCommand \index{interrupt}
11569 \added_space_bottom bigskip
11570 In the above example the parameter
11578 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11580 not present, this could cause unpredictable runtime behavior when called
11581 from an interrupt service routine.
11582 The #pragma\SpecialChar ~
11583 nooverlay ensures that the parameters and local variables for
11584 the function are NOT overlayed.
11587 Interrupt Service Routines
11588 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11595 General Information
11610 outines to be coded in C, with some extended keywords.
11615 void timer_isr (void) __interrupt (1) __using (1)
11629 The optional number following the
11632 \begin_inset LatexCommand \index{interrupt}
11637 \begin_inset LatexCommand \index{\_\_interrupt}
11643 keyword is the interrupt number this routine will service.
11644 When present, the compiler will insert a call to this routine in the interrupt
11646 \begin_inset LatexCommand \index{interrupt vector table}
11650 for the interrupt number specified.
11651 If you have multiple source files in your project, interrupt service routines
11652 can be present in any of them, but a prototype of the isr MUST be present
11653 or included in the file that contains the function
11658 The optional (8051 specific) keyword
11661 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11666 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11672 can be used to tell the compiler to use the specified register bank when
11673 generating code for this function.
11676 Interrupt service routines open the door for some very interesting bugs:
11677 \layout Subsubsection
11680 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11684 Common interrupt pitfall: variable not declared
11689 If an interrupt service routine changes variables which are accessed by
11690 other functions these variables have to be declared
11695 \begin_inset LatexCommand \index{volatile}
11701 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11706 \layout Subsubsection
11709 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11713 Common interrupt pitfall:
11718 If the access to these variables is not
11721 \begin_inset LatexCommand \index{atomic}
11728 the processor needs more than one instruction for the access and could
11729 be interrupted while accessing the variable) the interrupt must be disabled
11730 during the access to avoid inconsistent data.
11733 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11734 should be protected by disabling interrupts.
11735 You're not automatically on the safe side if you use 8 bit variables though.
11736 We need an example here: f.e.
11737 on the 8051 the harmless looking
11738 \begin_inset Quotes srd
11743 flags\SpecialChar ~
11748 \begin_inset Quotes sld
11757 \begin_inset Quotes srd
11762 flags\SpecialChar ~
11767 \begin_inset Quotes sld
11770 from within an interrupt routine might get lost if the interrupt occurs
11773 \begin_inset Quotes sld
11778 counter\SpecialChar ~
11783 \begin_inset Quotes srd
11786 is not atomic on the 8051 even if
11790 is located in data memory.
11792 Bugs like these are hard to reproduce and can cause a lot of trouble.
11794 \layout Subsubsection
11797 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11801 Common interrupt pitfall:
11806 The return address and the registers used in the interrupt service routine
11807 are saved on the stack
11808 \begin_inset LatexCommand \index{stack}
11812 so there must be sufficient stack space.
11813 If there isn't variables or registers (or even the return address itself)
11820 \begin_inset LatexCommand \index{stack overflow}
11824 is most likely to happen if the interrupt occurs during the
11825 \begin_inset Quotes sld
11829 \begin_inset Quotes srd
11832 subroutine when the stack is already in use for f.e.
11833 many return addresses.
11834 \layout Subsubsection
11837 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11841 Common interrupt pitfall:
11843 use of non-reentrant functions
11846 A special note here, int (16 bit) and long (32 bit) integer division
11847 \begin_inset LatexCommand \index{Division}
11852 \begin_inset LatexCommand \index{Multiplication}
11857 \begin_inset LatexCommand \index{Modulus}
11862 \begin_inset LatexCommand \index{Floating point support}
11866 operations are implemented using external support routines.
11867 If an interrupt service routine needs to do any of these operations then
11868 the support routines (as mentioned in a following section) will have to
11869 be recompiled using the
11882 \begin_inset LatexCommand \index{-\/-stack-auto}
11888 option and the source file will need to be compiled using the
11903 \begin_inset LatexCommand \index{-\/-int-long-reent}
11910 Note, the type promotion
11911 \begin_inset LatexCommand \index{type promotion}
11915 required by ANSI C can cause 16 bit routines to be used
11916 \begin_inset Marginal
11927 without the programmer being aware of it.
11931 (unsigned char)(tail-1)
11933 within the if clause in section
11934 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11940 \added_space_bottom bigskip
11941 Calling other functions from an interrupt service routine is not recommended,
11942 avoid it if possible.
11943 Note that when some function is called from an interrupt service routine
11944 it should be preceded by a #pragma\SpecialChar ~
11946 \begin_inset LatexCommand \index{\#pragma nooverlay}
11950 if it is not reentrant.
11951 Furthermore nonreentrant functions should not be called from the main program
11952 while the interrupt service routine might be active.
11953 They also must not be called from low priority interrupt service routines
11954 while a high priority interrupt service routine might be active.
11955 You could use semaphores or make the function
11959 if all parameters are passed in registers.
11962 \begin_inset LatexCommand \ref{sub:Overlaying}
11967 about Overlaying and section
11968 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11973 about Functions using private register banks.
11976 MCS51/DS390 Interrupt Service Routines
11980 \begin_inset LatexCommand \index{interrupt}
11984 numbers and the corresponding address & descriptions for the Standard 8051/8052
11986 SDCC will automatically adjust the
11987 \begin_inset LatexCommand \index{interrupt vector table}
11991 to the maximum interrupt number specified.
11997 \begin_inset Tabular
11998 <lyxtabular version="3" rows="9" columns="3">
12000 <column alignment="center" valignment="top" leftline="true" width="0in">
12001 <column alignment="left" valignment="top" leftline="true" width="0in">
12002 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12003 <row topline="true" bottomline="true">
12004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12029 <row topline="true">
12030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12055 <row topline="true">
12056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12081 <row topline="true">
12082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12107 <row topline="true">
12108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12133 <row topline="true">
12134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12159 <row topline="true">
12160 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12185 <row topline="true">
12186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12210 <row topline="true" bottomline="true">
12211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12244 If the interrupt service routine is defined without
12247 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12252 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12258 a register bank or with register bank 0 (
12262 0), the compiler will save the registers used by itself on the stack upon
12263 entry and restore them at exit, however if such an interrupt service routine
12264 calls another function then the entire register bank will be saved on the
12266 This scheme may be advantageous for small interrupt service routines which
12267 have low register usage.
12269 \added_space_bottom bigskip
12270 If the interrupt service routine is defined to be using a specific register
12275 & psw are saved and restored, if such an interrupt service routine calls
12276 another function (using another register bank) then the entire register
12277 bank of the called function will be saved on the stack
12278 \begin_inset LatexCommand \index{stack}
12283 This scheme is recommended for larger interrupt service routines.
12287 \begin_inset LatexCommand \index{HC08}
12291 Interrupt Service Routines
12293 \added_space_bottom bigskip
12294 Since the number of interrupts
12295 \begin_inset LatexCommand \index{HC08!interrupt}
12299 available is chip specific and the interrupt vector table always ends at
12300 the last byte of memory, the interrupt numbers corresponds to the interrupt
12301 vectors in reverse order of address.
12302 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12303 2 will use the interrupt vector at 0xfffa, and so on.
12304 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12305 this way; instead see section
12306 \begin_inset LatexCommand \ref{sub:Startup-Code}
12310 for details on customizing startup.
12313 Z80 Interrupt Service Routines
12317 \begin_inset LatexCommand \index{Z80}
12321 uses several different methods for determining the correct interrupt
12322 \begin_inset LatexCommand \index{Z80!interrupt}
12326 vector depending on the hardware implementation.
12327 Therefore, SDCC ignores the optional interrupt number and does not attempt
12328 to generate an interrupt vector table.
12331 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12332 instruction to return from the interrupt.
12333 To write an interrupt handler for the non-maskable interrupt, which needs
12334 a RETN instruction instead, add the
12343 void nmi_isr (void) critical interrupt
12356 \added_space_bottom bigskip
12357 However if you need to create a non-interruptable interrupt service routine
12358 you would also require the
12363 To distinguish between this and an nmi_isr you must provide an interrupt
12367 Enabling and Disabling Interrupts
12370 Critical Functions and Critical Statements
12373 A special keyword may be associated with a block or a function declaring
12379 SDCC will generate code to disable all interrupts
12380 \begin_inset LatexCommand \index{interrupt}
12384 upon entry to a critical function and restore the interrupt enable to the
12385 previous state before returning.
12386 Nesting critical functions will need one additional byte on the stack
12387 \begin_inset LatexCommand \index{stack}
12396 int foo () __critical
12397 \begin_inset LatexCommand \index{critical}
12402 \begin_inset LatexCommand \index{\_\_critical}
12427 The critical attribute maybe used with other attributes like
12437 may also be used to disable interrupts more locally:
12445 More than one statement could have been included in the block.
12448 Enabling and Disabling Interrupts directly
12452 \begin_inset LatexCommand \index{interrupt}
12456 can also be disabled and enabled directly (8051):
12461 EA = 0;\SpecialChar ~
12524 EA = 1;\SpecialChar ~
12591 On other architectures which have seperate opcodes for enabling and disabling
12592 interrupts you might want to make use of defines with inline assembly
12593 \begin_inset LatexCommand \index{Assembler routines}
12598 \begin_inset LatexCommand \index{HC08!interrupt}
12608 \begin_inset LatexCommand \index{\_asm}
12617 \begin_inset LatexCommand \index{\_endasm}
12626 #define SEI _asm\SpecialChar ~
12638 Note: it is sometimes sufficient to disable only a specific interrupt source
12640 a timer or serial interrupt by manipulating an
12643 \begin_inset LatexCommand \index{interrupt mask}
12653 Usually the time during which interrupts are disabled should be kept as
12655 This minimizes both
12660 \begin_inset LatexCommand \index{interrupt latency}
12664 (the time between the occurrence of the interrupt and the execution of
12665 the first code in the interrupt routine) and
12670 \begin_inset LatexCommand \index{interrupt jitter}
12674 (the difference between the shortest and the longest interrupt latency).
12675 These really are something different, f.e.
12676 a serial interrupt has to be served before its buffer overruns so it cares
12677 for the maximum interrupt latency, whereas it does not care about jitter.
12678 On a loudspeaker driven via a digital to analog converter which is fed
12679 by an interrupt a latency of a few milliseconds might be tolerable, whereas
12680 a much smaller jitter will be very audible.
12683 You can reenable interrupts within an interrupt routine and on some architecture
12684 s you can make use of two (or more) levels of
12686 interrupt priorities
12689 \begin_inset LatexCommand \index{interrupt priority}
12694 On some architectures which don't support interrupt priorities these can
12695 be implemented by manipulating the interrupt mask and reenabling interrupts
12696 within the interrupt routine.
12697 Check there is sufficient space on the stack
12698 \begin_inset LatexCommand \index{stack}
12702 and don't add complexity unless you have to.
12707 \begin_inset LatexCommand \index{semaphore}
12711 locking (mcs51/ds390)
12714 Some architectures (mcs51/ds390) have an atomic
12715 \begin_inset LatexCommand \index{atomic}
12728 These type of instructions are typically used in preemptive multitasking
12729 systems, where a routine f.e.
12730 claims the use of a data structure ('acquires a lock
12731 \begin_inset LatexCommand \index{lock}
12735 on it'), makes some modifications and then releases the lock when the data
12736 structure is consistent again.
12737 The instruction may also be used if interrupt and non-interrupt code have
12738 to compete for a resource.
12739 With the atomic bit test and clear instruction interrupts
12740 \begin_inset LatexCommand \index{interrupt}
12744 don't have to be disabled for the locking operation.
12748 SDCC generates this instruction if the source follows this pattern:
12754 \begin_inset LatexCommand \index{volatile}
12758 bit resource_is_free;
12762 if (resource_is_free)
12772 resource_is_free=0;
12785 resource_is_free=1;
12792 Note, mcs51 and ds390 support only an atomic
12793 \begin_inset LatexCommand \index{atomic}
12801 instruction (as opposed to atomic bit test and
12806 Functions using private register banks
12807 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12814 Some architectures have support for quickly changing register sets.
12815 SDCC supports this feature with the
12818 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12823 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12829 attribute (which tells the compiler to use a register bank
12830 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12834 other than the default bank zero).
12835 It should only be applied to
12838 \begin_inset LatexCommand \index{interrupt}
12844 functions (see footnote below).
12845 This will in most circumstances make the generated ISR code more efficient
12846 since it will not have to save registers on the stack.
12853 attribute will have no effect on the generated code for a
12857 function (but may occasionally be useful anyway
12863 possible exception: if a function is called ONLY from 'interrupt' functions
12864 using a particular bank, it can be declared with the same 'using' attribute
12865 as the calling 'interrupt' functions.
12866 For instance, if you have several ISRs using bank one, and all of them
12867 call memcpy(), it might make sense to create a specialized version of memcpy()
12868 'using 1', since this would prevent the ISR from having to save bank zero
12869 to the stack on entry and switch to bank zero before calling the function
12876 (pending: Note, nowadays the
12880 attribute has an effect on
12884 the generated code for a
12899 function using a non-zero bank will assume that it can trash that register
12900 bank, and will not save it.
12901 Since high-priority interrupts
12902 \begin_inset LatexCommand \index{interrupts}
12907 \begin_inset LatexCommand \index{interrupt priority}
12911 can interrupt low-priority ones on the 8051 and friends, this means that
12912 if a high-priority ISR
12916 a particular bank occurs while processing a low-priority ISR
12920 the same bank, terrible and bad things can happen.
12921 To prevent this, no single register bank should be
12925 by both a high priority and a low priority ISR.
12926 This is probably most easily done by having all high priority ISRs use
12927 one bank and all low priority ISRs use another.
12928 If you have an ISR which can change priority at runtime, you're on your
12929 own: I suggest using the default bank zero and taking the small performance
12932 \added_space_bottom bigskip
12933 It is most efficient if your ISR calls no other functions.
12934 If your ISR must call other functions, it is most efficient if those functions
12935 use the same bank as the ISR (see note 1 below); the next best is if the
12936 called functions use bank zero.
12937 It is very inefficient to call a function using a different, non-zero bank
12943 \begin_inset LatexCommand \label{sub:Startup-Code}
12948 \begin_inset LatexCommand \index{Startup code}
12955 MCS51/DS390 Startup Code
12958 The compiler inserts a call to the C routine
12960 _sdcc_external_startup()
12961 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12970 at the start of the CODE area.
12971 This routine is in the runtime library
12972 \begin_inset LatexCommand \index{Runtime library}
12977 By default this routine returns 0, if this routine returns a non-zero value,
12978 the static & global variable initialization will be skipped and the function
12979 main will be invoked.
12980 Otherwise static & global variables will be initialized before the function
12984 _sdcc_external_startup()
12986 routine to your program to override the default if you need to setup hardware
12987 or perform some other critical operation prior to static & global variable
12989 \begin_inset LatexCommand \index{Variable initialization}
12994 On some mcs51 variants xdata
12995 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12999 memory has to be explicitly enabled before it can be accessed or if the
13001 \begin_inset LatexCommand \index{watchdog}
13005 needs to be disabled, this is the place to do it.
13006 The startup code clears all internal data memory, 256 bytes by default,
13007 but from 0 to n-1 if
13020 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13027 (recommended for Chipcon CC1010).
13029 \added_space_bottom bigskip
13030 See also the compiler options
13049 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13068 \begin_inset LatexCommand \index{-\/-main-return}
13073 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13077 about MCS51-variants.
13082 \added_space_bottom bigskip
13084 \begin_inset LatexCommand \index{HC08}
13088 startup code follows the same scheme as the MCS51 startup code.
13093 \added_space_bottom bigskip
13095 \begin_inset LatexCommand \index{Z80}
13099 the startup code is inserted by linking with crt0.o which is generated from
13100 sdcc/device/lib/z80/crt0.s.
13101 If you need a different startup code you can use the compiler option
13122 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13126 and provide your own crt0.o.
13130 Inline Assembler Code
13131 \begin_inset LatexCommand \index{Assembler routines}
13138 A Step by Step Introduction
13139 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13146 Starting from a small snippet of c-code this example shows for the MCS51
13147 how to use inline assembly, access variables, a function parameter and
13148 an array in xdata memory.
13149 The example uses an MCS51 here but is easily adapted for other architectures.
13150 This is a buffer routine which should be optimized:
13156 unsigned char __far
13157 \begin_inset LatexCommand \index{far (storage class)}
13162 \begin_inset LatexCommand \index{\_\_far (storage class)}
13167 \begin_inset LatexCommand \index{at}
13172 \begin_inset LatexCommand \index{\_\_at}
13176 (0x7f00) buf[0x100];
13177 \begin_inset LatexCommand \index{Aligned array}
13183 unsigned char head, tail;\SpecialChar ~
13201 \begin_inset LatexCommand \index{interrupt}
13253 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13265 void to_buffer( unsigned char c )
13273 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13279 \begin_inset LatexCommand \index{promotion to signed int}
13284 \begin_inset LatexCommand \index{type promotion}
13289 \begin_inset Marginal
13310 buf[ head++ ] = c;\SpecialChar ~
13326 /* access to a 256 byte aligned array */
13331 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13332 then a corresponding buffer.asm file is generated.
13333 We define a new function
13337 in file buffer.c in which we cut and paste the generated code, removing
13338 unwanted comments and some ':'.
13340 \begin_inset Quotes sld
13344 \begin_inset Quotes srd
13348 \begin_inset Quotes sld
13352 \begin_inset Quotes srd
13355 to the beginning and the end of the function body:
13361 /* With a cut and paste from the .asm file, we have something to start with.
13366 The function is not yet OK! (registers aren't saved) */
13368 void to_buffer_asm( unsigned char c )
13377 \begin_inset LatexCommand \index{\_asm}
13382 \begin_inset LatexCommand \index{\_\_asm}
13396 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13402 \begin_inset LatexCommand \index{promotion to signed int}
13407 \begin_inset LatexCommand \index{type promotion}
13459 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13460 \begin_inset LatexCommand \index{Aligned array}
13525 \begin_inset LatexCommand \index{\_endasm}
13530 \begin_inset LatexCommand \index{\_\_endasm}
13539 The new file buffer.c should compile with only one warning about the unreferenced
13540 function argument 'c'.
13541 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13542 (1) and finally have:
13548 unsigned char __far __at(0x7f00) buf[0x100];
13550 unsigned char head, tail;
13552 #define USE_ASSEMBLY (1)
13560 void to_buffer( unsigned char c )
13568 if( head != (unsigned char)(tail-1) )
13588 void to_buffer( unsigned char c )
13596 c; // to avoid warning: unreferenced function argument
13603 \begin_inset LatexCommand \index{\_asm}
13608 \begin_inset LatexCommand \index{\_\_asm}
13622 ; save used registers here.
13633 ; If we were still using r2,r3 we would have to push them here.
13636 ; if( head != (unsigned char)(tail-1) )
13679 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13703 ; buf[ head++ ] = c;
13714 a,dpl \SpecialChar ~
13721 ; dpl holds lower byte of function argument
13732 dpl,_head \SpecialChar ~
13735 ; buf is 0x100 byte aligned so head can be used directly
13777 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13789 ; restore used registers here
13796 \begin_inset LatexCommand \index{\_endasm}
13801 \begin_inset LatexCommand \index{\_\_endasm}
13812 The inline assembler code can contain any valid code understood by the assembler
13813 , this includes any assembler directives and comment lines.
13814 The assembler does not like some characters like ':' or ''' in comments.
13815 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13816 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13821 \begin_inset LatexCommand \index{Assembler documentation}
13826 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13834 The compiler does not do any validation of the code within the
13837 \begin_inset LatexCommand \index{\_asm}
13842 \begin_inset LatexCommand \index{\_\_asm}
13850 \begin_inset LatexCommand \index{\_endasm}
13855 \begin_inset LatexCommand \index{\_\_endasm}
13864 Specifically it will not know which registers are used and thus register
13866 \begin_inset LatexCommand \index{push/pop}
13870 has to be done manually.
13874 It is recommended that each assembly instruction (including labels) be placed
13875 in a separate line (as the example shows).
13889 \begin_inset LatexCommand \index{-\/-peep-asm}
13895 command line option is used, the inline assembler code will be passed through
13896 the peephole optimizer
13897 \begin_inset LatexCommand \index{Peephole optimizer}
13902 There are only a few (if any) cases where this option makes sense, it might
13903 cause some unexpected changes in the inline assembler code.
13904 Please go through the peephole optimizer rules defined in file
13908 before using this option.
13912 \begin_inset LatexCommand \label{sub:Naked-Functions}
13917 \begin_inset LatexCommand \index{Naked functions}
13924 A special keyword may be associated with a function declaring it as
13927 \begin_inset LatexCommand \index{\_naked}
13932 \begin_inset LatexCommand \index{\_\_naked}
13943 function modifier attribute prevents the compiler from generating prologue
13944 \begin_inset LatexCommand \index{function prologue}
13949 \begin_inset LatexCommand \index{function epilogue}
13953 code for that function.
13954 This means that the user is entirely responsible for such things as saving
13955 any registers that may need to be preserved, selecting the proper register
13956 bank, generating the
13960 instruction at the end, etc.
13961 Practically, this means that the contents of the function must be written
13962 in inline assembler.
13963 This is particularly useful for interrupt functions, which can have a large
13964 (and often unnecessary) prologue/epilogue.
13965 For example, compare the code generated by these two functions:
13971 \begin_inset LatexCommand \index{volatile}
13975 data unsigned char counter;
13979 void simpleInterrupt(void) __interrupt
13980 \begin_inset LatexCommand \index{interrupt}
13985 \begin_inset LatexCommand \index{\_\_interrupt}
14003 void nakedInterrupt(void) __interrupt (2) __naked
14012 \begin_inset LatexCommand \index{\_asm}
14017 \begin_inset LatexCommand \index{\_\_asm}
14034 _counter ; does not change flags, no need to save psw
14046 ; MUST explicitly include ret or reti in _naked function.
14053 \begin_inset LatexCommand \index{\_endasm}
14058 \begin_inset LatexCommand \index{\_\_endasm}
14067 For an 8051 target, the generated simpleInterrupt looks like:
14076 example, recent versions of SDCC generate
14082 code for simpleInterrupt() and nakedInterrupt()!
14222 whereas nakedInterrupt looks like:
14237 _counter ; does not change flags, no need to save psw
14255 ; MUST explicitly include ret or reti in _naked function
14258 The related directive #pragma exclude
14259 \begin_inset LatexCommand \index{\#pragma exclude}
14263 allows a more fine grained control over pushing & popping
14264 \begin_inset LatexCommand \index{push/pop}
14271 While there is nothing preventing you from writing C code inside a
14275 function, there are many ways to shoot yourself in the foot doing this,
14276 and it is recommended that you stick to inline assembler.
14279 Use of Labels within Inline Assembler
14282 SDCC allows the use of in-line assembler with a few restrictions regarding
14284 In older versions of the compiler all labels defined within inline assembler
14293 where nnnn is a number less than 100 (which implies a limit of utmost 100
14294 inline assembler labels
14308 \begin_inset LatexCommand \index{\_asm}
14313 \begin_inset LatexCommand \index{\_\_asm}
14343 \begin_inset LatexCommand \index{\_endasm}
14348 \begin_inset LatexCommand \index{\_\_endasm}
14355 Inline assembler code cannot reference any C-Labels, however it can reference
14357 \begin_inset LatexCommand \index{Labels}
14361 defined by the inline assembler, e.g.:
14386 ; some assembler code
14406 /* some more c code */
14408 clabel:\SpecialChar ~
14410 /* inline assembler cannot reference this label */
14422 $0003: ;label (can be referenced by inline assembler only)
14429 \begin_inset LatexCommand \index{\_endasm}
14434 \begin_inset LatexCommand \index{\_\_endasm}
14444 /* some more c code */
14449 In other words inline assembly code can access labels defined in inline
14450 assembly within the scope of the function.
14451 The same goes the other way, i.e.
14452 labels defines in inline assembly can not be accessed by C statements.
14455 Interfacing with Assembler Code
14456 \begin_inset LatexCommand \index{Assembler routines}
14463 Global Registers used for Parameter Passing
14464 \begin_inset LatexCommand \index{Parameter passing}
14471 The compiler always uses the global registers
14474 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14479 \begin_inset LatexCommand \index{DPTR}
14484 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14493 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14499 to pass the first parameter to a routine.
14500 The second parameter onwards is either allocated on the stack (for reentrant
14511 -stack-auto is used) or in data / xdata memory (depending on the memory
14516 Assembler Routine (non-reentrant)
14519 In the following example
14520 \begin_inset LatexCommand \index{reentrant}
14525 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14529 the function c_func calls an assembler routine asm_func, which takes two
14531 \begin_inset LatexCommand \index{function parameter}
14540 extern int asm_func(unsigned char, unsigned char);
14544 int c_func (unsigned char i, unsigned char j)
14552 return asm_func(i,j);
14566 return c_func(10,9);
14571 The corresponding assembler function is:
14576 .globl _asm_func_PARM_2
14677 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14694 Note here that the return values
14695 \begin_inset LatexCommand \index{return value}
14699 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14701 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14702 b' & 'acc' for four byte values.
14705 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14706 the parameter number starting from 1, and counting from the left.
14707 The first parameter is passed in
14708 \begin_inset Quotes eld
14712 \begin_inset Quotes erd
14715 for a one byte parameter,
14716 \begin_inset Quotes eld
14720 \begin_inset Quotes erd
14724 \begin_inset Quotes eld
14728 \begin_inset Quotes erd
14731 for three bytes and
14732 \begin_inset Quotes eld
14736 \begin_inset Quotes erd
14739 for a four bytes parameter.
14740 The variable name for the second parameter will be _<function_name>_PARM_2.
14744 Assemble the assembler routine with the following command:
14751 asx8051 -losg asmfunc.asm
14758 Then compile and link the assembler routine to the C source file with the
14766 sdcc cfunc.c asmfunc.rel
14769 Assembler Routine (reentrant)
14773 \begin_inset LatexCommand \index{reentrant}
14778 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14782 the second parameter
14783 \begin_inset LatexCommand \index{function parameter}
14787 onwards will be passed on the stack, the parameters are pushed from right
14789 after the call the leftmost parameter will be on the top of the stack.
14790 Here is an example:
14795 extern int asm_func(unsigned char, unsigned char);
14799 int c_func (unsigned char i, unsigned char j) reentrant
14807 return asm_func(i,j);
14821 return c_func(10,9);
14826 The corresponding assembler routine is:
14925 \added_space_bottom bigskip
14926 The compiling and linking procedure remains the same, however note the extra
14927 entry & exit linkage required for the assembler code, _bp is the stack
14928 frame pointer and is used to compute the offset into the stack for parameters
14929 and local variables.
14933 \begin_inset LatexCommand \index{int (16 bit)}
14938 \begin_inset LatexCommand \index{long (32 bit)}
14945 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14946 multiplication and modulus operations are implemented by support routines.
14947 These support routines are all developed in ANSI-C to facilitate porting
14948 to other MCUs, although some model specific assembler optimizations are
14950 The following files contain the described routines, all of them can be
14951 found in <installdir>/share/sdcc/lib.
14957 \begin_inset Tabular
14958 <lyxtabular version="3" rows="11" columns="2">
14960 <column alignment="left" valignment="top" leftline="true" width="0">
14961 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14962 <row topline="true" bottomline="true">
14963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14984 <row topline="true">
14985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14998 16 bit multiplication
15002 <row topline="true">
15003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15016 signed 16 bit division (calls _divuint)
15020 <row topline="true">
15021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15034 unsigned 16 bit division
15038 <row topline="true">
15039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15052 signed 16 bit modulus (calls _moduint)
15056 <row topline="true">
15057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15070 unsigned 16 bit modulus
15074 <row topline="true">
15075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15088 32 bit multiplication
15092 <row topline="true">
15093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15106 signed 32 division (calls _divulong)
15110 <row topline="true">
15111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15124 unsigned 32 division
15128 <row topline="true">
15129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15142 signed 32 bit modulus (calls _modulong)
15146 <row topline="true" bottomline="true">
15147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15160 unsigned 32 bit modulus
15173 Since they are compiled as
15178 \begin_inset LatexCommand \index{reentrant}
15183 \begin_inset LatexCommand \index{interrupt}
15187 service routines should not do any of the above operations.
15188 If this is unavoidable then the above routines will need to be compiled
15202 \begin_inset LatexCommand \index{-\/-stack-auto}
15208 option, after which the source program will have to be compiled with
15221 \begin_inset LatexCommand \index{-\/-int-long-reent}
15228 Notice that you don't have to call these routines directly.
15229 The compiler will use them automatically every time an integer operation
15233 Floating Point Support
15234 \begin_inset LatexCommand \index{Floating point support}
15241 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15242 The floating point support routines are derived from gcc's floatlib.c and
15243 consist of the following routines:
15251 \begin_inset Tabular
15252 <lyxtabular version="3" rows="17" columns="2">
15254 <column alignment="left" valignment="top" leftline="true" width="0">
15255 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15256 <row topline="true" bottomline="true">
15257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15283 <row topline="true">
15284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15315 add floating point numbers
15319 <row topline="true">
15320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15351 subtract floating point numbers
15355 <row topline="true">
15356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15387 divide floating point numbers
15391 <row topline="true">
15392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15423 multiply floating point numbers
15427 <row topline="true">
15428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15459 convert floating point to unsigned char
15463 <row topline="true">
15464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15495 convert floating point to signed char
15499 <row topline="true">
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15531 convert floating point to unsigned int
15535 <row topline="true">
15536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15567 convert floating point to signed int
15571 <row topline="true">
15572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15612 convert floating point to unsigned long
15616 <row topline="true">
15617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15648 convert floating point to signed long
15652 <row topline="true">
15653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15684 convert unsigned char to floating point
15688 <row topline="true">
15689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15720 convert char to floating point number
15724 <row topline="true">
15725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15756 convert unsigned int to floating point
15760 <row topline="true">
15761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15792 convert int to floating point numbers
15796 <row topline="true">
15797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15828 convert unsigned long to floating point number
15832 <row topline="true" bottomline="true">
15833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15864 convert long to floating point number
15876 \added_space_bottom bigskip
15877 These support routines are developed in ANSI-C so there is room for space
15878 and speed improvement
15884 These floating point routines (
15888 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15893 Note if all these routines are used simultaneously the data space might
15895 For serious floating point usage the large model might be needed.
15896 Also notice that you don't have to call this routines directly.
15897 The compiler will use them automatically every time a floating point operation
15902 \begin_inset LatexCommand \index{Libraries}
15911 <pending: this is messy and incomplete - a little more information is in
15912 sdcc/doc/libdoc.txt
15917 Compiler support routines (_gptrget, _mulint etc.)
15920 Stdclib functions (puts, printf, strcat etc.)
15921 \layout Subsubsection
15927 \begin_inset LatexCommand \index{<stdio.h>}
15931 As usual on embedded systems you have to provide your own
15934 \begin_inset LatexCommand \index{getchar()}
15943 \begin_inset LatexCommand \index{putchar()}
15950 SDCC does not know whether the system connects to a serial line with or
15951 without handshake, LCD, keyboard or other device.
15965 You'll find examples for serial routines f.e.
15966 in sdcc/device/lib.
15972 \begin_inset LatexCommand \index{printf()}
15982 does not support float (except on ds390).
15983 To enable this recompile it with the option
15996 \begin_inset LatexCommand \index{USE\_FLOATS}
16002 on the command line.
16016 \begin_inset LatexCommand \index{-\/-model-large}
16022 for the mcs51 port, since this uses a lot of memory.
16025 If you're short on memory you might want to use
16028 \begin_inset LatexCommand \index{printf\_small()}
16043 For the mcs51 there additionally are assembly versions
16046 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16052 (subset of printf using less than 270 bytes) and
16055 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16064 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16070 (floating-point aware version of printf_fast) which should fit the requirements
16071 of many embedded systems (printf_fast() can be customized by unsetting
16076 support long variables and field widths).
16077 \layout Subsubsection
16080 \begin_inset LatexCommand \index{malloc.h}
16087 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16088 using dynamic memory allocation
16089 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16094 \begin_inset LatexCommand \index{heap (malloc)}
16098 space of 1024 bytes is provided for malloc to allocate memory from.
16099 If you need a different heap size you need to recompile _heap.c with the
16100 required size defined in HEAP_SIZE.
16101 It is recommended to make a copy of this file into your project directory
16102 and compile it there with:
16107 sdcc -c _heap.c -D HEAD_SIZE=2048
16111 And then link it with:
16116 sdcc main.rel _heap.rel
16121 Math functions (sinf, powf, sqrtf etc.)
16122 \layout Subsubsection
16127 See definitions in file <math.h>.
16134 \begin_inset LatexCommand \index{Libraries}
16138 included in SDCC should have a license at least as liberal as the GNU Lesser
16139 General Public License
16140 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16151 license statements for the libraries are missing.
16152 sdcc/device/lib/ser_ir.c
16156 come with a GPL (as opposed to LGPL) License - this will not be liberal
16157 enough for many embedded programmers.
16160 If you have ported some library or want to share experience about some code
16162 falls into any of these categories Busses (I
16163 \begin_inset Formula $^{\textrm{2}}$
16166 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16167 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16168 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
16169 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16174 would certainly like to hear about it.
16176 \added_space_bottom bigskip
16177 Programmers coding for embedded systems are not especially famous for being
16178 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16179 e these references are very valuable.
16180 Let's help to create a climate where information is shared.
16186 MCS51 Memory Models
16187 \begin_inset LatexCommand \index{Memory model}
16192 \begin_inset LatexCommand \index{MCS51 memory model}
16197 \layout Subsubsection
16199 Small, Medium and Large
16202 SDCC allows three memory models for MCS51 code,
16211 Modules compiled with different memory models should
16215 be combined together or the results would be unpredictable.
16216 The library routines supplied with the compiler are compiled as small,
16218 The compiled library modules are contained in separate directories as small,
16219 medium and large so that you can link to the appropriate set.
16222 When the medium or large model is used all variables declared without a
16223 storage class will be allocated into the external ram, this includes all
16224 parameters and local variables (for non-reentrant
16225 \begin_inset LatexCommand \index{reentrant}
16230 When the small model is used variables without storage class are allocated
16231 in the internal ram.
16234 Judicious usage of the processor specific storage classes
16235 \begin_inset LatexCommand \index{Storage class}
16239 and the 'reentrant' function type will yield much more efficient code,
16240 than using the large model.
16241 Several optimizations are disabled when the program is compiled using the
16242 large model, it is therefore recommended that the small model be used unless
16243 absolutely required.
16244 \layout Subsubsection
16247 \begin_inset LatexCommand \label{sub:External-Stack}
16252 \begin_inset LatexCommand \index{stack}
16257 \begin_inset LatexCommand \index{External stack (mcs51)}
16264 The external stack (-
16275 \begin_inset LatexCommand \index{-\/-xstack}
16279 ) is located in pdata
16280 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16284 memory (usually at the start of the external ram segment) and uses all
16285 unused space in pdata (max.
16297 -xstack option is used to compile the program, the parameters and local
16299 \begin_inset LatexCommand \index{local variables}
16303 of all reentrant functions are allocated in this area.
16304 This option is provided for programs with large stack space requirements.
16305 When used with the -
16316 \begin_inset LatexCommand \index{-\/-stack-auto}
16320 option, all parameters and local variables are allocated on the external
16321 stack (note: support libraries will need to be recompiled with the same
16323 There is a predefined target in the library makefile).
16326 The compiler outputs the higher order address byte of the external ram segment
16328 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16333 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16337 ), therefore when using the External Stack option, this port
16341 be used by the application program.
16345 \begin_inset LatexCommand \index{Memory model}
16350 \begin_inset LatexCommand \index{DS390 memory model}
16357 The only model supported is Flat 24
16358 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
16363 This generates code for the 24 bit contiguous addressing mode of the Dallas
16365 In this mode, up to four meg of external RAM or code space can be directly
16367 See the data sheets at www.dalsemi.com for further information on this part.
16371 Note that the compiler does not generate any code to place the processor
16372 into 24 bitmode (although
16376 in the ds390 libraries will do that for you).
16382 \begin_inset LatexCommand \index{Tinibios (DS390)}
16386 , the boot loader or similar code must ensure that the processor is in 24
16387 bit contiguous addressing mode before calling the SDCC startup code.
16405 option, variables will by default be placed into the XDATA segment.
16410 Segments may be placed anywhere in the 4 meg address space using the usual
16422 Note that if any segments are located above 64K, the -r flag must be passed
16423 to the linker to generate the proper segment relocations, and the Intel
16424 HEX output format must be used.
16425 The -r flag can be passed to the linker by using the option
16429 on the SDCC command line.
16430 However, currently the linker can not handle code segments > 64k.
16434 \begin_inset LatexCommand \label{sec:Pragmas}
16439 \begin_inset LatexCommand \index{Pragmas}
16446 SDCC supports the following #pragma directives:
16454 \begin_inset LatexCommand \index{\#pragma save}
16458 - this will save most current options to the save/restore stack.
16459 See #pragma\SpecialChar ~
16468 \begin_inset LatexCommand \index{\#pragma restore}
16472 - will restore saved options from the last save.
16473 saves & restores can be nested.
16474 SDCC uses a save/restore stack: save pushes current options to the stack,
16475 restore pulls current options from the stack.
16476 See #pragma\SpecialChar ~
16487 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16492 \begin_inset LatexCommand \index{function prologue}
16496 function1[,function2[,function3...]] - The compiler by default uses a caller
16497 saves convention for register saving across function calls, however this
16498 can cause unnecessary register pushing & popping
16499 \begin_inset LatexCommand \index{push/pop}
16503 when calling small functions from larger functions.
16504 This option can be used to switch off the register saving convention for
16505 the function names specified.
16506 The compiler will not save registers when calling these functions, extra
16507 code need to be manually inserted at the entry & exit for these functions
16508 to save & restore the registers used by these functions, this can SUBSTANTIALLY
16509 reduce code & improve run time performance of the generated code.
16510 In the future the compiler (with inter procedural analysis) may be able
16511 to determine the appropriate scheme to use for each function call.
16522 -callee-saves command line option is used, the function names specified
16523 in #pragma\SpecialChar ~
16525 \begin_inset LatexCommand \index{\#pragma callee\_saves}
16529 is appended to the list of functions specified in the command line.
16537 \begin_inset LatexCommand \index{\#pragma exclude}
16541 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
16542 of pairs of push/pop
16543 \begin_inset LatexCommand \index{push/pop}
16552 \begin_inset LatexCommand \index{interrupt}
16565 The directive should be placed immediately before the ISR function definition
16566 and it affects ALL ISR functions following it.
16567 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
16568 exclude\SpecialChar ~
16570 \begin_inset LatexCommand \index{\#pragma exclude}
16575 See also the related keyword _naked
16576 \begin_inset LatexCommand \index{\_naked}
16581 \begin_inset LatexCommand \index{\_\_naked}
16593 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
16597 - the compiler will not warn you anymore for obvious mistakes, you'r on
16606 \begin_inset LatexCommand \index{\#pragma disable\_warning}
16610 - the compiler will not warn you anymore about warning number <nnnn>.
16618 \begin_inset LatexCommand \index{\#pragma nogcse}
16622 - will stop global common subexpression elimination.
16630 \begin_inset LatexCommand \index{\#pragma noinduction}
16634 - will stop loop induction optimizations.
16642 \begin_inset LatexCommand \index{\#pragma noinvariant}
16646 - will not do loop invariant optimizations.
16647 For more details see Loop Invariants in section
16648 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
16660 \begin_inset LatexCommand \index{\#pragma noiv}
16664 - Do not generate interrupt
16665 \begin_inset LatexCommand \index{interrupt}
16670 \begin_inset LatexCommand \index{interrupt vector table}
16674 entries for all ISR functions defined after the pragma.
16675 This is useful in cases where the interrupt vector table must be defined
16676 manually, or when there is a secondary, manually defined interrupt vector
16678 for the autovector feature of the Cypress EZ-USB FX2).
16679 More elegantly this can be achieved by obmitting the optional interrupt
16680 number after the interrupt keyword, see section
16681 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
16694 \begin_inset LatexCommand \index{\#pragma nojtbound}
16698 - will not generate code for boundary value checking, when switch statements
16699 are turned into jump-tables (dangerous).
16700 For more details see section
16701 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
16713 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16717 - Will not do loop reversal optimization
16725 \begin_inset LatexCommand \index{\#pragma nooverlay}
16729 - the compiler will not overlay the parameters and local variables of a
16738 \begin_inset LatexCommand \index{\#pragma stackauto}
16753 \begin_inset LatexCommand \index{-\/-stack-auto}
16758 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16762 Parameters and Local Variables.
16770 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16774 - The compiler will optimize code generation towards fast code, possibly
16775 at the expense of code size.
16776 Currently this has little effect.
16784 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16788 - The compiler will optimize code generation towards compact code, possibly
16789 at the expense of code speed.
16790 Currently this has little effect.
16798 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16802 - The compiler will attempt to generate code that is both compact and fast,
16803 as long as meeting one goal is not a detriment to the other (this is the
16813 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16817 - Generally follow the C89 standard, but allow SDCC features that conflict
16818 with the standard (default).
16826 \begin_inset LatexCommand \index{\#pragma std\_c89}
16830 - Follow the C89 standard and disable SDCC features that conflict with the
16839 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16843 - Generally follow the C99 standard, but allow SDCC features that conflict
16844 with the standard (incomplete support).
16852 \begin_inset LatexCommand \index{\#pragma std\_c99}
16856 - Follow the C99 standard and disable SDCC features that conflict with the
16857 standard (incomplete support).
16865 \begin_inset LatexCommand \index{\#pragma codeseg}
16869 - Use this name (max.
16870 8 characters) for the code segment.
16889 \begin_inset LatexCommand \index{\#pragma constseg}
16893 - Use this name (max.
16894 8 characters) for the const segment.
16908 The preprocessor SDCPP
16909 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
16913 supports the following #pragma directives:
16921 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16925 (+ | -) - switch _asm _endasm block preprocessing on / off.
16927 You use this prama to define multilines of assembly code.
16928 This will prevent the preprocessor from changing the formating required
16930 Below is an example on how to use this pragma.
16935 #pragma preproc_asm -
16936 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16942 #define MYDELAY _asm
16947 nop ;my assembly comment...
16961 #pragma preproc_asm +
16993 pedantic_parse_number
16996 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17000 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
17001 parsed properly and the macro LO_B(3) gets expanded.
17003 Below is an example on how to use this pragma.
17006 Note: this functionality is not in conformance with standard!
17012 #pragma pedantic_parse_number +
17013 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17020 #define LO_B(x) ((x) & 0xff)
17023 unsigned char foo(void)
17028 unsigned char c=0xfe-LO_B(3);
17042 The pragma's are intended to be used to turn-on or off certain optimizations
17043 which might cause the compiler to generate extra stack / data space to
17044 store compiler generated temporary variables.
17045 This usually happens in large functions.
17046 Pragma directives should be used as shown in the following example, they
17047 are used to control options & optimizations for a given function; pragmas
17048 should be placed before and/or after a function, placing pragma's inside
17049 a function body could have unpredictable results.
17055 \begin_inset LatexCommand \index{\#pragma save}
17066 /* save the current settings */
17069 \begin_inset LatexCommand \index{\#pragma nogcse}
17078 /* turnoff global subexpression elimination */
17080 #pragma noinduction
17081 \begin_inset LatexCommand \index{\#pragma noinduction}
17085 /* turn off induction optimizations */
17108 \begin_inset LatexCommand \index{\#pragma restore}
17112 /* turn the optimizations back on */
17115 The compiler will generate a warning message when extra space is allocated.
17116 It is strongly recommended that the save and restore pragma's be used when
17117 changing options for a function.
17126 Defines Created by the Compiler
17129 The compiler creates the following #defines
17130 \begin_inset LatexCommand \index{\#defines}
17135 \begin_inset LatexCommand \index{Defines created by the compiler}
17145 \begin_inset Tabular
17146 <lyxtabular version="3" rows="11" columns="2">
17148 <column alignment="left" valignment="top" leftline="true" width="3in">
17149 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
17150 <row topline="true" bottomline="true">
17151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17172 <row topline="true">
17173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17179 \begin_inset LatexCommand \index{SDCC}
17186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17192 Since version 2.5.6 the version number as an int (ex.
17197 <row topline="true">
17198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17204 \begin_inset LatexCommand \index{SDCC\_mcs51}
17209 \begin_inset LatexCommand \index{SDCC\_ds390}
17214 \begin_inset LatexCommand \index{SDCC\_z80}
17221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17226 depending on the model used (e.g.: -mds390)
17230 <row topline="true">
17231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17237 \begin_inset LatexCommand \index{\_\_mcs51}
17242 \begin_inset LatexCommand \index{\_\_ds390}
17247 \begin_inset LatexCommand \index{\_\_hc08}
17252 \begin_inset LatexCommand \index{\_\_z80}
17259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17264 depending on the model used (e.g.
17269 <row topline="true">
17270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17276 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17306 <row topline="true">
17307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17313 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
17320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17343 <row topline="true">
17344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17350 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
17357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17380 <row topline="true">
17381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17387 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
17394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17417 <row topline="true">
17418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17424 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
17431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17454 <row topline="true">
17455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17461 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
17468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17481 <row topline="true" bottomline="true">
17482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17488 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
17495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17515 Notes on supported Processors
17519 \begin_inset LatexCommand \label{sub:MCS51-variants}
17524 \begin_inset LatexCommand \index{MCS51 variants}
17531 MCS51 processors are available from many vendors and come in many different
17533 While they might differ considerably in respect to Special Function Registers
17534 the core MCS51 is usually not modified or is kept compatible.
17538 pdata access by SFR
17541 With the upcome of devices with internal xdata and flash memory devices
17543 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17547 as dedicated I/O port is becoming more popular.
17548 Switching the high byte for pdata
17549 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17553 access which was formerly done by port P2 is then achieved by a Special
17555 \begin_inset LatexCommand \index{sfr}
17560 In well-established MCS51 tradition the address of this
17564 is where the chip designers decided to put it.
17565 Needless to say that they didn't agree on a common name either.
17566 So that the startup code can correctly initialize xdata variables, you
17567 should define an sfr with the name _XPAGE
17570 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
17576 at the appropriate location if the default, port P2, is not used for this.
17582 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
17587 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17592 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
17595 For more exotic implementations further customizations may be needed.
17597 \begin_inset LatexCommand \ref{sub:Startup-Code}
17601 for other possibilities.
17604 Other Features available by SFR
17606 \added_space_bottom bigskip
17607 Some MCS51 variants offer features like Double DPTR
17608 \begin_inset LatexCommand \index{DPTR}
17612 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17613 These are currently not used for the MCS51 port.
17614 If you absolutely need them you can fall back to inline assembly or submit
17620 \added_space_bottom bigskip
17622 \begin_inset LatexCommand \index{DS80C400}
17627 \begin_inset LatexCommand \index{DS400}
17631 microcontroller has a rich set of peripherals.
17632 In its built-in ROM library it includes functions to access some of the
17633 features, among them is a TCP stack with IP4 and IP6 support.
17634 Library headers (currently in beta status) and other files are provided
17638 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
17646 The Z80 and gbz80 port
17649 SDCC can target both the Zilog Z80
17650 \begin_inset LatexCommand \index{Z80}
17654 and the Nintendo Gameboy's Z80-like gbz80
17655 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17660 The Z80 port is passed through the same
17663 \begin_inset LatexCommand \index{Regression test}
17670 \begin_inset LatexCommand \ref{sec:Quality-control}
17674 ) as the MCS51 and DS390 ports, so floating point support, support for long
17675 variables and bitfield support is fine.
17676 See mailing lists and forums about interrupt routines.
17678 \added_space_bottom bigskip
17679 As always, the code is the authoritative reference - see z80/ralloc.c and
17682 \begin_inset LatexCommand \index{Z80!stack}
17686 frame is similar to that generated by the IAR Z80 compiler.
17687 IX is used as the base pointer, HL and IY are used as a temporary registers,
17688 and BC and DE are available for holding variables.
17690 \begin_inset LatexCommand \index{Z80!return value}
17694 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
17696 The gbz80 port use the same set of registers for the return values, but
17697 in a different order of significance: E (one byte), DE (two bytes), or
17704 The port to the Freescale/Motorola HC08
17705 \begin_inset LatexCommand \index{HC08}
17709 family has been added in October 2003, and is still undergoing some basic
17711 The code generator is complete, but the register allocation is still quite
17713 Some of the SDCC's standard C library functions have embedded non-HC08
17714 inline assembly and so are not yet usable.
17716 \added_space_bottom bigskip
17717 The HC08 port passes the regression test suite (see section
17718 \begin_inset LatexCommand \ref{sec:Quality-control}
17729 \begin_inset LatexCommand \index{PIC14}
17733 port still requires a major effort from the development community.
17734 However it can work for simple code.
17735 It passes its (smaller set of) regression tests
17736 \begin_inset LatexCommand \index{Regression test (PIC14)}
17742 sdcc/src/regression
17747 C code and 14bit PIC code page
17748 \begin_inset LatexCommand \index{code page (pic14)}
17753 \begin_inset LatexCommand \index{RAM bank (pic14)}
17760 The linker organizes allocation for the code page and RAM banks.
17761 It does not have intimate knowledge of the code flow.
17762 It will put all the code section of a single asm file into a single code
17764 In order to make use of multiple code pages, separate asm files must be
17766 The compiler treats all functions of a single C file as being in the same
17767 code page unless it is non static.
17768 The compiler treats all local variables of a single C file as being in
17769 the same RAM bank unless it is an extern.
17773 To get the best follow these guide lines:
17776 make local functions static, as non static functions require code page selection
17780 Make local variables static as extern variables require RAM bank selection
17784 For devices that have multiple code pages it is more efficient to use the
17785 same number of files as pages, i.e.
17786 for the 16F877 use 4 separate files and i.e.
17787 for the 16F874 use 2 separate files.
17788 This way the linker can put the code for each file into different code
17789 pages and the compiler can allocate reusable variables more efficiently
17790 and there's less page selection overhead.
17791 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
17792 instruction set) use 'unsigned char' whereever possible instead of 'int'.
17795 Creating a device include file
17798 For generating a device include file
17799 \begin_inset LatexCommand \index{PIC14!Header files}
17803 use the support perl script inc2h.pl kept in directory support/script.
17809 For the interrupt function, use the keyword 'interrupt'
17810 \begin_inset LatexCommand \index{PIC14!interrupt}
17814 with level number of 0 (PIC14 only has 1 interrupt so this number is only
17815 there to avoid a syntax error - it ought to be fixed).
17821 void Intr(void) interrupt 0
17827 T0IF = 0; /* Clear timer interrupt */
17832 Linking and assembling
17835 For assembling you can use either GPUTILS'
17836 \begin_inset LatexCommand \index{gputils (pic tools)}
17840 gpasm.exe or MPLAB's mpasmwin.exe.
17841 GPUTILS is available from
17842 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17847 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
17848 If you use MPLAB and an interrupt function then the linker script file
17849 vectors section will need to be enlarged to link with mplink.
17872 sdcc -S -V -mpic14 -p16F877 $<
17886 $(PRJ).hex: $(OBJS)
17896 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
17918 sdcc -S -V -mpic14 -p16F877 $<
17928 mpasmwin /q /o $*.asm
17932 $(PRJ).hex: $(OBJS)
17942 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17945 Please note that indentations within a
17949 have to be done with a tabulator character.
17952 Command-line options
17955 Besides the switches common to all SDCC backends, the PIC14 port accepts
17956 the following options (for an updated list see sdcc -
17968 \labelwidthstring 00.00.0000
17981 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
17985 emit debug info in assembly output
17987 \labelwidthstring 00.00.0000
18000 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
18004 disable (slightly faulty) optimization on pCode
18008 \layout Subsubsection
18010 error: missing definition for symbol
18011 \begin_inset Quotes sld
18015 \begin_inset Quotes srd
18021 The PIC14 port uses library routines to provide more complex operations
18022 like multiplication, division/modulus and (generic) pointer dereferencing.
18023 In order to add these routines to your project, you must link with PIC14's
18029 For single source file projects this is done automatically, more complex
18034 to the linker's arguments.
18035 Make sure you also add an include path for the library (using the -I switch
18037 \layout Subsubsection
18039 Processor mismatch in file
18040 \begin_inset Quotes sld
18044 \begin_inset Quotes srd
18050 This warning can usually be ignored due to the very good compatibility amongst
18052 \begin_inset LatexCommand \index{PIC14}
18059 You might also consider recompiling the library for your specific device
18060 by changing the ARCH=p16f877 (default target) entry in
18062 device/lib/pic/Makefile.in
18066 device/lib/pic/Makefile
18068 to reflect your device.
18069 This might even improve performance for smaller devices as unneccesary
18070 BANKSELs migth be removed.
18074 \layout Subsubsection
18079 Currently, data can only be initialized if it resides in the source file
18085 Data in other source files will silently
18093 \begin_inset Marginal
18108 \begin_inset LatexCommand \index{PIC16}
18116 \begin_inset LatexCommand \index{PIC16}
18120 port is the portion of SDCC that is responsible to produce code for the
18122 \begin_inset LatexCommand \index{Microchip}
18126 (TM) microcontrollers with 16 bit core.
18127 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
18128 Currently supported devices are:
18132 \begin_inset Tabular
18133 <lyxtabular version="3" rows="4" columns="6">
18135 <column alignment="center" valignment="top" leftline="true" width="0">
18136 <column alignment="center" valignment="top" leftline="true" width="0">
18137 <column alignment="center" valignment="top" leftline="true" width="0">
18138 <column alignment="center" valignment="top" leftline="true" width="0">
18139 <column alignment="center" valignment="top" leftline="true" width="0">
18140 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18141 <row topline="true">
18142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18191 <row topline="true">
18192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18241 <row topline="true">
18242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18291 <row topline="true" bottomline="true">
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18348 PIC16 port supports the standard command line arguments as supposed, with
18349 the exception of certain cases that will be mentioned in the following
18352 \labelwidthstring 00.00.0000
18365 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
18381 \labelwidthstring 00.00.0000
18394 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
18398 All function arguments are passed on stack by default.
18401 There is no need to specify this in the command line.
18403 \labelwidthstring 00.00.0000
18415 -fommit-frame-pointer
18416 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
18420 Frame pointer will be omitted when the function uses no local variables.
18423 Port Specific Options
18424 \begin_inset LatexCommand \index{Options PIC16}
18431 The port specific options appear after the global options in the sdcc --help
18433 \layout Subsubsection
18438 General options enable certain port features and optimizations.
18440 \labelwidthstring 00.00.0000
18452 -stack-model=[model] Used in conjuction with the command above.
18453 Defines the stack model to be used, valid stack models are :
18456 \labelwidthstring 00.00.0000
18462 Selects small stack model.
18463 8 bit stack and frame pointers.
18464 Supports 256 bytes stack size.
18466 \labelwidthstring 00.00.0000
18472 Selects large stack model.
18473 16 bit stack and frame pointers.
18474 Supports 65536 bytes stack size.
18477 \labelwidthstring 00.00.0000
18489 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
18490 unitialized data variables with [kword].
18491 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
18493 \labelwidthstring 00.00.0000
18505 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
18506 Useful for bootloaders.
18508 \labelwidthstring 00.00.0000
18520 -asm= sets the full path and name of an external assembler to call.
18522 \labelwidthstring 00.00.0000
18534 -link= sets the full path and name of an external linker to call.
18536 \labelwidthstring 00.00.0000
18549 \begin_inset LatexCommand \index{PIC16!MPLAB}
18553 compatibility option.
18554 Currently only suppresses special gpasm directives.
18555 \layout Subsubsection
18557 Optimization Options
18559 \labelwidthstring 00.00.0000
18571 -optimize-goto Try to use (conditional) BRA instead of GOTO
18573 \labelwidthstring 00.00.0000
18585 -optimize-cmp Try to optimize some compares.
18587 \labelwidthstring 00.00.0000
18599 -optimize-df Analyze the dataflow of the generated code and improve it.
18601 \labelwidthstring 00.00.0000
18613 -obanksel=nn Set optimization level for inserting BANKSELs.
18618 \labelwidthstring 00.00.0000
18622 \labelwidthstring 00.00.0000
18624 1 checks previous used register and if it is the same then does not emit
18625 BANKSEL, accounts only for labels.
18627 \labelwidthstring 00.00.0000
18629 2 tries to check the location of (even different) symbols and removes BANKSELs
18630 if they are in the same bank.
18635 Important: There might be problems if the linker script has data sections
18636 across bank borders!
18638 \layout Subsubsection
18642 \labelwidthstring 00.00.0000
18654 -nodefaultlibs do not link default libraries when linking
18656 \labelwidthstring 00.00.0000
18668 -no-crt Don't link the default run-time modules
18670 \labelwidthstring 00.00.0000
18682 -use-crt= Use a custom run-time module instead of the defaults.
18683 \layout Subsubsection
18688 Debugging options enable extra debugging information in the output files.
18690 \labelwidthstring 00.00.0000
18702 -debug-xtra Similar to -
18713 \begin_inset LatexCommand \index{-\/-debug}
18717 , but dumps more information.
18719 \labelwidthstring 00.00.0000
18731 -debug-ralloc Force register allocator to dump <source>.d file with debugging
18733 <source> is the name of the file compiled.
18735 \labelwidthstring 00.00.0000
18747 -pcode-verbose Enable pcode debugging information in translation.
18749 \labelwidthstring 00.00.0000
18761 -denable-peeps Force the usage of peepholes.
18764 \labelwidthstring 00.00.0000
18776 -gstack Trace push/pops for stack pointer overflow
18778 \labelwidthstring 00.00.0000
18790 -call-tree dump call tree in .calltree file
18793 Enviromental Variables
18796 There is a number of enviromental variables that can be used when running
18797 SDCC to enable certain optimizations or force a specific program behaviour.
18798 these variables are primarily for debugging purposes so they can be enabled/dis
18802 Currently there is only two such variables available:
18804 \labelwidthstring 00.00.0000
18806 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
18807 bitfields is optimized by directly loading FSR0 with the address of the
18808 bitfield structure.
18809 Normally SDCC will cast the bitfield structure to a bitfield pointer and
18811 This step saves data ram and code space for functions that perform heavy
18814 80 bytes of code space are saved when compiling malloc.c with this option).
18817 \labelwidthstring 00.00.0000
18819 NO_REG_OPT do not perform pCode registers optimization.
18820 This should be used for debugging purposes.
18821 In some where bugs in the pcode optimizer are found, users can benefit
18822 from temporarily disabling the optimizer until the bug is fixed.
18825 Preprocessor Macros
18829 \begin_inset LatexCommand \index{PIC16}
18833 port defines the following preprocessor macros while translating a source.
18837 \begin_inset Tabular
18838 <lyxtabular version="3" rows="6" columns="2">
18840 <column alignment="center" valignment="top" leftline="true" width="0">
18841 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18842 <row topline="true" bottomline="true">
18843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18860 <row topline="true">
18861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18874 Port identification
18878 <row topline="true">
18879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18902 Port identification (same as above)
18906 <row topline="true">
18907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18920 MCU Identification.
18925 is the microcontrol identification number, i.e.
18930 <row topline="true">
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18954 MCU Identification (same as above)
18958 <row topline="true" bottomline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18972 nnn = SMALL or LARGE respectively according to the stack model used
18983 In addition the following macros are defined when calling assembler:
18987 \begin_inset Tabular
18988 <lyxtabular version="3" rows="4" columns="2">
18990 <column alignment="center" valignment="top" leftline="true" width="0">
18991 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18992 <row topline="true" bottomline="true">
18993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19010 <row topline="true">
19011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19024 MCU Identification.
19029 is the microcontrol identification number, i.e.
19034 <row topline="true">
19035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19048 nnn = SMALL or LARGE respectively according to the memory model used for
19053 <row topline="true" bottomline="true">
19054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19067 nnn = SMALL or LARGE respectively according to the stack model used
19082 \begin_inset LatexCommand \index{PIC16}
19086 port uses the following directories for searching header files and libraries.
19090 \begin_inset Tabular
19091 <lyxtabular version="3" rows="3" columns="4">
19093 <column alignment="center" valignment="top" leftline="true" width="0">
19094 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19095 <column alignment="center" valignment="top" width="0">
19096 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19097 <row topline="true" bottomline="true">
19098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19131 <row topline="true">
19132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19137 PREFIX/sdcc/include/pic16
19140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19145 PIC16 specific headers
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19165 <row topline="true" bottomline="true">
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19171 PREFIX/sdcc/lib/pic16
19174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19179 PIC16 specific libraries
19182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19207 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
19215 \begin_inset LatexCommand \index{PIC16}
19219 port currently supports the following pragmas:
19221 \labelwidthstring 00.00.0000
19224 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
19229 \begin_inset LatexCommand \index{PIC16!stack}
19233 forces the code generator to initialize the stack & frame pointers at a
19235 This is an adhoc solution for cases where no STACK directive is available
19236 in the linker script or gplink is not instructed to create a stack section.
19238 The stack pragma should be used only once in a project.
19239 Multiple pragmas may result in indeterminate behaviour of the program.
19245 The old format (ie.
19246 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
19247 cross page boundaries (or even exceed the available data RAM) and crash
19249 Make sure that stack does not cross page boundaries when using the SMALL
19255 The format is as follows:
19258 #pragma stack bottom_address [stack_size]
19265 is the lower bound of the stack section.
19266 The stack pointer initially will point at address (bottom_address+stack_size-1).
19274 /* initializes stack of 100 bytes at RAM address 0x200 */
19277 #pragma stack 0x200 100
19280 If the stack_size field is omitted then a stack is created with the default
19282 This size might be enough for most programs, but its not enough for operations
19283 with deep function nesting or excessive stack usage.
19285 \labelwidthstring 00.00.0000
19288 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
19292 place a function symbol at static FLASH address
19300 /* place function test_func at 0x4000 */
19303 #pragma code test_func 0x4000
19307 \labelwidthstring 00.00.0000
19309 library instructs the linker to use a library module.
19314 #pragma library module_name
19321 can be any library or object file (including its path).
19322 Note that there are four reserved keywords which have special meaning.
19327 \begin_inset Tabular
19328 <lyxtabular version="3" rows="6" columns="3">
19330 <column alignment="center" valignment="top" leftline="true" width="0">
19331 <column alignment="block" valignment="top" leftline="true" width="20page%">
19332 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19333 <row topline="true" bottomline="true">
19334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19359 <row topline="true">
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19375 ignore all library pragmas
19378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19389 <row topline="true">
19390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19421 <row topline="true">
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19437 link the Math libarary
19440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19453 <row topline="true">
19454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19469 link the I/O library
19472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19485 <row topline="true" bottomline="true">
19486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19501 link the debug library
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19523 * is the device number, i.e.
19524 452 for PIC18F452 MCU.
19527 This feature allows for linking with specific libraries withoug having to
19528 explicit name them in the command line.
19533 keyword will reject all modules specified by the library pragma.
19535 \labelwidthstring 00.00.0000
19537 udata pragma udata instructs the compiler to emit code so that linker will
19538 place a variable at a specific memory bank
19546 /* places variable foo at bank2 */
19549 #pragma udata bank2 foo
19555 In order for this pragma to work extra SECTION directives should be added
19556 in the .lkr script.
19557 In the following example a sample .lkr file is shown:
19562 // Sample linker script for the PIC18F452 processor
19568 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
19571 CODEPAGE NAME=page START=0x2A END=0x7FFF
19574 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
19577 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
19580 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
19583 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
19586 ACCESSBANK NAME=accessram START=0x0 END=0x7F
19591 DATABANK NAME=gpr0 START=0x80 END=0xFF
19594 DATABANK NAME=gpr1 START=0x100 END=0x1FF
19597 DATABANK NAME=gpr2 START=0x200 END=0x2FF
19600 DATABANK NAME=gpr3 START=0x300 END=0x3FF
19603 DATABANK NAME=gpr4 START=0x400 END=0x4FF
19606 DATABANK NAME=gpr5 START=0x500 END=0x5FF
19609 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
19614 SECTION NAME=CONFIG ROM=config
19619 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
19622 SECTION NAME=bank1 RAM=gpr1 # should be added to link
19625 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
19628 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
19631 SECTION NAME=bank4 RAM=gpr4
19634 SECTION NAME=bank5 RAM=gpr5
19637 The linker will recognise the section name set in the pragma statement and
19638 will position the variable at the memory bank set with the RAM field at
19639 the SECTION line in the linker script file.
19643 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
19650 There is one main header file
19651 \begin_inset LatexCommand \index{PIC16!Header files}
19655 that can be included to the source files using the pic16
19656 \begin_inset LatexCommand \index{PIC16}
19666 This header file contains the definitions for the processor special registers,
19667 so it is necessary if the source accesses them.
19668 It can be included by adding the following line in the beginning of the
19672 #include <pic18fregs.h>
19675 The specific microcontroller is selected within the pic18fregs.h automatically,
19676 so the same source can be used with a variety of devices.
19683 \begin_inset LatexCommand \index{PIC16!Libraries}
19688 \begin_inset LatexCommand \index{PIC16}
19692 port depends on are the microcontroller device libraries which contain
19693 the symbol definitions for the microcontroller special function registers.
19694 These libraries have the format pic18fxxxx.lib, where
19698 is the microcontroller identification number.
19699 The specific library is selected automatically by the compiler at link
19700 stage according to the selected device.
19703 Libraries are created with gplib which is part of the gputils package
19704 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19709 \layout Subsubsection*
19711 Building the libraries
19714 Before using SDCC/pic16 there are some libraries that need to be compiled.
19715 This process is not done automatically by SDCC since not all users use
19716 SDCC for pic16 projects.
19717 So each user should compile the libraries separately.
19720 The steps to compile the pic16 libraries under Linux are:
19723 cd device/lib/pic16
19738 su -c 'make install' # install the libraries, you need the root password
19741 If you need to install the headers too, do:
19747 su -c 'make install' # install the headers, you need the root password
19750 There exist a special target to build the I/O libraries.
19751 This target is not automatically build because it will build the I/O library
19757 This way building will take quite a lot of time.
19758 Users are advised to edit the
19760 device/lib/pic16/pics.build
19762 file and then execute:
19771 The following memory models are supported by the PIC16 port:
19780 Memory model affects the default size of pointers within the source.
19781 The sizes are shown in the next table:
19785 \begin_inset Tabular
19786 <lyxtabular version="3" rows="3" columns="3">
19788 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19789 <column alignment="center" valignment="top" leftline="true" width="0">
19790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19791 <row topline="true" bottomline="true">
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19797 Pointer sizes according to memory model
19800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19817 <row topline="true" bottomline="true">
19818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19826 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19843 <row topline="true" bottomline="true">
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19852 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
19860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19876 It is advisable that all sources within a project are compiled with the
19878 If one wants to override the default memory model, this can be done by
19879 declaring a pointer as
19888 Far selects large memory model's pointers, while near selects small memory
19892 The standard device libraries (see
19893 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
19897 ) contain no reference to pointers, so they can be used with both memory
19905 \begin_inset LatexCommand \index{PIC16!stack}
19909 implementation for the PIC16 port uses two indirect registers, FSR1 and
19912 \labelwidthstring 00.00.0000
19914 FSR1 is assigned as stack pointer
19916 \labelwidthstring 00.00.0000
19918 FSR2 is assigned as frame pointer
19921 The following stack models are supported by the PIC16 port
19942 model means that only the FSRxL byte is used to access stack and frame,
19949 uses both FSRxL and FSRxH registers.
19950 The following table shows the stack/frame pointers sizes according to stack
19951 model and the maximum space they can address:
19955 \begin_inset Tabular
19956 <lyxtabular version="3" rows="3" columns="3">
19958 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19959 <column alignment="center" valignment="top" leftline="true" width="0">
19960 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19961 <row topline="true" bottomline="true">
19962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19967 Stack & Frame pointer sizes according to stack model
19970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 <row topline="true">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20013 <row topline="true" bottomline="true">
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20050 stack model is currently not working properly throughout the code generator.
20051 So its use is not advised.
20052 Also there are some other points that need special care:
20057 Do not create stack sections with size more than one physical bank (that
20061 Stack sections should no cross physical bank limits (i.e.
20062 #pragma stack 0x50 0x100)
20065 These limitations are caused by the fact that only FSRxL is modified when
20066 using SMALL stack model, so no more than 256 bytes of stack can be used.
20067 This problem will disappear after LARGE model is fully implemented.
20073 In addition to the standard SDCC function keywords, PIC16
20074 \begin_inset LatexCommand \index{PIC16}
20078 port makes available two more:
20080 \labelwidthstring 00.00.0000
20083 \begin_inset LatexCommand \index{PIC16!wparam}
20087 Use the WREG to pass one byte of the first function argument.
20088 This improves speed but you may not use this for functions with arguments
20089 that are called via function pointers, otherwise the first byte of the
20090 first parameter will get lost.
20094 void func_wparam(int a) wparam
20100 /* WREG hold the lower part of a */
20103 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
20112 \labelwidthstring 00.00.0000
20115 \begin_inset LatexCommand \index{PIC16!shadowregs}
20119 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
20120 hardware shadow registers which hold the values of WREG, STATUS and BSR
20122 This can be done by adding the keyword
20130 keyword in the function's header.
20133 void isr_shadow(void) shadowregs interrupt 1
20149 instructs the code generator not to store/restore WREG, STATUS, BSR when
20150 entering/exiting the ISR.
20153 Function return values
20156 Return values from functions are placed to the appropriate registers following
20157 a modified Microchip policy optimized for SDCC.
20158 The following table shows these registers:
20162 \begin_inset Tabular
20163 <lyxtabular version="3" rows="6" columns="2">
20165 <column alignment="center" valignment="top" leftline="true" width="0">
20166 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20167 <row topline="true" bottomline="true">
20168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20181 destination register
20185 <row topline="true">
20186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20203 <row topline="true">
20204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20221 <row topline="true">
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20239 <row topline="true">
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20253 FSR0L:PRODH:PRODL:WREG
20257 <row topline="true" bottomline="true">
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20271 on stack, FSR0 points to the beginning
20286 \begin_inset LatexCommand \index{PIC16!interrupt}
20290 service routine (ISR) is declared using the
20297 void isr(void) interrupt
20315 is the interrupt number, which for PIC18F devices can be:
20319 \begin_inset Tabular
20320 <lyxtabular version="3" rows="4" columns="3">
20322 <column alignment="center" valignment="top" leftline="true" width="0">
20323 <column alignment="center" valignment="top" leftline="true" width="0">
20324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20325 <row topline="true" bottomline="true">
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20349 Interrupt Vector Address
20353 <row topline="true">
20354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20379 <row topline="true">
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 HIGH priority interrupts
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20423 <row topline="true" bottomline="true">
20424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20437 LOW priority interrupts
20440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20456 When generating assembly code for ISR the code generator places a
20462 Interrupt Vector Address
20464 which points at the genetated ISR.
20465 This single GOTO instruction is part of an automatically generated
20467 interrupt entry point
20470 The actuall ISR code is placed as normally would in the code space.
20471 Upon interrupt request, the GOTO instruction is executed which jumps to
20473 When declaring interrupt functions as _naked this GOTO instruction is
20478 The whole interrupt functions is therefore placed at the Interrupt Vector
20479 Address of the specific interrupt.
20480 This is not a problem for the LOW priority interrupts, but it is a problem
20481 for the RESET and the HIGH priority interrupts because code may be written
20482 at the next interrupt´s vector address and cause undeterminate program
20483 behaviour if that interrupt is raised.
20489 This is not a problem when
20492 this is a HIGH interrupt ISR and LOW interrupts are
20499 when the ISR is small enough not to reach the next interrupt´s vector address.
20509 is possible to be omitted.
20510 This way a function is generated similar to an ISR, but it is not assigned
20514 When entering an interrupt, currently the PIC16
20515 \begin_inset LatexCommand \index{PIC16}
20519 port automatically saves the following registers:
20531 PROD (PRODL and PRODH)
20534 FSR0 (FSR0L and FSR0H)
20537 These registers are restored upon return from the interrupt routine.
20543 NOTE that when the _naked attribute is specified for an interrupt routine,
20544 then NO registers are stored or restored.
20553 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
20554 There are 3 types of generic pointers currently implemented data, code
20555 and eeprom pointers.
20556 They are differentiated by the value of the 7th and 6th bits of the upper
20561 \begin_inset Tabular
20562 <lyxtabular version="3" rows="5" columns="5">
20564 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20565 <column alignment="center" valignment="top" width="0">
20566 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20567 <column alignment="center" valignment="top" width="0">
20568 <column alignment="left" valignment="top" rightline="true" width="0">
20569 <row topline="true" bottomline="true">
20570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20599 rest of the pointer
20602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 <row topline="true" bottomline="true">
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20645 uuuuuu uuuuxxxx xxxxxxxx
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20653 a 12-bit data pointer in data RAM memory
20657 <row bottomline="true">
20658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20691 uxxxxx xxxxxxxx xxxxxxxx
20694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20699 a 21-bit code pointer in FLASH memory
20703 <row bottomline="true">
20704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20737 uuuuuu uuuuuuxx xxxxxxxx
20740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20745 a 10-bit eeprom pointer in EEPROM memory
20749 <row bottomline="true">
20750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20783 xxxxxx xxxxxxxx xxxxxxxx
20786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20791 unimplemented pointer type
20802 Generic pointer are read and written with a set of library functions which
20803 read/write 1, 2, 3, 4 bytes.
20807 \layout Subsubsection
20809 Standard I/O Streams
20816 the type FILE is defined as:
20819 typedef char * FILE;
20822 This type is the stream type implemented I/O in the PIC18F devices.
20823 Also the standard input and output streams are declared in stdio.h:
20826 extern FILE * stdin;
20829 extern FILE * stdout;
20832 The FILE type is actually a generic pointer which defines one more type
20833 of generic pointers, the
20838 This new type has the format:
20842 \begin_inset Tabular
20843 <lyxtabular version="3" rows="2" columns="7">
20845 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20846 <column alignment="center" valignment="top" width="0">
20847 <column alignment="center" valignment="top" leftline="true" width="0">
20848 <column alignment="center" valignment="top" leftline="true" width="0">
20849 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20850 <column alignment="center" valignment="top" width="0">
20851 <column alignment="left" valignment="top" rightline="true" width="0">
20852 <row topline="true" bottomline="true">
20853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20898 rest of the pointer
20901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20910 <row topline="true" bottomline="true">
20911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20968 upper byte high nubble is 0x2n, the rest are zeroes
20979 Currently implemented there are 3 types of streams defined:
20983 \begin_inset Tabular
20984 <lyxtabular version="3" rows="4" columns="4">
20986 <column alignment="center" valignment="top" leftline="true" width="0">
20987 <column alignment="center" valignment="top" leftline="true" width="0">
20988 <column alignment="center" valignment="top" leftline="true" width="0">
20989 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20990 <row topline="true" bottomline="true">
20991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21024 <row topline="true">
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21056 Writes/Reads characters via the USART peripheral
21060 <row topline="true">
21061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21092 Writes/Reads characters via the MSSP peripheral
21096 <row topline="true" bottomline="true">
21097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21128 Writes/Reads characters via used defined functions
21139 The stream identifiers are declared as macros in the stdio.h header.
21142 In the libc library there exist the functions that are used to write to
21143 each of the above streams.
21146 \labelwidthstring 00.00.0000
21158 _stream_usart_putchar writes a character at the USART stream
21160 \labelwidthstring 00.00.0000
21172 _stream_mssp_putchar writes a character at the MSSP stream
21174 \labelwidthstring 00.00.0000
21176 putchar dummy function.
21177 This writes a character to a user specified manner.
21180 In order to increase performance
21184 is declared in stdio.h as having its parameter in WREG (it has the wparam
21186 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
21187 in a user-friendly way.
21192 is the name of the variable that holds the character to print.
21193 An example follows:
21196 #include <pic18fregs.h>
21208 PORTA = c; /* dump character c to PORTA */
21221 stdout = STREAM_USER; /* this is not necessary, since stdout points
21224 * by default to STREAM_USER */
21227 printf (¨This is a printf test
21235 \layout Subsubsection
21240 PIC16 contains an implementation of the printf-family of functions.
21241 There exist the following functions:
21244 extern unsigned int sprintf(char *buf, char *fmt, ...);
21247 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
21252 extern unsigned int printf(char *fmt, ...);
21255 extern unsigned int vprintf(char *fmt, va_lista ap);
21260 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
21263 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
21266 For sprintf and vsprintf
21270 should normally be a data pointer where the resulting string will be placed.
21271 No range checking is done so the user should allocate the necessery buffer.
21272 For fprintf and vfprintf
21276 should be a stream pointer (i.e.
21277 stdout, STREAM_MSSP, etc...).
21278 \layout Subsubsection
21283 The PIC18F family of microcontrollers supports a number of interrupt sources.
21284 A list of these interrupts is shown in the following table:
21288 \begin_inset Tabular
21289 <lyxtabular version="3" rows="11" columns="4">
21291 <column alignment="left" valignment="top" leftline="true" width="0">
21292 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21293 <column alignment="left" valignment="top" leftline="true" width="0">
21294 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21295 <row topline="true" bottomline="true">
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21329 <row topline="true">
21330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21338 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21343 PORTB change interrupt
21346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21359 EEPROM/FLASH write complete interrupt
21363 <row topline="true">
21364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21377 INT0 external interrupt
21380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21393 Bus collision interrupt
21397 <row topline="true">
21398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21411 INT1 external interrupt
21414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21427 Low voltage detect interrupt
21431 <row topline="true">
21432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21445 INT2 external interrupt
21448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21461 Parallel slave port interrupt
21465 <row topline="true">
21466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21479 CCP1 module interrupt
21482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21495 AD convertion complete interrupt
21499 <row topline="true">
21500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21513 CCP2 module interrupt
21516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21529 USART receive interrupt
21533 <row topline="true">
21534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21547 TMR0 overflow interrupt
21550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21563 USART transmit interrupt
21567 <row topline="true">
21568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21581 TMR1 overflow interrupt
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21597 SSP receive/transmit interrupt
21601 <row topline="true">
21602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21615 TMR2 matches PR2 interrupt
21618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21633 <row topline="true" bottomline="true">
21634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21647 TMR3 overflow interrupt
21650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21672 The prototypes for these names are defined in the header file
21679 In order to simplify signal handling, a number of macros is provided:
21681 \labelwidthstring 00.00.0000
21683 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
21684 high priority interrupts.
21689 is the function name to use.
21691 \labelwidthstring 00.00.0000
21693 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
21694 low priority interrupt.
21699 is the function name to use.
21701 \labelwidthstring 00.00.0000
21703 DEF_HANDLER(sig,handler) define a handler for signal
21707 \labelwidthstring 00.00.0000
21709 END_DEF end the declaration of the dispatch table.
21712 Additionally there are two more macros to simplify the declaration of the
21715 \labelwidthstring 00.00.0000
21719 SIGHANDLER(handler)
21721 this declares the function prototype for the
21727 \labelwidthstring 00.00.0000
21729 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
21732 An example of using the macros above is shown below:
21735 #include <pic18fregs.h>
21738 #include <signal.h>
21742 DEF_INTHIGH(high_int)
21745 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
21748 DEF_HANDLER(SIG_BCOL, _bcol_handler)
21755 SIGHANDLER(_tmr0_handler)
21761 /* action to be taken when timer 0 overflows */
21768 SIGHANDLERNAKED(_bcol_handler)
21777 /* action to be taken when bus collision occurs */
21793 Special care should be taken when using the above scheme:
21796 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
21799 when declaring SIGHANDLERNAKED handler never forget to use
21803 for proper returning.
21809 Here you can find some general tips for compiling programs with SDCC/pic16.
21810 \layout Subsubsection
21816 \begin_inset LatexCommand \index{PIC16!stack}
21820 size (that is 64 bytes) probably is enough for many programs.
21821 One must take care that when there are many levels of function nesting,
21822 or there is excessive usage of stack, its size should be extended.
21823 An example of such a case is the printf/sprintf family of functions.
21824 If you encounter problems like not being able to print integers, then you
21825 need to set the stack size around the maximum (256 for small stack model).
21826 The following diagram shows what happens when calling printf to print an
21830 printf () --> ltoa () --> ultoa () --> divschar ()
21833 It is should be understood that stack is easily consumed when calling complicate
21835 Using command line arguments like -
21845 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
21847 Other ways to reduce stack usage may exist.
21853 The PIC16 Port currently does not pass SDCC's regression test
21854 \begin_inset LatexCommand \index{Regression test (PIC16)}
21859 \begin_inset LatexCommand \ref{sec:Quality-control}
21863 ) and thus the nightly regression tests for the PIC16 target are currently
21864 disabled for all hosts except for
21869 This means you can see the result of the PIC16 regression tests f.e.
21870 by checking the log files in
21871 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
21875 (pick the most up to date file there, scroll down, lend a hand).
21881 There are several approaches to debugging your code.
21882 This chapter is meant to show your options and to give detail on some of
21887 When writing your code:
21890 write your code with debugging in mind (avoid duplicating code, put conceptually
21891 similar variables into structs, use structured code, have strategic points
21892 within your code where all variables are consistent, ...)
21895 run a syntax-checking tool like splint
21896 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21901 \begin_inset LatexCommand \index{lint (syntax checking tool)}
21916 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21923 for the high level code use a C-compiler (like f.e.
21924 GCC) to compile run and debug the code on your host.
21936 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
21940 ) on howto handle syntax extensions like __xdata, __at(), ...
21944 use another C-compiler to compile code for your target.
21945 Always an option but not recommended:) And not very likely to help you.
21946 If you seriously consider walking this path you should at least occasionally
21947 check portability of your code.
21948 Most commercial compiler vendors will offer an evaluation version so you
21949 can test compile your code or snippets of your code.
21952 Debugging on a simulator:
21955 there is a separate section about SDCDB (section
21956 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
21963 or (8051 specific) use a freeware/commercial simulator which interfaces
21965 \begin_inset LatexCommand \index{AOMF, AOMF51}
21970 \begin_inset LatexCommand \ref{OMF file}
21974 ) optionally generated by SDCC.
21977 Debugging On-target:
21980 use a MCU port pin to serially output debug data to the RS232 port of your
21982 You'll probably want some level shifting device typically involving a MAX232
21984 If the hardware serial port of the MCU is not available search for 'Software
21985 UART' in your favourite search machine.
21988 use an on-target monitor.
21989 In this context a monitor is a small program which usually accepts commands
21990 via a serial line and allows to set program counter, to single step through
21991 a program and read/write memory locations.
21992 For the 8051 good examples of monitors are paulmon and cmon51 (see section
21994 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
22001 toggle MCU port pins at strategic points within your code and use an oscilloscop
22005 digital oscilloscope
22008 \begin_inset LatexCommand \index{Oscilloscope}
22012 with deep trace memory is really helpful especially if you have to debug
22013 a realtime application.
22014 If you need to monitor more pins than your oscilloscope provides you can
22015 sometimes get away with a small R-2R network.
22016 On a single channel oscilloscope you could f.e.
22017 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22019 \begin_inset Formula $\Omega$
22022 resistor and the other one by a 5\SpecialChar ~
22024 \begin_inset Formula $\Omega$
22027 resistor to the oscilloscope probe (check output drive capability of the
22028 pins you want to monitor).
22029 If you need to monitor many more pins a
22049 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22054 Usually very expensive.
22055 And very nice to have too.
22056 And usually locks you (for years...) to the devices the ICE can emulate.
22060 use a remote debugger.
22061 In most 8-bit systems the symbol information is not available on the target,
22062 and a complete debugger is too bulky for the target system.
22063 Therefore usually a debugger on the host system connects to an on-target
22064 debugging stub which accepts only primitive commands.
22067 Terms to enter into your favourite search engine could be 'remote debugging',
22068 'gdb stub' or 'inferior debugger'.
22072 use an on target hardware debugger.
22073 Some of the more modern MCUs include hardware support for setting break
22074 points and monitoring/changing variables by using dedicated hardware pins.
22075 This facility doesn't require additional code to run on the target and
22080 doesn't affect runtime behaviour until a breakpoint is hit.
22081 For the mcs51 most hardware debuggers use the AOMF
22082 \begin_inset LatexCommand \index{AOMF, AOMF51}
22087 \begin_inset LatexCommand \ref{OMF file}
22098 if you are not familiar with any of the following terms you're likely to
22099 run into problems rather sooner than later:
22116 As an embedded programmer you
22120 to know them so why not look them up
22124 you have problems?)
22127 tell someone else about your problem (actually this is a surprisingly effective
22128 means to hunt down the bug even if the listener is not familiar with your
22130 As 'failure to communicate' is probably one of the job-induced deformations
22131 of an embedded programmer this is highly encouraged.
22134 Debugging with SDCDB
22135 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
22140 \begin_inset LatexCommand \index{SDCDB (debugger)}
22147 SDCC is distributed with a source level debugger
22148 \begin_inset LatexCommand \index{Debugger}
22153 The debugger uses a command line interface, the command repertoire of the
22154 debugger has been kept as close to gdb
22155 \begin_inset LatexCommand \index{gdb}
22159 (the GNU debugger) as possible.
22160 The configuration and build process is part of the standard compiler installati
22161 on, which also builds and installs the debugger in the target directory
22162 specified during configuration.
22163 The debugger allows you debug BOTH at the C source and at the ASM source
22167 Compiling for Debugging
22181 \begin_inset LatexCommand \index{-\/-debug}
22185 option must be specified for all files for which debug information is to
22187 The compiler generates a .adb file for each of these files.
22188 The linker creates the .cdb
22189 \begin_inset LatexCommand \index{<file>.cdb}
22194 \begin_inset LatexCommand \index{<file>.adb}
22198 files and the address information.
22199 This .cdb is used by the debugger.
22202 How the Debugger Works
22215 -debug option is specified the compiler generates extra symbol information
22216 some of which are put into the assembler source and some are put into the
22218 Then the linker creates the .cdb file from the individual .adb files with
22219 the address information for the symbols.
22220 The debugger reads the symbolic information generated by the compiler &
22221 the address information generated by the linker.
22222 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
22223 execution is controlled by the debugger.
22224 When a command is issued for the debugger, it translates it into appropriate
22225 commands for the simulator.
22226 (Currently SDCDM only connects to the simulator but
22231 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
22235 is an effort to connect directly to the hardware.)
22238 Starting the Debugger SDCDB
22241 The debugger can be started using the following command line.
22242 (Assume the file you are debugging has the file name foo).
22256 The debugger will look for the following files.
22259 foo.c - the source file.
22262 foo.cdb - the debugger symbol information file.
22265 foo.ihx - the Intel hex format
22266 \begin_inset LatexCommand \index{Intel hex format}
22273 SDCDB Command Line Options
22286 -directory=<source file directory> this option can used to specify the directory
22288 The debugger will look into the directory list specified for source, cdb
22290 The items in the directory list must be separated by ':', e.g.
22291 if the source files can be in the directories /home/src1 and /home/src2,
22302 -directory option should be -
22312 -directory=/home/src1:/home/src2.
22313 Note there can be no spaces in the option.
22317 -cd <directory> - change to the <directory>.
22320 -fullname - used by GUI front ends.
22323 -cpu <cpu-type> - this argument is passed to the simulator please see the
22324 simulator docs for details.
22327 -X <Clock frequency > this options is passed to the simulator please see
22328 the simulator docs for details.
22331 -s <serial port file> passed to simulator see the simulator docs for details.
22334 -S <serial in,out> passed to simulator see the simulator docs for details.
22337 -k <port number> passed to simulator see the simulator docs for details.
22340 SDCDB Debugger Commands
22343 As mentioned earlier the command interface for the debugger has been deliberatel
22344 y kept as close the GNU debugger gdb, as possible.
22345 This will help the integration with existing graphical user interfaces
22346 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
22347 If you use a graphical user interface for the debugger you can skip this
22349 \layout Subsubsection*
22351 break [line | file:line | function | file:function]
22354 Set breakpoint at specified line or function:
22363 sdcdb>break foo.c:100
22365 sdcdb>break funcfoo
22367 sdcdb>break foo.c:funcfoo
22368 \layout Subsubsection*
22370 clear [line | file:line | function | file:function ]
22373 Clear breakpoint at specified line or function:
22382 sdcdb>clear foo.c:100
22384 sdcdb>clear funcfoo
22386 sdcdb>clear foo.c:funcfoo
22387 \layout Subsubsection*
22392 Continue program being debugged, after breakpoint.
22393 \layout Subsubsection*
22398 Execute till the end of the current function.
22399 \layout Subsubsection*
22404 Delete breakpoint number 'n'.
22405 If used without any option clear ALL user defined break points.
22406 \layout Subsubsection*
22408 info [break | stack | frame | registers ]
22411 info break - list all breakpoints
22414 info stack - show the function call stack.
22417 info frame - show information about the current execution frame.
22420 info registers - show content of all registers.
22421 \layout Subsubsection*
22426 Step program until it reaches a different source line.
22427 Note: pressing <return> repeats the last command.
22428 \layout Subsubsection*
22433 Step program, proceeding through subroutine calls.
22434 \layout Subsubsection*
22439 Start debugged program.
22440 \layout Subsubsection*
22445 Print type information of the variable.
22446 \layout Subsubsection*
22451 print value of variable.
22452 \layout Subsubsection*
22457 load the given file name.
22458 Note this is an alternate method of loading file for debugging.
22459 \layout Subsubsection*
22464 print information about current frame.
22465 \layout Subsubsection*
22470 Toggle between C source & assembly source.
22471 \layout Subsubsection*
22473 ! simulator command
22476 Send the string following '!' to the simulator, the simulator response is
22478 Note the debugger does not interpret the command being sent to the simulator,
22479 so if a command like 'go' is sent the debugger can loose its execution
22480 context and may display incorrect values.
22481 \layout Subsubsection*
22488 My name is Bobby Brown"
22491 Interfacing SDCDB with DDD
22494 The screenshot was converted from png to eps with:
22495 \begin_inset Quotes sld
22498 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
22499 \begin_inset Quotes srd
22502 which produces a pretty compact eps file which is free from compression
22506 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
22507 as this broke the build system on Sourceforge (pdf-file was broken.
22508 pdflatex does not accept eps files).
22526 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
22532 shows a screenshot of a debugging session with DDD
22533 \begin_inset LatexCommand \index{DDD (debugger)}
22537 (Unix only) on a simulated 8032.
22538 The debugging session might not run as smoothly as the screenshot suggests.
22539 The debugger allows setting of breakpoints, displaying and changing variables,
22540 single stepping through C and assembler code.
22543 The source was compiled with
22566 -debug ddd_example.c
22579 and DDD was invoked with
22586 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
22589 Interfacing SDCDB with XEmacs
22590 \begin_inset LatexCommand \index{XEmacs}
22595 \begin_inset LatexCommand \index{Emacs}
22602 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
22603 sdcdb.el and sdcdbsrc.el.
22604 These two files can be found in the $(prefix)/bin directory after the installat
22606 These files need to be loaded into XEmacs for the interface to work.
22607 This can be done at XEmacs startup time by inserting the following into
22608 your '.xemacs' file (which can be found in your HOME directory):
22614 (load-file sdcdbsrc.el)
22620 .xemacs is a lisp file so the () around the command is REQUIRED.
22621 The files can also be loaded dynamically while XEmacs is running, set the
22622 environment variable 'EMACSLOADPATH' to the installation bin directory
22623 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
22624 To start the interface enter the following command:
22638 You will prompted to enter the file name to be debugged.
22643 The command line options that are passed to the simulator directly are bound
22644 to default values in the file sdcdbsrc.el.
22645 The variables are listed below, these values maybe changed as required.
22648 sdcdbsrc-cpu-type '51
22651 sdcdbsrc-frequency '11059200
22654 sdcdbsrc-serial nil
22657 The following is a list of key mapping for the debugger interface.
22668 ;;key\SpecialChar ~
22682 binding\SpecialChar ~
22706 ;;---\SpecialChar ~
22720 -------\SpecialChar ~
22762 sdcdb-next-from-src\SpecialChar ~
22790 sdcdb-back-from-src\SpecialChar ~
22818 sdcdb-cont-from-src\SpecialChar ~
22828 SDCDB continue command
22846 sdcdb-step-from-src\SpecialChar ~
22874 sdcdb-whatis-c-sexp\SpecialChar ~
22884 SDCDB ptypecommand for data at
22951 sdcdbsrc-delete\SpecialChar ~
22965 SDCDB Delete all breakpoints if no arg
23014 given or delete arg (C-u arg x)
23032 sdcdbsrc-frame\SpecialChar ~
23047 SDCDB Display current frame if no arg,
23096 given or display frame arg
23163 sdcdbsrc-goto-sdcdb\SpecialChar ~
23173 Goto the SDCDB output buffer
23191 sdcdb-print-c-sexp\SpecialChar ~
23202 SDCDB print command for data at
23269 sdcdbsrc-goto-sdcdb\SpecialChar ~
23279 Goto the SDCDB output buffer
23297 sdcdbsrc-mode\SpecialChar ~
23313 Toggles Sdcdbsrc mode (turns it off)
23328 sdcdb-finish-from-src\SpecialChar ~
23336 SDCDB finish command
23351 sdcdb-break\SpecialChar ~
23369 Set break for line with point
23384 sdcdbsrc-mode\SpecialChar ~
23400 Toggle Sdcdbsrc mode
23415 sdcdbsrc-srcmode\SpecialChar ~
23438 Here are a few guidelines that will help the compiler generate more efficient
23439 code, some of the tips are specific to this compiler others are generally
23440 good programming practice.
23443 Use the smallest data type to represent your data-value.
23444 If it is known in advance that the value is going to be less than 256 then
23445 use an 'unsigned char' instead of a 'short' or 'int'.
23446 Please note, that ANSI C requires both signed and unsigned chars to be
23447 promoted to 'signed int'
23448 \begin_inset LatexCommand \index{promotion to signed int}
23453 \begin_inset Marginal
23464 before doing any operation.
23466 \begin_inset LatexCommand \index{type promotion}
23471 \begin_inset LatexCommand \label{type promotion}
23475 can be omitted, if the result is the same.
23476 The effect of the promotion rules together with the sign-extension is often
23483 unsigned char uc = 0xfe;
23485 if (uc * uc < 0) /* this is true! */
23504 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
23514 (unsigned char) -12 / (signed char) -3 = ...
23517 No, the result is not 4:
23522 (int) (unsigned char) -12 / (int) (signed char) -3 =
23524 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
23526 (int) 0x00f4 / (int) 0xfffd =
23528 (int) 0x00f4 / (int) 0xfffd =
23530 (int) 244 / (int) -3 =
23532 (int) -81 = (int) 0xffaf;
23535 Don't complain, that gcc gives you a different result.
23536 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
23537 Therefore the results are different.
23540 \begin_inset Quotes sld
23544 \begin_inset Quotes srd
23552 If well-defined overflow characteristics are important and negative values
23553 are not, or if you want to steer clear of sign-extension problems when
23554 manipulating bits or bytes, use one of the corresponding unsigned types.
23555 (Beware when mixing signed and unsigned values in expressions, though.)
23557 Although character types (especially unsigned char) can be used as "tiny"
23558 integers, doing so is sometimes more trouble than it's worth, due to unpredicta
23559 ble sign extension and increased code size.
23563 Use unsigned when it is known in advance that the value is not going to
23565 This helps especially if you are doing division or multiplication, bit-shifting
23566 or are using an array index.
23569 NEVER jump into a LOOP.
23572 Declare the variables to be local
23573 \begin_inset LatexCommand \index{local variables}
23577 whenever possible, especially loop control variables (induction).
23580 Since the compiler does not always do implicit integral promotion, the programme
23581 r should do an explicit cast when integral promotion is required.
23584 Reducing the size of division, multiplication & modulus operations can reduce
23585 code size substantially.
23586 Take the following code for example.
23592 foobar(unsigned int p1, unsigned char ch)
23600 unsigned char ch1 = p1 % ch ;
23611 For the modulus operation the variable ch will be promoted to unsigned int
23612 first then the modulus operation will be performed (this will lead to a
23613 call to support routine _moduint()), and the result will be casted to a
23615 If the code is changed to
23620 foobar(unsigned int p1, unsigned char ch)
23628 unsigned char ch1 = (unsigned char)p1 % ch ;
23639 It would substantially reduce the code generated (future versions of the
23640 compiler will be smart enough to detect such optimization opportunities).
23644 Have a look at the assembly listing to get a
23645 \begin_inset Quotes sld
23649 \begin_inset Quotes srd
23652 for the code generation.
23655 Porting code from or to other compilers
23656 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
23663 check whether endianness of the compilers differs and adapt where needed.
23666 check the device specific header files
23667 \begin_inset LatexCommand \index{Header files}
23672 \begin_inset LatexCommand \index{Include files}
23676 for compiler specific syntax.
23677 Eventually include the file <compiler.h
23678 \begin_inset LatexCommand \index{compiler.h (include file)}
23683 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
23687 to allow using common header files.
23690 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
23697 check whether the startup code contains the correct initialization (watchdog,
23701 check whether the sizes of short, int, long match.
23704 check if some 16 or 32 bit hardware registers require a specific addressing
23705 order (least significant or most significant byte first) and adapt if needed
23714 relate to time and not to lower/upper memory location here, so this is
23719 the same as endianness).
23722 check whether the keyword
23726 is used where needed.
23727 The compilers might differ in their optimization characteristics (as different
23728 versions of the same compiler might also use more clever optimizations
23729 this is good idea anyway).
23731 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
23738 check that the compilers are not told to supress warnings.
23741 check and convert compiler specific extensions (interrupts, memory areas,
23745 check for differences in type promotion.
23746 Especially check for math operations on
23755 For the sake of C99 compatibility SDCC will probably promote these to
23759 more often than other compilers.
23760 Eventually insert explicit casts to
23769 Also check that the ~\SpecialChar ~
23771 \begin_inset LatexCommand \index{\~\/ Operator}
23778 \begin_inset LatexCommand \index{bit}
23784 variables, use the !\SpecialChar ~
23787 \begin_inset LatexCommand \ref{type promotion}
23792 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23799 check the assembly code generated for interrupt routines (f.e.
23800 for calls to possibly non-reentrant library functions).
23803 check whether timing loops result in proper timing (or preferably consider
23804 a rewrite of the code with timer based delays instead).
23807 check for differences in printf parameters (some compilers push (va_arg
23808 \begin_inset LatexCommand \index{vararg, va\_arg}
23812 ) char variables as
23816 others push them as
23822 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
23829 check the resulting memory map
23830 \begin_inset LatexCommand \index{Memory map}
23835 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
23836 ly idata, pdata, xdata).
23837 Eventually check if unexpected library functions are included.
23841 \begin_inset LatexCommand \index{Tools}
23845 included in the distribution
23849 \begin_inset Tabular
23850 <lyxtabular version="3" rows="12" columns="3">
23852 <column alignment="left" valignment="top" leftline="true" width="0pt">
23853 <column alignment="left" valignment="top" leftline="true" width="0pt">
23854 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23855 <row topline="true" bottomline="true">
23856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23881 <row topline="true">
23882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23895 Simulator for various architectures
23898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23907 <row topline="true">
23908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23922 \begin_inset LatexCommand \index{Header files}
23927 \begin_inset LatexCommand \index{Include files}
23934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23939 sdcc/support/scripts
23943 <row topline="true">
23944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23957 header file conversion
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23965 sdcc/support/scripts
23969 <row topline="true">
23970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24004 <row topline="true">
24005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24039 <row topline="true">
24040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24074 <row topline="true">
24075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24109 <row topline="true">
24110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24144 <row topline="true">
24145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24179 <row topline="true">
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24214 <row topline="true" bottomline="true">
24215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24229 \begin_inset LatexCommand \index{packihx (tool)}
24236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24264 \begin_inset LatexCommand \index{Documentation}
24268 included in the distribution
24272 \begin_inset Tabular
24273 <lyxtabular version="3" rows="10" columns="2">
24275 <column alignment="left" valignment="top" leftline="true" width="0">
24276 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24277 <row topline="true" bottomline="true">
24278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24291 Where to get / filename
24295 <row topline="true">
24296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24301 SDCC Compiler User Guide
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24309 You're reading it right now
24313 <row topline="true">
24314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24338 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
24343 \begin_inset LatexCommand \index{Assembler documentation}
24347 Assemblers and ASLINK
24348 \begin_inset LatexCommand \index{aslink}
24353 \begin_inset LatexCommand \index{Linker documentation}
24360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24365 sdcc/as/doc/asxhtm.html
24369 <row topline="true">
24370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24375 SDCC regression test
24376 \begin_inset LatexCommand \index{Regression test}
24383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24388 sdcc/doc/test_suite_spec.pdf
24392 <row topline="true">
24393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24410 <row topline="true">
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24416 Notes on debugging with SDCDB
24417 \begin_inset LatexCommand \index{SDCDB (debugger)}
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24429 sdcc/debugger/README
24433 <row topline="true">
24434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24439 Software simulator for microcontrollers
24442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24469 <row topline="true">
24470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24475 Temporary notes on the pic16
24476 \begin_inset LatexCommand \index{PIC16}
24483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24488 sdcc/src/pic16/NOTES
24492 <row topline="true" bottomline="true">
24493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24498 SDCC internal documentation (debugging file format)
24501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24537 Related open source tools
24538 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
24543 \begin_inset LatexCommand \index{Related tools}
24551 \begin_inset Tabular
24552 <lyxtabular version="3" rows="14" columns="3">
24554 <column alignment="left" valignment="top" leftline="true" width="0pt">
24555 <column alignment="block" valignment="top" leftline="true" width="30line%">
24556 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24557 <row topline="true" bottomline="true">
24558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24583 <row topline="true">
24584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24590 \begin_inset LatexCommand \index{gpsim (pic simulator)}
24597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24611 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
24619 <row topline="true">
24620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24626 \begin_inset LatexCommand \index{gputils (pic tools)}
24633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24647 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24655 <row topline="true">
24656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24678 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
24686 <row topline="true">
24687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24700 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
24704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24710 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
24718 <row topline="true">
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24725 \begin_inset LatexCommand \index{indent (source formatting tool)}
24732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24737 Formats C source - Master of the white spaces
24740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24746 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
24754 <row topline="true">
24755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24761 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
24768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24773 Object file conversion, checksumming, ...
24776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
24790 <row topline="true">
24791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24797 \begin_inset LatexCommand \index{objdump (tool)}
24804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24809 Object file conversion, ...
24812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24817 Part of binutils (should be there anyway)
24821 <row topline="true">
24822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24835 8051 monitor (hex up-/download, single step, disassemble)
24838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24844 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
24852 <row topline="true">
24853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24859 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
24866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24871 Source code documentation system
24874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24880 \begin_inset LatexCommand \url{http://www.doxygen.org}
24888 <row topline="true">
24889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24902 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
24905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24911 \begin_inset LatexCommand \url{http://www.kdevelop.org}
24919 <row topline="true">
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24933 8051 monitor (hex up-/download, single step, disassemble)
24936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24942 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
24950 <row topline="true">
24951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24957 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24969 Statically checks c sources (see
24970 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24983 \begin_inset LatexCommand \url{http://www.splint.org}
24991 <row topline="true" bottomline="true">
24992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24998 \begin_inset LatexCommand \index{DDD (debugger)}
25005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25010 Debugger, serves nicely as GUI to SDCDB
25011 \begin_inset LatexCommand \index{SDCDB (debugger)}
25018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25024 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
25041 Related documentation / recommended reading
25045 \begin_inset Tabular
25046 <lyxtabular version="3" rows="7" columns="3">
25048 <column alignment="left" valignment="top" leftline="true" width="0pt">
25049 <column alignment="center" valignment="top" leftline="true" width="0">
25050 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25051 <row topline="true" bottomline="true">
25052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25077 <row topline="true">
25078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25101 \begin_inset LatexCommand \index{C Reference card}
25108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25114 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
25122 <row topline="true">
25123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25137 \begin_inset LatexCommand \index{C FAQ}
25144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25150 \begin_inset LatexCommand \url{http://www.c-faq.com}
25158 <row topline="true">
25159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25173 \begin_inset Quotes sld
25177 \begin_inset Quotes srd
25183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25191 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
25199 <row topline="true">
25200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25214 \begin_inset Quotes sld
25217 Extensions for Embedded C
25218 \begin_inset Quotes srd
25224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25232 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
25240 <row topline="true">
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25253 Latest datasheet of target CPU
25256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25265 <row topline="true" bottomline="true">
25266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25278 Revision history of datasheet
25281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25299 Application notes specifically for SDCC
25302 SDCC makes no claims about the completeness of this list and about up-to-datenes
25303 s or correctness of the application notes
25304 \begin_inset LatexCommand \index{Application notes}
25314 \begin_inset Tabular
25315 <lyxtabular version="3" rows="7" columns="3">
25317 <column alignment="block" valignment="top" leftline="true" width="17col%">
25318 <column alignment="block" valignment="top" leftline="true" width="27col%">
25319 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
25320 <row topline="true" bottomline="true">
25321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25331 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25352 <row topline="true">
25353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25370 Using the SDCC Compiler for the DS80C400
25371 \begin_inset LatexCommand \index{DS80C400}
25378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25386 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
25394 <row topline="true">
25395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25405 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
25412 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
25413 \begin_inset LatexCommand \index{DS89C4x0}
25417 Family of Microcontrollers
25420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25428 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
25436 <row topline="true">
25437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25444 Silicon Laboratories / Cygnal
25447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25454 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
25455 \begin_inset LatexCommand \index{IDE}
25462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25470 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
25478 <row topline="true">
25479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25486 Ramtron / Goal Semiconductor
25489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25496 Interfacing SDCC to Syn and Textpad
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25507 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25515 <row topline="true">
25516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25523 Ramtron / Goal Semiconductor
25526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25533 Installing and Configuring SDCC and Crimson Editor
25536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25544 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
25552 <row topline="true" bottomline="true">
25553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25570 MSC12xx Programming with SDCC
25573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25581 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
25599 Some questions answered, some pointers given - it might be time to in turn
25607 can you solve your project with the selected microcontroller? Would you
25608 find out early or rather late that your target is too small/slow/whatever?
25609 Can you switch to a slightly better device if it doesn't fit?
25612 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
25613 and/or another programming language be more adequate? Would an operating
25614 system on the target device help?
25617 if you solved the problem, will the marketing department be happy?
25620 if the marketing department is happy, will customers be happy?
25623 if you're the project manager, marketing department and maybe even the customer
25624 in one person, have you tried to see the project from the outside?
25627 is the project done if you think it is done? Or is just that other interface/pro
25628 tocol/feature/configuration/option missing? How about website, manual(s),
25629 internationali(z|s)ation, packaging, labels, 2nd source for components,
25630 electromagnetic compatability/interference, documentation for production,
25631 production test software, update mechanism, patent issues?
25634 is your project adequately positioned in that magic triangle: fame, fortune,
25638 Maybe not all answers to these questions are known and some answers may
25643 , nevertheless knowing these questions may help you to avoid burnout
25649 burnout is bad for electronic devices, programmers and motorcycle tyres
25653 Chances are you didn't want to hear some of them...
25657 \begin_inset LatexCommand \index{Support}
25664 SDCC has grown to be a large project.
25665 The compiler alone (without the preprocessor, assembler and linker) is
25666 well over 150,000 lines of code (blank stripped).
25667 The open source nature of this project is a key to its continued growth
25669 You gain the benefit and support of many active software developers and
25671 Is SDCC perfect? No, that's why we need your help.
25672 The developers take pride in fixing reported bugs.
25673 You can help by reporting the bugs and helping other SDCC users.
25674 There are lots of ways to contribute, and we encourage you to take part
25675 in making SDCC a great software package.
25679 The SDCC project is hosted on the SDCC sourceforge site at
25680 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
25685 You'll find the complete set of mailing lists
25686 \begin_inset LatexCommand \index{Mailing list(s)}
25690 , forums, bug reporting system, patch submission
25691 \begin_inset LatexCommand \index{Patch submission}
25696 \begin_inset LatexCommand \index{download}
25700 area and Subversion code repository
25701 \begin_inset LatexCommand \index{Subversion code repository}
25709 \begin_inset LatexCommand \index{Bug reporting}
25714 \begin_inset LatexCommand \index{Reporting bugs}
25721 The recommended way of reporting bugs is using the infrastructure of the
25723 You can follow the status of bug reports there and have an overview about
25727 Bug reports are automatically forwarded to the developer mailing list and
25728 will be fixed ASAP.
25729 When reporting a bug, it is very useful to include a small test program
25730 (the smaller the better) which reproduces the problem.
25731 If you can isolate the problem by looking at the generated assembly code,
25732 this can be very helpful.
25733 Compiling your program with the -
25744 \begin_inset LatexCommand \index{-\/-dumpall}
25748 option can sometimes be useful in locating optimization problems.
25749 When reporting a bug please make sure you:
25752 Attach the code you are compiling with SDCC.
25756 Specify the exact command you use to run SDCC, or attach your Makefile.
25760 Specify the SDCC version (type "
25766 "), your platform, and operating system.
25770 Provide an exact copy of any error message or incorrect output.
25774 Put something meaningful in the subject of your message.
25777 Please attempt to include these 5 important parts, as applicable, in all
25778 requests for support or when reporting any problems or bugs with SDCC.
25779 Though this will make your message lengthy, it will greatly improve your
25780 chance that SDCC users and developers will be able to help you.
25781 Some SDCC developers are frustrated by bug reports without code provided
25782 that they can use to reproduce and ultimately fix the problem, so please
25783 be sure to provide sample code if you are reporting a bug!
25786 Please have a short check that you are using a recent version of SDCC and
25787 the bug is not yet known.
25788 This is the link for reporting bugs:
25789 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
25794 With SDCC on average having more than 200 downloads
25795 \begin_inset LatexCommand \index{download}
25799 on sourceforge per day
25805 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
25806 between 2002 and 2005.
25807 This does not include other methods of distribution.
25810 there must be some users.
25811 So it's not exactly easy to find a new bug.
25812 If you find one we need it:
25814 reporting bugs is good
25819 Requesting Features
25820 \begin_inset LatexCommand \label{sub:Requesting-Features}
25825 \begin_inset LatexCommand \index{Feature request}
25830 \begin_inset LatexCommand \index{Requesting features}
25837 Like bug reports feature requests are forwarded to the developer mailing
25839 This is the link for requesting features:
25840 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
25850 Like bug reports contributed patches are forwarded to the developer mailing
25852 This is the link for submitting patches
25853 \begin_inset LatexCommand \index{Patch submission}
25858 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
25865 You need to specify some parameters to the
25869 command for the patches to be useful.
25870 If you modified more than one file a patch created f.e.
25875 \begin_inset Quotes sld
25878 diff -Naur unmodified_directory modified_directory >my_changes.patch
25879 \begin_inset Quotes srd
25885 will be fine, otherwise
25889 \begin_inset Quotes sld
25892 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
25893 \begin_inset Quotes srd
25906 These links should take you directly to the
25907 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
25917 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
25918 automated messages (mid 2003)
25922 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
25927 \begin_inset LatexCommand \index{Mailing list(s)}
25931 and forums are archived and searchable so if you are lucky someone already
25932 had a similar problem.
25933 While mails to the lists themselves are delivered promptly their web front
25934 end on sourceforge sometimes shows a severe time lag (up to several weeks),
25935 if you're seriously using SDCC please consider subscribing to the lists.
25941 You can follow the status of the Subversion version
25942 \begin_inset LatexCommand \index{version}
25946 of SDCC by watching the Changelog
25947 \begin_inset LatexCommand \index{Changelog}
25951 in the Subversion repository
25954 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25961 Subversion Source Code Repository
25970 or the filenames of the snapshot versions of SDCC include date and its
25972 \begin_inset LatexCommand \index{Subversion code repository}
25977 Subversion allows to download the source of recent or previous versions
25979 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
25983 (by number or by date).
25984 An on-line source code browser and detailled instructions are also available
25986 SDCC versions starting from 1999 up to now are available (currently the
25987 versions prior to the conversion from cvs
25988 \begin_inset LatexCommand \index{cvs|see{Subversion}}
25992 to Subversion (April 2006) are either by accessible by Subversion or by
25997 \begin_inset LatexCommand \index{Release policy}
26004 Historically there often were long delays between official releases and
26005 the sourceforge download area tends to get not updated at all.
26006 Excuses in the past might have referred to problems with live range analysis,
26007 but as this was fixed a while ago, the current problem is that another
26008 excuse has to be found.
26009 Kidding aside, we have to get better there! On the other hand there are
26010 daily snapshots available at
26011 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
26015 , and you can always build the very last version (hopefully with many bugs
26016 fixed, and features added) from the source code available at
26017 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
26023 \begin_inset LatexCommand \index{wiki}
26028 \begin_inset LatexCommand \index{Release wiki}
26033 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
26037 also holds some information about past and future releases.
26041 \begin_inset LatexCommand \index{Examples}
26048 You'll find some small examples in the directory
26050 sdcc/device/examples/.
26053 More examples and libraries are available at
26055 The SDCC Open Knowledge Resource
26056 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
26063 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
26070 I did insert a reference to Paul's web site here although it seems rather
26071 dedicated to a specific 8032 board (I think it's okay because it f.e.
26072 shows LCD/Harddisc interface and has a free 8051 monitor.
26073 Independent 8032 board vendors face hard competition of heavily subsidized
26074 development boards anyway).
26077 Maybe we should include some links to real world applications.
26078 Preferably pointer to pointers (one for each architecture) so this stays
26083 \begin_inset LatexCommand \label{sec:Quality-control}
26088 \begin_inset LatexCommand \index{Quality control}
26095 The compiler is passed through nightly compile and build checks.
26101 \begin_inset LatexCommand \index{Regression test}
26105 check that SDCC itself compiles flawlessly on several host platforms (i386,
26106 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
26107 the quality of the code generated by SDCC by running the code for several
26108 target platforms through simulators.
26109 The regression test suite comprises more than 100 files which expand to
26110 more than 500 test cases which include more than 4500 tests.
26111 The results of these tests are published daily on SDCC's snapshot page
26112 (click on the red or green symbols on the right side of
26113 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
26120 There is a separate document
26123 \begin_inset LatexCommand \index{Test suite}
26130 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26134 about the regression test suite.
26137 You'll find the test code in the directory
26139 sdcc/support/regression
26142 You can run these tests manually by running
26146 in this directory (or f.e.
26151 \begin_inset Quotes sld
26155 \begin_inset Quotes srd
26161 if you don't want to run the complete tests).
26162 The test code might also be interesting if you want to look for examples
26163 \begin_inset LatexCommand \index{Examples}
26167 checking corner cases of SDCC or if you plan to submit patches
26168 \begin_inset LatexCommand \index{Patch submission}
26175 The 14bit pic port uses a different set of regression tests
26176 \begin_inset LatexCommand \index{Regression test (PIC14)}
26180 , you'll find them in the directory
26182 sdcc/src/regression
26187 Use of SDCC in Education
26200 the phrase "use in education" might evoke the association "
26204 fit for use in education".
26205 This connotation is not intended but nevertheless risked as the licensing
26206 of SDCC makes it difficult to offer educational discounts
26210 If your rationales are to:
26213 give students a chance to understand the
26217 steps of code generation
26220 have a curriculum that can be extended for years.
26221 Then you could use an fpga board as target and your curriculum will seamlessly
26222 extend from logic synthesis (
26223 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
26228 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
26232 ), over assembly programming, to C to FPGA compilers (
26233 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
26240 be able to insert excursions about skills like using a revision control
26241 system, submitting/applying patches, using a type-setting (as opposed to
26242 word-processing) engine LyX/LaTeX, using
26243 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
26248 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
26252 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
26253 Source Software, CPU simulation, compiler regression tests
26254 \begin_inset LatexCommand \index{Regression test}
26261 And if there should be a shortage of ideas then you can always point students
26262 to the ever-growing feature request list
26263 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26270 not tie students to a specific host platform and instead allow them to use
26275 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
26277 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
26284 not encourage students to use illegal copies of educational software
26287 be immune to licensing/availability/price changes of the chosen tool chain
26290 be able to change to a new target platform without having to adopt a new
26294 have complete control over and insight into the tool chain
26297 make your students aware about the pros and cons of open source software
26301 give back to the public as you are probably at least partially publically
26305 give students a chance to publically prove their skills and to possibly
26306 see a world wide impact
26309 then SDCC is probably among the first choices.
26310 Well, probably SDCC might be the only choice.
26313 SDCC Technical Data
26317 \begin_inset LatexCommand \index{Optimizations}
26324 SDCC performs a host of standard optimizations in addition to some MCU specific
26329 Sub-expression Elimination
26330 \begin_inset LatexCommand \index{Subexpression elimination}
26337 The compiler does local and
26363 will be translated to
26375 Some subexpressions are not as obvious as the above example, e.g.:
26385 In this case the address arithmetic a->b[i] will be computed only once;
26386 the equivalent code in C would be.
26398 The compiler will try to keep these temporary variables in registers.
26401 Dead-Code Elimination
26402 \begin_inset LatexCommand \index{Dead-code elimination}
26423 i = 1; \SpecialChar ~
26432 global = 1;\SpecialChar ~
26445 global = 3;\SpecialChar ~
26470 \begin_inset LatexCommand \index{Copy propagation}
26526 Note: the dead stores created by this copy propagation will be eliminated
26527 by dead-code elimination.
26531 \begin_inset LatexCommand \index{Loop optimization}
26536 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
26543 Two types of loop optimizations are done by SDCC
26551 of loop induction variables.
26552 In addition to the strength reduction the optimizer marks the induction
26553 variables and the register allocator tries to keep the induction variables
26554 in registers for the duration of the loop.
26555 Because of this preference of the register allocator
26556 \begin_inset LatexCommand \index{Register allocation}
26560 , loop induction optimization causes an increase in register pressure, which
26561 may cause unwanted spilling of other temporary variables into the stack
26562 \begin_inset LatexCommand \index{stack}
26567 The compiler will generate a warning message when it is forced to allocate
26568 extra space either on the stack or data space.
26569 If this extra space allocation is undesirable then induction optimization
26570 can be eliminated either for the entire source file (with -
26580 -noinduction option) or for a given function only using #pragma\SpecialChar ~
26582 \begin_inset LatexCommand \index{\#pragma noinduction}
26595 for (i = 0 ; i < 100 ; i ++)
26611 for (i = 0; i < 100; i++)
26620 As mentioned previously some loop invariants are not as apparent, all static
26621 address computations are also moved out of the loop.
26626 \begin_inset LatexCommand \index{Strength reduction}
26630 , this optimization substitutes an expression by a cheaper expression:
26635 for (i=0;i < 100; i++)
26653 for (i=0;i< 100;i++) {
26659 ar[itemp1] = itemp2;
26676 The more expensive multiplication
26677 \begin_inset LatexCommand \index{Multiplication}
26681 is changed to a less expensive addition.
26685 \begin_inset LatexCommand \index{Loop reversing}
26692 This optimization is done to reduce the overhead of checking loop boundaries
26693 for every iteration.
26694 Some simple loops can be reversed and implemented using a
26695 \begin_inset Quotes eld
26698 decrement and jump if not zero
26699 \begin_inset Quotes erd
26703 SDCC checks for the following criterion to determine if a loop is reversible
26704 (note: more sophisticated compilers use data-dependency analysis to make
26705 this determination, SDCC uses a more simple minded analysis).
26708 The 'for' loop is of the form
26714 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
26724 The <for body> does not contain
26725 \begin_inset Quotes eld
26729 \begin_inset Quotes erd
26733 \begin_inset Quotes erd
26739 All goto's are contained within the loop.
26742 No function calls within the loop.
26745 The loop control variable <sym> is not assigned any value within the loop
26748 The loop control variable does NOT participate in any arithmetic operation
26752 There are NO switch statements in the loop.
26755 Algebraic Simplifications
26758 SDCC does numerous algebraic simplifications, the following is a small sub-set
26759 of these optimizations.
26764 i = j + 0;\SpecialChar ~
26768 /* changed to: */\SpecialChar ~
26774 i /= 2;\SpecialChar ~
26781 /* changed to: */\SpecialChar ~
26787 i = j - j;\SpecialChar ~
26791 /* changed to: */\SpecialChar ~
26797 i = j / 1;\SpecialChar ~
26801 /* changed to: */\SpecialChar ~
26808 Note the subexpressions
26809 \begin_inset LatexCommand \index{Subexpression}
26813 given above are generally introduced by macro expansions or as a result
26814 of copy/constant propagation.
26817 'switch' Statements
26818 \begin_inset LatexCommand \label{sub:'switch'-Statements}
26823 \begin_inset LatexCommand \index{switch statement}
26830 SDCC can optimize switch statements to jump tables
26831 \begin_inset LatexCommand \index{jump tables}
26836 It makes the decision based on an estimate of the generated code size.
26837 SDCC is quite liberal in the requirements for jump table generation:
26840 The labels need not be in order, and the starting number need not be one
26841 or zero, the case labels are in numerical sequence or not too many case
26842 labels are missing.
26848 switch(i) {\SpecialChar ~
26879 case 4: ...\SpecialChar ~
26911 case 5: ...\SpecialChar ~
26943 case 3: ...\SpecialChar ~
26974 case 6: ...\SpecialChar ~
27006 case 7: ...\SpecialChar ~
27038 case 8: ...\SpecialChar ~
27070 case 9: ...\SpecialChar ~
27102 case 10: ...\SpecialChar ~
27133 case 11: ...\SpecialChar ~
27200 Both the above switch statements will be implemented using a jump-table.
27201 The example to the right side is slightly more efficient as the check for
27202 the lower boundary of the jump-table is not needed.
27206 The number of case labels is not larger than supported by the target architectur
27210 If the case labels are not in numerical sequence ('gaps' between cases)
27211 SDCC checks whether a jump table with additionally inserted dummy cases
27212 is still attractive.
27216 If the starting number is not zero and a check for the lower boundary of
27217 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
27222 Switch statements which have large gaps in the numeric sequence or those
27223 that have too many case labels can be split into more than one switch statement
27224 for efficient code generation, e.g.:
27304 If the above switch statement is broken down into two switch statements
27394 then both the switch statements will be implemented using jump-tables whereas
27395 the unmodified switch statement will not be.
27398 There might be reasons which SDCC cannot know about to either favour or
27399 not favour jump tables.
27400 If the target system has to be as quick for the last switch case as for
27401 the first (pro jump table), or if the switch argument is known to be zero
27402 in the majority of the cases (contra jump table).
27405 The pragma nojtbound
27406 \begin_inset LatexCommand \index{\#pragma nojtbound}
27410 can be used to turn off checking the
27423 It has no effect if a default label is supplied.
27424 Use of this pragma is dangerous: if the switch
27425 \begin_inset LatexCommand \index{switch statement}
27429 argument is not matched by a case statement the processor will happily
27433 Bit-shifting Operations
27434 \begin_inset LatexCommand \index{Bit shifting}
27441 Bit shifting is one of the most frequently used operation in embedded programmin
27443 SDCC tries to implement bit-shift operations in the most efficient way
27459 generates the following code:
27476 In general SDCC will never setup a loop if the shift count is known.
27519 \begin_inset LatexCommand \index{Bit rotation}
27526 A special case of the bit-shift operation is bit rotation
27527 \begin_inset LatexCommand \index{rotating bits}
27531 , SDCC recognizes the following expression to be a left bit-rotation:
27541 char i;\SpecialChar ~
27552 /* unsigned is needed for rotation */
27557 i = ((i << 1) | (i >> 7));
27566 will generate the following code:
27585 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
27586 ns of this case will also be recognized as bit-rotation, i.e.:
27591 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
27594 Nibble and Byte Swapping
27597 Other special cases of the bit-shift operations are nibble or byte swapping
27598 \begin_inset LatexCommand \index{swapping nibbles/bytes}
27602 , SDCC recognizes the following expressions:
27625 i = ((i << 4) | (i >> 4));
27631 j = ((j << 8) | (j >> 8));
27634 and generates a swap instruction for the nibble swapping
27635 \begin_inset LatexCommand \index{Nibble swapping}
27639 or move instructions for the byte swapping
27640 \begin_inset LatexCommand \index{Byte swapping}
27646 \begin_inset Quotes sld
27650 \begin_inset Quotes srd
27653 example can be used to convert from little to big-endian or vice versa.
27654 If you want to change the endianness of a
27658 integer you have to cast to
27665 Note that SDCC stores numbers in little-endian
27671 Usually 8-bit processors don't care much about endianness.
27672 This is not the case for the standard 8051 which only has an instruction
27678 \begin_inset LatexCommand \index{DPTR}
27686 so little-endian is the more efficient byte order.
27690 \begin_inset LatexCommand \index{little-endian}
27695 \begin_inset LatexCommand \index{Endianness}
27700 lowest order first).
27704 \begin_inset LatexCommand \index{Highest Order Bit}
27709 \begin_inset LatexCommand \index{Any Order Bit}
27716 It is frequently required to obtain the highest order bit of an integral
27717 type (long, int, short or char types).
27718 Also obtaining any other order bit is not uncommon.
27719 SDCC recognizes the following expressions to yield the highest order bit
27720 and generates optimized code for it, e.g.:
27733 unsigned char hob1, aob1;
27737 bit hob2, hob3, aob2, aob3;
27746 hob1 = (gint >> 15) & 1;
27750 hob2 = (gint >> 15) & 1;
27754 hob3 = gint & 0x8000;
27758 aob1 = (gint >> 9) & 1;
27762 aob2 = (gint >> 8) & 1;
27766 aob3 = gint & 0x0800;
27776 will generate the following code:
27809 000A E5*01\SpecialChar ~
27836 000C 23\SpecialChar ~
27867 000D 54 01\SpecialChar ~
27894 000F F5*02\SpecialChar ~
27949 0011 E5*01\SpecialChar ~
27976 0013 33\SpecialChar ~
28006 0014 92*00\SpecialChar ~
28061 0016 E5*01\SpecialChar ~
28088 0018 33\SpecialChar ~
28118 0019 92*01\SpecialChar ~
28173 001B E5*01\SpecialChar ~
28200 001D 03\SpecialChar ~
28231 001E 54 01\SpecialChar ~
28258 0020 F5*03\SpecialChar ~
28313 0022 E5*01\SpecialChar ~
28340 0024 13\SpecialChar ~
28370 0025 92*02\SpecialChar ~
28425 0027 E5*01\SpecialChar ~
28452 0029 A2 E3\SpecialChar ~
28479 002B 92*03\SpecialChar ~
28507 Other variations of these cases however will
28512 They are standard C expressions, so I heartily recommend these be the only
28513 way to get the highest order bit, (it is portable).
28514 Of course it will be recognized even if it is embedded in other expressions,
28520 xyz = gint + ((gint >> 15) & 1);
28523 will still be recognized.
28527 \begin_inset LatexCommand \index{Higher Order Byte}
28531 / Higher Order Word
28532 \begin_inset LatexCommand \index{Higher Order Word}
28539 It is also frequently required to obtain a higher order byte or word of
28540 a larger integral type (long, int or short types).
28541 SDCC recognizes the following expressions to yield the higher order byte
28542 or word and generates optimized code for it, e.g.:
28549 unsigned long int glong;
28557 unsigned char hob1, hob2;
28561 unsigned int how1, how2;
28570 hob1 = (gint >> 8) & 0xFF;
28574 hob2 = glong >> 24;
28578 how1 = (glong >> 16) & 0xFFFF;
28592 will generate the following code:
28625 0037 85*01*06\SpecialChar ~
28647 _foo_hob1_1_1,(_gint + 1)
28677 003A 85*05*07\SpecialChar ~
28699 _foo_hob2_1_1,(_glong + 3)
28729 003D 85*04*08\SpecialChar ~
28751 _foo_how1_1_1,(_glong + 2)
28753 0040 85*05*09\SpecialChar ~
28775 (_foo_how1_1_1 + 1),(_glong + 3)
28777 0043 85*03*0A\SpecialChar ~
28799 _foo_how2_1_1,(_glong + 1)
28801 0046 85*04*0B\SpecialChar ~
28823 (_foo_how2_1_1 + 1),(_glong + 2)
28826 Again, variations of these cases may
28831 They are standard C expressions, so I heartily recommend these be the only
28832 way to get the higher order byte/word, (it is portable).
28833 Of course it will be recognized even if it is embedded in other expressions,
28839 xyz = gint + ((gint >> 8) & 0xFF);
28842 will still be recognized.
28846 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
28851 \begin_inset LatexCommand \index{Peephole optimizer}
28858 The compiler uses a rule based, pattern matching and re-writing mechanism
28859 for peep-hole optimization.
28864 a peep-hole optimizer by Christopher W.
28865 Fraser (cwfraser\SpecialChar ~
28868 A default set of rules are compiled into the compiler, additional rules
28869 may be added with the
28882 \begin_inset LatexCommand \index{-\/-peep-file}
28889 The rule language is best illustrated with examples.
28913 The above rule will change the following assembly
28914 \begin_inset LatexCommand \index{Assembler routines}
28936 Note: All occurrences of a
28940 (pattern variable) must denote the same string.
28941 With the above rule, the assembly sequence:
28951 will remain unmodified.
28955 Other special case optimizations may be added by the user (via
28971 some variants of the 8051 MCU
28972 \begin_inset LatexCommand \index{MCS51 variants}
28985 The following two rules will change all
29004 replace { lcall %1 } by { acall %1 }
29006 replace { ljmp %1 } by { ajmp %1 }
29011 inline-assembler code
29013 is also passed through the peep hole optimizer, thus the peephole optimizer
29014 can also be used as an assembly level macro expander.
29015 The rules themselves are MCU dependent whereas the rule language infra-structur
29016 e is MCU independent.
29017 Peephole optimization rules for other MCU can be easily programmed using
29022 The syntax for a rule is as follows:
29027 rule := replace [ restart ] '{' <assembly sequence> '
29065 <assembly sequence> '
29083 '}' [if <functionName> ] '
29088 <assembly sequence> := assembly instruction (each instruction including
29089 labels must be on a separate line).
29093 The optimizer will apply to the rules one by one from the top in the sequence
29094 of their appearance, it will terminate when all rules are exhausted.
29095 If the 'restart' option is specified, then the optimizer will start matching
29096 the rules again from the top, this option for a rule is expensive (performance)
29097 , it is intended to be used in situations where a transformation will trigger
29098 the same rule again.
29099 An example of this (not a good one, it has side effects) is the following
29122 Note that the replace pattern cannot be a blank, but can be a comment line.
29123 Without the 'restart' option only the innermost 'pop' 'push' pair would
29124 be eliminated, i.e.:
29154 the restart option the rule will be applied again to the resulting code
29155 and then all the pop-push pairs will be eliminated to yield:
29165 A conditional function can be attached to a rule.
29166 Attaching rules are somewhat more involved, let me illustrate this with
29193 The optimizer does a look-up of a function name table defined in function
29198 in the source file SDCCpeeph.c, with the name
29203 If it finds a corresponding entry the function is called.
29204 Note there can be no parameters specified for these functions, in this
29209 is crucial, since the function
29213 expects to find the label in that particular variable (the hash table containin
29214 g the variable bindings is passed as a parameter).
29215 If you want to code more such functions, take a close look at the function
29216 labelInRange and the calling mechanism in source file SDCCpeeph.c.
29217 Currently implemented are
29219 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
29220 24bitMode, portIsDS390, 24bitModeAndPortDS390
29229 I know this whole thing is a little kludgey, but maybe some day we will
29230 have some better means.
29231 If you are looking at this file, you will see the default rules that are
29232 compiled into the compiler, you can add your own rules in the default set
29233 there if you get tired of specifying the -
29247 \begin_inset LatexCommand \index{ANSI-compliance}
29252 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
29259 The latest publically available version of the standard
29261 ISO/IEC 9899 - Programming languages - C
29263 should be available at:
29264 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
29273 Deviations from the compliance:
29276 functions are not reentrant
29277 \begin_inset LatexCommand \index{reentrant}
29281 unless explicitly declared as such or the
29294 \begin_inset LatexCommand \index{-\/-stack-auto}
29300 command line option is specified.
29304 \begin_inset LatexCommand \index{struct}
29309 \begin_inset LatexCommand \index{union}
29313 cannot be assigned values directly, cannot be passed as function parameters
29314 or assigned to each other and cannot be a return value
29315 \begin_inset LatexCommand \index{return value}
29319 from a function, e.g.:
29345 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
29364 s parms) /* invalid in SDCC although allowed in ANSI */
29385 return rets; /* is invalid in SDCC although allowed in ANSI */
29391 initialization of structure arrays must be fully braced.
29397 struct s { char x } a[] = {1, 2};\SpecialChar ~
29402 /* invalid in SDCC */
29404 struct s { char x } a[] = {{1}, {2}}; /* OK */
29409 \begin_inset LatexCommand \index{long long (not supported)}
29414 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
29422 \begin_inset LatexCommand \index{double (not supported)}
29426 ' precision floating point
29427 \begin_inset LatexCommand \index{Floating point support}
29435 \begin_inset LatexCommand \index{K\&R style}
29439 function declarations are NOT allowed.
29445 foo(i,j) /* this old style of function declarations */
29447 int i,j; /* are valid in ANSI but not valid in SDCC */
29462 Most enhancements in C99 are not supported, f.e.:
29470 \begin_inset LatexCommand \index{inline (not supported)}
29476 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
29482 can be used as a work around */
29490 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
29494 Certain words that are valid identifiers in the standard may be reserved
29495 words in SDCC unless the
29508 \begin_inset LatexCommand \index{-\/-std-c89}
29523 \begin_inset LatexCommand \index{-\/-std-c99}
29529 command line options are used.
29530 These may include (depending on the selected processor): 'at', 'banked',
29531 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
29532 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
29533 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
29535 Compliant equivalents of these keywords are always available in a form
29536 that begin with two underscores
29537 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
29542 '__data' instead of 'data'.
29545 Cyclomatic Complexity
29546 \begin_inset LatexCommand \index{Cyclomatic complexity}
29553 Cyclomatic complexity of a function is defined as the number of independent
29554 paths the program can take during execution of the function.
29555 This is an important number since it defines the number test cases you
29556 have to generate to validate the function.
29557 The accepted industry standard for complexity number is 10, if the cyclomatic
29558 complexity reported by SDCC exceeds 10 you should think about simplification
29559 of the function logic.
29560 Note that the complexity level is not related to the number of lines of
29561 code in a function.
29562 Large functions can have low complexity, and small functions can have large
29568 SDCC uses the following formula to compute the complexity:
29573 complexity = (number of edges in control flow graph) - (number of nodes
29574 in control flow graph) + 2;
29578 Having said that the industry standard is 10, you should be aware that in
29579 some cases it be may unavoidable to have a complexity level of less than
29581 For example if you have switch statement with more than 10 case labels,
29582 each case label adds one to the complexity level.
29583 The complexity level is by no means an absolute measure of the algorithmic
29584 complexity of the function, it does however provide a good starting point
29585 for which functions you might look at for further optimization.
29588 Retargetting for other Processors
29591 The issues for retargetting the compiler are far too numerous to be covered
29593 What follows is a brief description of each of the seven phases of the
29594 compiler and its MCU dependency.
29597 Parsing the source and building the annotated parse tree.
29598 This phase is largely MCU independent (except for the language extensions).
29599 Syntax & semantic checks are also done in this phase, along with some initial
29600 optimizations like back patching labels and the pattern matching optimizations
29601 like bit-rotation etc.
29604 The second phase involves generating an intermediate code which can be easy
29605 manipulated during the later phases.
29606 This phase is entirely MCU independent.
29607 The intermediate code generation assumes the target machine has unlimited
29608 number of registers, and designates them with the name iTemp.
29609 The compiler can be made to dump a human readable form of the code generated
29623 This phase does the bulk of the standard optimizations and is also MCU independe
29625 This phase can be broken down into several sub-phases:
29629 Break down intermediate code (iCode) into basic blocks.
29631 Do control flow & data flow analysis on the basic blocks.
29633 Do local common subexpression elimination, then global subexpression elimination
29635 Dead code elimination
29639 If loop optimizations caused any changes then do 'global subexpression eliminati
29640 on' and 'dead code elimination' again.
29643 This phase determines the live-ranges; by live range I mean those iTemp
29644 variables defined by the compiler that still survive after all the optimization
29646 Live range analysis
29647 \begin_inset LatexCommand \index{Live range analysis}
29651 is essential for register allocation, since these computation determines
29652 which of these iTemps will be assigned to registers, and for how long.
29655 Phase five is register allocation.
29656 There are two parts to this process.
29660 The first part I call 'register packing' (for lack of a better term).
29661 In this case several MCU specific expression folding is done to reduce
29666 The second part is more MCU independent and deals with allocating registers
29667 to the remaining live ranges.
29668 A lot of MCU specific code does creep into this phase because of the limited
29669 number of index registers available in the 8051.
29672 The Code generation phase is (unhappily), entirely MCU dependent and very
29673 little (if any at all) of this code can be reused for other MCU.
29674 However the scheme for allocating a homogenized assembler operand for each
29675 iCode operand may be reused.
29678 As mentioned in the optimization section the peep-hole optimizer is rule
29679 based system, which can reprogrammed for other MCUs.
29682 More information is available in a wiki
29683 \begin_inset LatexCommand \index{wiki}
29688 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
29692 ) and in the thread
29693 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
29701 \begin_inset LatexCommand \index{Compiler internals}
29708 The anatomy of the compiler
29709 \begin_inset LatexCommand \label{sub:The-anatomy-of}
29718 This is an excerpt from an article published in Circuit Cellar Magazine
29724 It's a little outdated (the compiler is much more efficient now and user/develo
29725 per friendly), but pretty well exposes the guts of it all.
29731 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
29732 It is fairly easy to retarget for other 8-bit MCU.
29733 Here we take a look at some of the internals of the compiler.
29738 \begin_inset LatexCommand \index{Parsing}
29745 Parsing the input source file and creating an AST (Annotated Syntax Tree
29746 \begin_inset LatexCommand \index{Annotated syntax tree}
29751 This phase also involves propagating types (annotating each node of the
29752 parse tree with type information) and semantic analysis.
29753 There are some MCU specific parsing rules.
29754 For example the storage classes, the extended storage classes are MCU specific
29755 while there may be a xdata storage class for 8051 there is no such storage
29756 class for z80 or Atmel AVR.
29757 SDCC allows MCU specific storage class extensions, i.e.
29758 xdata will be treated as a storage class specifier when parsing 8051 C
29759 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
29764 \begin_inset LatexCommand \index{iCode}
29771 Intermediate code generation.
29772 In this phase the AST is broken down into three-operand form (iCode).
29773 These three operand forms are represented as doubly linked lists.
29774 ICode is the term given to the intermediate form generated by the compiler.
29775 ICode example section shows some examples of iCode generated for some simple
29776 C source functions.
29780 \begin_inset LatexCommand \index{Optimizations}
29787 Bulk of the target independent optimizations is performed in this phase.
29788 The optimizations include constant propagation, common sub-expression eliminati
29789 on, loop invariant code movement, strength reduction of loop induction variables
29790 and dead-code elimination.
29793 Live range analysis
29794 \begin_inset LatexCommand \index{Live range analysis}
29801 During intermediate code generation phase, the compiler assumes the target
29802 machine has infinite number of registers and generates a lot of temporary
29804 The live range computation determines the lifetime of each of these compiler-ge
29805 nerated temporaries.
29806 A picture speaks a thousand words.
29807 ICode example sections show the live range annotations for each of the
29809 It is important to note here, each iCode is assigned a number in the order
29810 of its execution in the function.
29811 The live ranges are computed in terms of these numbers.
29812 The from number is the number of the iCode which first defines the operand
29813 and the to number signifies the iCode which uses this operand last.
29816 Register Allocation
29817 \begin_inset LatexCommand \index{Register allocation}
29824 The register allocation determines the type and number of registers needed
29826 In most MCUs only a few registers can be used for indirect addressing.
29827 In case of 8051 for example the registers R0 & R1 can be used to indirectly
29828 address the internal ram and DPTR to indirectly address the external ram.
29829 The compiler will try to allocate the appropriate register to pointer variables
29831 ICode example section shows the operands annotated with the registers assigned
29833 The compiler will try to keep operands in registers as much as possible;
29834 there are several schemes the compiler uses to do achieve this.
29835 When the compiler runs out of registers the compiler will check to see
29836 if there are any live operands which is not used or defined in the current
29837 basic block being processed, if there are any found then it will push that
29838 operand and use the registers in this block, the operand will then be popped
29839 at the end of the basic block.
29843 There are other MCU specific considerations in this phase.
29844 Some MCUs have an accumulator; very short-lived operands could be assigned
29845 to the accumulator instead of a general-purpose register.
29851 Figure II gives a table of iCode
29852 \begin_inset LatexCommand \index{iCode}
29856 operations supported by the compiler.
29857 The code generation involves translating these operations into corresponding
29858 assembly code for the processor.
29859 This sounds overly simple but that is the essence of code generation.
29860 Some of the iCode operations are generated on a MCU specific manner for
29861 example, the z80 port does not use registers to pass parameters so the
29862 SEND and RECV iCode operations will not be generated, and it also does
29863 not support JUMPTABLES.
29872 \begin_inset Tabular
29873 <lyxtabular version="3" rows="39" columns="4">
29874 <features islongtable="true" headBottomDL="true">
29875 <column alignment="block" valignment="top" leftline="true" width="13col%">
29876 <column alignment="left" valignment="top" leftline="true" width="13col%">
29877 <column alignment="block" valignment="top" leftline="true" width="22col%">
29878 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
29879 <row topline="true" bottomline="true" endhead="true">
29880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29890 \begin_inset LatexCommand \index{iCode}
29897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29928 <row topline="true">
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29946 IC_LEFT() IC_RESULT()
29949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29966 IC_RESULT = ! IC_LEFT;
29970 <row topline="true">
29971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29988 IC_LEFT() IC_RESULT()
29991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29998 Bitwise complement of
30001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30008 IC_RESULT = ~IC_LEFT;
30012 <row topline="true">
30013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30030 IC_LEFT() IC_RESULT()
30033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30040 Rotate right with carry
30043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30050 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
30054 <row topline="true">
30055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30072 IC_LEFT() IC_RESULT()
30075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30082 Rotate left with carry
30085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30092 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
30096 <row topline="true">
30097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30114 IC_LEFT() IC_RESULT()
30117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30124 Get the highest order bit of IC_LEFT
30127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30134 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
30138 <row topline="true">
30139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30156 IC_LEFT() IC_RESULT()
30159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30176 IC_RESULT = - IC_LEFT;
30180 <row topline="true">
30181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30208 Push the operand into stack
30211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30222 <row topline="true">
30223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30250 Pop the operand from the stack
30253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30264 <row topline="true">
30265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30282 IC_LEFT() IC_RESULT()
30285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30292 Call the function represented by IC_LEFT
30295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30302 IC_RESULT = IC_LEFT();
30306 <row topline="true">
30307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30324 IC_LEFT() IC_RESULT()
30327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30334 Call via function pointer
30337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30344 IC_RESULT = (*IC_LEFT)();
30348 <row topline="true">
30349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30376 Return the value in operand IC_LEFT
30379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30390 <row topline="true">
30391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30432 <row topline="true">
30433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30474 <row topline="true">
30475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30492 IC_LEFT() IC_RIGHT() IC_RESULT()
30495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30512 IC_RESULT = IC_LEFT + IC_RIGHT
30516 <row topline="true">
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30534 IC_LEFT() IC_RIGHT() IC_RESULT()
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30554 IC_RESULT = IC_LEFT - IC_RIGHT
30558 <row topline="true">
30559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30576 IC_LEFT() IC_RIGHT() IC_RESULT()
30579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30596 IC_RESULT = IC_LEFT * IC_RIGHT;
30600 <row topline="true">
30601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30618 IC_LEFT() IC_RIGHT() IC_RESULT()
30621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30638 IC_RESULT = IC_LEFT / IC_RIGHT;
30642 <row topline="true">
30643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30660 IC_LEFT() IC_RIGHT() IC_RESULT()
30663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30680 IC_RESULT = IC_LEFT % IC_RIGHT;
30684 <row topline="true">
30685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30702 IC_LEFT() IC_RIGHT() IC_RESULT()
30705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30722 IC_RESULT = IC_LEFT < IC_RIGHT;
30726 <row topline="true">
30727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30744 IC_LEFT() IC_RIGHT() IC_RESULT()
30747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30764 IC_RESULT = IC_LEFT > IC_RIGHT;
30768 <row topline="true">
30769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30786 IC_LEFT() IC_RIGHT() IC_RESULT()
30789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30806 IC_RESULT = IC_LEFT == IC_RIGHT;
30810 <row topline="true">
30811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30828 IC_LEFT() IC_RIGHT() IC_RESULT()
30831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30838 Logical and operation
30841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30848 IC_RESULT = IC_LEFT && IC_RIGHT;
30852 <row topline="true">
30853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30870 IC_LEFT() IC_RIGHT() IC_RESULT()
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30880 Logical or operation
30883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30890 IC_RESULT = IC_LEFT || IC_RIGHT;
30894 <row topline="true">
30895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30912 IC_LEFT() IC_RIGHT() IC_RESULT()
30915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30932 IC_RESULT = IC_LEFT ^ IC_RIGHT;
30936 <row topline="true">
30937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30954 IC_LEFT() IC_RIGHT() IC_RESULT()
30957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30974 IC_RESULT = IC_LEFT | IC_RIGHT;
30978 <row topline="true">
30979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30996 IC_LEFT() IC_RIGHT() IC_RESULT()
30999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31016 IC_RESULT = IC_LEFT & IC_RIGHT;
31020 <row topline="true">
31021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31038 IC_LEFT() IC_RIGHT() IC_RESULT()
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31058 IC_RESULT = IC_LEFT << IC_RIGHT
31062 <row topline="true">
31063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31080 IC_LEFT() IC_RIGHT() IC_RESULT()
31083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31100 IC_RESULT = IC_LEFT >> IC_RIGHT
31104 <row topline="true">
31105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31124 IC_LEFT() IC_RESULT()
31127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31144 IC_RESULT = (*IC_LEFT);
31148 <row topline="true">
31149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31166 IC_RIGHT() IC_RESULT()
31169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31186 (*IC_RESULT) = IC_RIGHT;
31190 <row topline="true">
31191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31208 IC_RIGHT() IC_RESULT()
31211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31228 IC_RESULT = IC_RIGHT;
31232 <row topline="true">
31233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31250 IC_COND IC_TRUE IC_LABEL
31253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31261 If true label is present then jump to true label if condition is true else
31262 jump to false label if condition is false
31265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31272 if (IC_COND) goto IC_TRUE;
31278 If (!IC_COND) goto IC_FALSE;
31282 <row topline="true">
31283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31300 IC_LEFT() IC_RESULT()
31303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31320 IC_RESULT = &IC_LEFT();
31324 <row topline="true">
31325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31342 IC_JTCOND IC_JTLABELS
31345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31352 Jump to list of labels depending on the value of JTCOND
31355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31366 <row topline="true">
31367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31384 IC_RIGHT() IC_LEFT() IC_RESULT()
31387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31404 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
31408 <row topline="true">
31409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31436 This is used for passing parameters in registers;
31438 move IC_LEFT to the next available parameter register.
31441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31452 <row topline="true">
31453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31480 This is used for receiving parameters passed in registers;
31482 Move the values in the next parameter register to IC_RESULT
31485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31496 <row topline="true" bottomline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31505 (some more have been added)
31508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31548 In the original article Figure II was announced to be downloadable on
31553 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
31557 \begin_inset LatexCommand \index{iCode}
31564 This section shows some details of iCode.
31565 The example C code does not do anything useful; it is used as an example
31566 to illustrate the intermediate code generated by the compiler.
31578 /* This function does nothing useful.
31585 for the purpose of explaining iCode */
31588 short function (data int *x)
31596 short i=10; \SpecialChar ~
31598 /* dead initialization eliminated */
31603 short sum=10; /* dead initialization eliminated */
31616 while (*x) *x++ = *p++;
31630 /* compiler detects i,j to be induction variables */
31634 for (i = 0, j = 10 ; i < 10 ; i++, j
31660 mul += i * 3; \SpecialChar ~
31662 /* this multiplication remains */
31668 gint += j * 3;\SpecialChar ~
31670 /* this multiplication changed to addition */
31684 In addition to the operands each iCode contains information about the filename
31685 and line it corresponds to in the source file.
31686 The first field in the listing should be interpreted as follows:
31691 Filename(linenumber: iCode Execution sequence number : ICode hash table
31692 key : loop depth of the iCode).
31697 Then follows the human readable form of the ICode operation.
31698 Each operand of this triplet form can be of three basic types a) compiler
31699 generated temporary b) user defined variable c) a constant value.
31700 Note that local variables and parameters are replaced by compiler generated
31703 \begin_inset LatexCommand \index{Live range analysis}
31707 are computed only for temporaries (i.e.
31708 live ranges are not computed for global variables).
31710 \begin_inset LatexCommand \index{Register allocation}
31714 are allocated for temporaries only.
31715 Operands are formatted in the following manner:
31720 Operand Name [lr live-from : live-to ] { type information } [ registers
31726 As mentioned earlier the live ranges are computed in terms of the execution
31727 sequence number of the iCodes, for example
31729 the iTemp0 is live from (i.e.
31730 first defined in iCode with execution sequence number 3, and is last used
31731 in the iCode with sequence number 5).
31732 For induction variables such as iTemp21 the live range computation extends
31733 the lifetime from the start to the end of the loop.
31735 The register allocator used the live range information to allocate registers,
31736 the same registers may be used for different temporaries if their live
31737 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
31738 iTemp17 since their live ranges do not overlap.
31739 In addition the allocator also takes into consideration the type and usage
31740 of a temporary, for example itemp6 is a pointer to near space and is used
31741 as to fetch data from (i.e.
31742 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
31743 Some short lived temporaries are allocated to special registers which have
31744 meaning to the code generator e.g.
31745 iTemp13 is allocated to a pseudo register CC which tells the back end that
31746 the temporary is used only for a conditional jump the code generation makes
31747 use of this information to optimize a compare and jump ICode.
31749 There are several loop optimizations
31750 \begin_inset LatexCommand \index{Loop optimization}
31754 performed by the compiler.
31755 It can detect induction variables iTemp21(i) and iTemp23(j).
31756 Also note the compiler does selective strength reduction
31757 \begin_inset LatexCommand \index{Strength reduction}
31762 the multiplication of an induction variable in line 18 (gint = j * 3) is
31763 changed to addition, a new temporary iTemp17 is allocated and assigned
31764 a initial value, a constant 3 is then added for each iteration of the loop.
31765 The compiler does not change the multiplication
31766 \begin_inset LatexCommand \index{Multiplication}
31770 in line 17 however since the processor does support an 8 * 8 bit multiplication.
31772 Note the dead code elimination
31773 \begin_inset LatexCommand \index{Dead-code elimination}
31777 optimization eliminated the dead assignments in line 7 & 8 to I and sum
31785 Sample.c (5:1:0:0) _entry($9) :
31790 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
31795 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
31800 Sample.c(11:4:53:0) preHeaderLbl0($11) :
31805 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
31811 Sample.c(11:6:5:1) _whilecontinue_0($1) :
31816 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
31822 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
31827 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
31833 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
31839 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
31845 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
31851 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
31852 * int}[r0] + 0x2 {short}
31857 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
31862 Sample.c(11:17:21:0)_whilebreak_0($3) :
31867 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
31872 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
31877 Sample.c(15:20:54:0)preHeaderLbl1($13) :
31882 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
31887 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
31892 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
31897 Sample.c(15:24:26:1)_forcond_0($4) :
31902 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
31908 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
31913 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
31914 + ITemp21 [lr21:38]{short}[r4]
31919 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
31925 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
31926 + iTemp15 [lr29:30]{short}[r1]
31931 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
31937 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
31943 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
31949 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
31955 Sample.c(19:38:47:1) goto _forcond_0($4)
31960 Sample.c(19:39:48:0)_forbreak_0($7) :
31965 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
31966 + ITemp11 [lr19:40]{short}[r3]
31971 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
31976 Sample.c(20:42:51:0)_return($8) :
31981 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
31987 Finally the code generated for this function:
32028 ; ----------------------------------------------
32033 ; function function
32038 ; ----------------------------------------------
32048 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
32060 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
32072 ;_whilecontinue_0($1) :
32082 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
32087 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32146 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
32165 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
32212 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
32252 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
32278 ; iTemp6 [lr5:16]{_near * int}[r0] =
32283 ; iTemp6 [lr5:16]{_near * int}[r0] +
32300 ; goto _whilecontinue_0($1)
32312 ; _whilebreak_0($3) :
32322 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32334 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32346 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32358 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32377 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32406 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
32411 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32456 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
32461 ; iTemp21 [lr21:38]{short}[r4]
32487 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
32520 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
32525 ; iTemp15 [lr29:30]{short}[r1]
32544 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
32591 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
32638 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
32650 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
32664 cjne r5,#0xff,00104$
32676 ; goto _forcond_0($4)
32688 ; _forbreak_0($7) :
32698 ; ret iTemp24 [lr40:41]{short}
32741 A few words about basic block successors, predecessors and dominators
32744 Successors are basic blocks
32745 \begin_inset LatexCommand \index{Basic blocks}
32749 that might execute after this basic block.
32751 Predecessors are basic blocks that might execute before reaching this basic
32754 Dominators are basic blocks that WILL execute before reaching this basic
32788 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
32791 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
32794 c) domVect of [BB4] = BB1 ...
32795 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
32803 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
32813 Thanks to all the other volunteer developers who have helped with coding,
32814 testing, web-page creation, distribution sets, etc.
32815 You know who you are :-)
32823 Also thanks to Sourceforge
32824 \begin_inset LatexCommand \url{http://www.sf.net}
32828 which has hosted the project since 1999 and donates significant download
32829 bandwidth and probably more than
32837 CPU cycles per day.
32845 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
32846 minutes for (configure+make+regression test), and there is (i386, amd64,
32847 alpha, ppc64, (mingw32), sparc, macosx).
32854 This document was initially written by Sandeep Dutta
32857 All product names mentioned herein may be trademarks
32858 \begin_inset LatexCommand \index{Trademarks}
32862 of their respective companies.
32869 To avoid confusion, the installation and building options for SDCC itself
32870 (chapter 2) are not part of the index.
32874 \begin_inset LatexCommand \printindex{}