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
1063 \labelwidthstring 00.00.0000
1075 -datarootdir see table below
1079 \labelwidthstring 00.00.0000
1083 docdir environment variable, see table below
1085 \labelwidthstring 00.00.0000
1089 include_dir_suffix environment variable, see table below
1091 \labelwidthstring 00.00.0000
1095 lib_dir_suffix environment variable, see table below
1097 \labelwidthstring 00.00.0000
1101 sdccconf_h_dir_separator environment variable, either / or
1106 This character will only be used in sdccconf.h; don't forget it's a C-header,
1107 therefore a double-backslash is needed there.
1111 \labelwidthstring 00.00.0000
1123 -disable-mcs51-port Excludes the Intel mcs51 port
1125 \labelwidthstring 00.00.0000
1137 -disable-gbz80-port Excludes the Gameboy gbz80 port
1139 \labelwidthstring 00.00.0000
1151 -disable-z80-port Excludes the z80 port
1153 \labelwidthstring 00.00.0000
1165 -disable-avr-port Excludes the AVR port
1167 \labelwidthstring 00.00.0000
1179 -disable-ds390-port Excludes the DS390 port
1181 \labelwidthstring 00.00.0000
1193 -disable-hc08-port Excludes the HC08 port
1195 \labelwidthstring 00.00.0000
1207 -disable-pic-port Excludes the PIC port
1209 \labelwidthstring 00.00.0000
1221 -disable-xa51-port Excludes the XA51 port
1223 \labelwidthstring 00.00.0000
1235 -disable-ucsim Disables configuring and building of ucsim
1237 \labelwidthstring 00.00.0000
1249 -disable-device-lib Disables automatically building device libraries
1251 \labelwidthstring 00.00.0000
1263 -disable-packihx Disables building packihx
1267 \labelwidthstring 00.00.0000
1279 -enable-doc Build pdf, html and txt files from the lyx sources
1281 \labelwidthstring 00.00.0000
1293 -enable-libgc Use the Bohem memory allocator.
1294 Lower runtime footprint.
1297 Furthermore the environment variables CC, CFLAGS, ...
1298 the tools and their arguments can be influenced.
1299 Please see `configure -
1309 -help` and the man/info pages of `configure` for details.
1313 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1314 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1315 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1316 At the moment it's not possible to change the default settings (it was
1317 simply never required).
1321 These configure options are compiled into the binaries, and can only be
1322 changed by rerunning 'configure' and recompiling SDCC.
1323 The configure options are written in
1327 to distinguish them from run time environment variables (see section search
1333 \begin_inset Quotes sld
1337 \begin_inset Quotes srd
1340 are used by the SDCC team to build the official Win32 binaries.
1341 The SDCC team uses Mingw32 to build the official Windows binaries, because
1348 a gcc compiler and last but not least
1351 the binaries can be built by cross compiling on Sourceforge's compile farm.
1354 See the examples, how to pass the Win32 settings to 'configure'.
1355 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1356 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1367 \begin_inset Tabular
1368 <lyxtabular version="3" rows="9" columns="3">
1370 <column alignment="block" valignment="top" leftline="true" width="0in">
1371 <column alignment="block" valignment="top" leftline="true" width="0in">
1372 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1373 <row topline="true" bottomline="true">
1374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1399 <row topline="true">
1400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1429 <row topline="true">
1430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1461 <row topline="true">
1462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1499 <row topline="true">
1500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1531 <row topline="true">
1532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1603 <row topline="true">
1604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1631 <row topline="true" bottomline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1668 'configure' also computes relative paths.
1669 This is needed for full relocatability of a binary package and to complete
1670 search paths (see section search paths below):
1676 \begin_inset Tabular
1677 <lyxtabular version="3" rows="4" columns="3">
1679 <column alignment="block" valignment="top" leftline="true" width="0in">
1680 <column alignment="block" valignment="top" leftline="true" width="0in">
1681 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1682 <row topline="true" bottomline="true">
1683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1708 <row topline="true" bottomline="true">
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1736 <row bottomline="true">
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1764 <row bottomline="true">
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1816 \begin_inset Quotes srd
1820 \begin_inset Quotes srd
1834 \begin_inset Quotes srd
1838 \begin_inset Quotes srd
1866 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1875 \begin_inset Quotes srd
1878 i586-mingw32msvc-gcc
1879 \begin_inset Quotes srd
1883 \begin_inset Quotes srd
1886 i586-mingw32msvc-g++
1887 \begin_inset Quotes srd
1895 \begin_inset Quotes srd
1898 i586-mingw32msvc-ranlib
1899 \begin_inset Quotes srd
1907 \begin_inset Quotes srd
1910 i586-mingw32msvc-strip
1911 \begin_inset Quotes srd
1929 \begin_inset Quotes srd
1933 \begin_inset Quotes srd
1951 \begin_inset Quotes srd
1955 \begin_inset Quotes srd
1963 \begin_inset Quotes srd
1969 \begin_inset Quotes srd
1977 \begin_inset Quotes srd
1981 \begin_inset Quotes srd
1989 \begin_inset Quotes srd
1993 \begin_inset Quotes srd
2000 sdccconf_h_dir_separator=
2001 \begin_inset Quotes srd
2013 \begin_inset Quotes srd
2044 -host=i586-mingw32msvc
2058 -build=unknown-unknown-linux-gnu
2062 \begin_inset Quotes sld
2066 \begin_inset Quotes srd
2069 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2088 \begin_inset Quotes srd
2092 \begin_inset Quotes srd
2110 \begin_inset Quotes srd
2114 \begin_inset Quotes srd
2122 \begin_inset Quotes srd
2128 \begin_inset Quotes srd
2136 \begin_inset Quotes srd
2140 \begin_inset Quotes srd
2148 \begin_inset Quotes srd
2152 \begin_inset Quotes srd
2159 sdccconf_h_dir_separator=
2160 \begin_inset Quotes srd
2172 \begin_inset Quotes srd
2180 \begin_inset Quotes srd
2184 \begin_inset Quotes srd
2192 \begin_inset Quotes srd
2196 \begin_inset Quotes srd
2202 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2213 -C' turns on caching, which gives a little bit extra speed.
2214 However if options are changed, it can be necessary to delete the config.cache
2219 \begin_inset LatexCommand \label{sub:Install-paths}
2224 \begin_inset LatexCommand \index{Install paths}
2230 \added_space_top medskip \align center
2232 \begin_inset Tabular
2233 <lyxtabular version="3" rows="5" columns="4">
2235 <column alignment="left" valignment="top" leftline="true" width="0">
2236 <column alignment="left" valignment="top" leftline="true" width="0">
2237 <column alignment="left" valignment="top" leftline="true" width="0">
2238 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2239 <row topline="true" bottomline="true">
2240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2281 <row topline="true">
2282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2321 <row topline="true">
2322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 $DATADIR/ $INCLUDE_DIR_SUFFIX
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2345 /usr/local/share/sdcc/include
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2361 <row topline="true">
2362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2377 $DATADIR/$LIB_DIR_SUFFIX
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2385 /usr/local/share/sdcc/lib
2388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2401 <row topline="true" bottomline="true">
2402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2425 /usr/local/share/sdcc/doc
2428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2450 *compiler, preprocessor, assembler, and linker
2456 is auto-appended by the compiler, e.g.
2457 small, large, z80, ds390 etc
2460 The install paths can still be changed during `make install` with e.g.:
2463 make install prefix=$(HOME)/local/sdcc
2466 Of course this doesn't change the search paths compiled into the binaries.
2470 Moreover the install path can be changed by defining DESTDIR
2471 \begin_inset LatexCommand \index{DESTDIR}
2478 make install DESTDIR=$(HOME)/sdcc.rpm/
2481 Please note that DESTDIR must have a trailing slash!
2485 \begin_inset LatexCommand \label{sub:Search-Paths}
2490 \begin_inset LatexCommand \index{Search path}
2497 Some search paths or parts of them are determined by configure variables
2502 , see section above).
2503 Further search paths are determined by environment variables during runtime.
2506 The paths searched when running the compiler are as follows (the first catch
2512 Binary files (preprocessor, assembler and linker)
2518 \begin_inset Tabular
2519 <lyxtabular version="3" rows="4" columns="3">
2521 <column alignment="block" valignment="top" leftline="true" width="0in">
2522 <column alignment="block" valignment="top" leftline="true" width="0in">
2523 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2524 <row topline="true" bottomline="true">
2525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2550 <row topline="true">
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2580 <row topline="true">
2581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2586 Path of argv[0] (if available)
2589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2606 <row topline="true" bottomline="true">
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2648 \begin_inset Tabular
2649 <lyxtabular version="3" rows="6" columns="3">
2651 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2652 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2653 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2654 <row topline="true" bottomline="true">
2655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2680 <row topline="true">
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2736 <row topline="true">
2737 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2762 <row topline="true">
2763 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2777 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2800 <row topline="true">
2801 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2882 <row topline="true" bottomline="true">
2883 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2904 /usr/local/share/sdcc/
2909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2937 -nostdinc disables the last two search paths.
2947 With the exception of
2948 \begin_inset Quotes sld
2962 \begin_inset Quotes srd
2969 is auto-appended by the compiler (e.g.
2970 small, large, z80, ds390 etc.).
2977 \begin_inset Tabular
2978 <lyxtabular version="3" rows="6" columns="3">
2980 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2981 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2982 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2983 <row topline="true" bottomline="true">
2984 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2992 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3009 <row topline="true">
3010 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3065 <row topline="true">
3066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3078 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3105 <row topline="true">
3106 <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">
3134 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3151 <row topline="true">
3152 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3167 $LIB_DIR_SUFFIX/<model>
3170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3279 <row topline="true" bottomline="true">
3280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3289 $LIB_DIR_SUFFIX/<model>
3292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3297 /usr/local/share/sdcc/
3304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3322 Don't delete any of the stray spaces in the table above without checking
3323 the HTML output (last line)!
3339 -nostdlib disables the last two search paths.
3343 \begin_inset LatexCommand \index{Building SDCC}
3350 Building SDCC on Linux
3351 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3360 Download the source package
3362 either from the SDCC Subversion repository or from the nightly snapshots
3364 , it will be named something like sdcc
3375 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3384 Bring up a command line terminal, such as xterm.
3389 Unpack the file using a command like:
3392 "tar -xvzf sdcc.src.tar.gz
3397 , this will create a sub-directory called sdcc with all of the sources.
3400 Change directory into the main SDCC directory, for example type:
3417 This configures the package for compilation on your system.
3433 All of the source packages will compile, this can take a while.
3449 This copies the binary executables, the include files, the libraries and
3450 the documentation to the install directories.
3451 Proceed with section
3452 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3459 Building SDCC on OSX 2.x
3462 Follow the instruction for Linux.
3466 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3467 )) fails to compile SDCC.
3468 Fortunately there's also gcc 2.9.x installed, which works fine.
3469 This compiler can be selected by running 'configure' with:
3472 ./configure CC=gcc2 CXX=g++2
3475 Cross compiling SDCC on Linux for Windows
3478 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3479 See section 'Configure Options'.
3482 Building SDCC using Cygwin and Mingw32
3485 For building and installing a Cygwin executable follow the instructions
3491 \begin_inset Quotes sld
3495 \begin_inset Quotes srd
3498 Win32-binary can be built, which will not need the Cygwin-DLL.
3499 For the necessary 'configure' options see section 'configure options' or
3500 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3504 In order to install Cygwin on Windows download setup.exe from
3505 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3511 \begin_inset Quotes sld
3514 default text file type
3515 \begin_inset Quotes srd
3519 \begin_inset Quotes sld
3523 \begin_inset Quotes srd
3526 and download/install at least the following packages.
3527 Some packages are selected by default, others will be automatically selected
3528 because of dependencies with the manually selected packages.
3529 Never deselect these packages!
3538 gcc ; version 3.x is fine, no need to use the old 2.9x
3541 binutils ; selected with gcc
3547 rxvt ; a nice console, which makes life much easier under windoze (see below)
3550 man ; not really needed for building SDCC, but you'll miss it sooner or
3554 less ; not really needed for building SDCC, but you'll miss it sooner or
3558 svn ; only if you use Subversion access
3561 If you want to develop something you'll need:
3564 python ; for the regression tests
3567 gdb ; the gnu debugger, together with the nice GUI
3568 \begin_inset Quotes sld
3572 \begin_inset Quotes srd
3578 openssh ; to access the CF or commit changes
3581 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3582 use autoconf-stable!
3585 rxvt is a nice console with history.
3586 Replace in your cygwin.bat the line
3605 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3608 -bg black -fg white -geometry 100x65 -e bash -
3621 Text selected with the mouse is automatically copied to the clipboard, pasting
3622 works with shift-insert.
3626 The other good tip is to make sure you have no //c/-style paths anywhere,
3627 use /cygdrive/c/ instead.
3628 Using // invokes a network lookup which is very slow.
3630 \begin_inset Quotes sld
3634 \begin_inset Quotes srd
3637 is too long, you can change it with e.g.
3643 SDCC sources use the unix line ending LF.
3644 Life is much easier, if you store the source tree on a drive which is mounted
3646 And use an editor which can handle LF-only line endings.
3647 Make sure not to commit files with windows line endings.
3648 The tabulator spacing
3649 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3653 used in the project is 8.
3654 Although a tabulator spacing of 8 is a sensible choice for programmers
3655 (it's a power of 2 and allows to display 8/16 bit signed variables without
3656 loosing columns) the plan is to move towards using only spaces in the source.
3659 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3664 Download the source package
3666 either from the SDCC Subversion repository or from the
3667 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3673 , it will be named something like sdcc
3680 SDCC is distributed with all the projects, workspaces, and files you need
3681 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3682 The workspace name is 'sdcc.dsw'.
3683 Please note that as it is now, all the executables are created in a folder
3687 Once built you need to copy the executables from sdcc
3691 bin before running SDCC.
3696 WARNING: Visual studio is very picky with line terminations; it expects
3697 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3698 When using the Subversion repository it's easiest to configure the svn
3699 client to convert automatically for you.
3700 If however you are getting a message such as "This makefile was not generated
3701 by Developer Studio etc.
3703 \begin_inset Quotes srd
3706 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3707 need to convert the Unix style line endings to DOS style line endings.
3708 To do so you can use the
3709 \begin_inset Quotes sld
3713 \begin_inset Quotes srd
3716 utility freely available on the internet.
3717 Doug Hawkins reported in the sdcc-user list that this works:
3725 SDCC> unix2dos sdcc.dsw
3731 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3735 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3736 flex.exe, and gawk.exe.
3737 One good place to get them is
3738 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3746 Download the file UnxUtils
3747 \begin_inset LatexCommand \index{UnxUtils}
3752 Now you have to install the utilities and setup MSVC so it can locate the
3754 Here there are two alternatives (choose one!):
3761 a) Extract UnxUtils.zip to your C:
3763 hard disk PRESERVING the original paths, otherwise bison won't work.
3764 (If you are using WinZip make certain that 'Use folder names' is selected)
3768 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3769 in 'Show directories for:' select 'Executable files', and in the directories
3770 window add a new path: 'C:
3780 (As a side effect, you get a bunch of Unix utilities that could be useful,
3781 such as diff and patch.)
3788 This one avoids extracting a bunch of files you may not use, but requires
3793 a) Create a directory were to put the tools needed, or use a directory already
3801 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3802 to such directory WITHOUT preserving the original paths.
3803 (If you are using WinZip make certain that 'Use folder names' is not selected)
3807 c) Rename bison.exe to '_bison.exe'.
3811 d) Create a batch file 'bison.bat' in 'C:
3815 ' and add these lines:
3835 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3839 Steps 'c' and 'd' are needed because bison requires by default that the
3840 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3841 '/usr/local/share/' I think.
3842 So it is necessary to tell bison where those files are located if they
3843 are not in such directory.
3844 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3848 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3849 in 'Show directories for:' select 'Executable files', and in the directories
3850 window add a new path: 'c:
3853 Note that you can use any other path instead of 'c:
3855 util', even the path where the Visual C++ tools are, probably: 'C:
3859 Microsoft Visual Studio
3864 So you don't have to execute step 'e' :)
3868 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3869 the executables from sdcc
3873 bin, and you can compile using SDCC.
3876 Building SDCC Using Borland
3879 From the sdcc directory, run the command "make -f Makefile.bcc".
3880 This should regenerate all the .exe files in the bin directory except for
3884 If you modify any source files and need to rebuild, be aware that the dependenci
3885 es may not be correctly calculated.
3886 The safest option is to delete all .obj files and run the build again.
3887 From a Cygwin BASH prompt, this can easily be done with the command (be
3888 sure you are in the sdcc directory):
3898 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3900 ) -print -exec rm {}
3909 or on Windows NT/2000/XP from the command prompt with the command:
3916 del /s *.obj *.lib *.rul
3919 from the sdcc directory.
3922 Windows Install Using a ZIP Package
3925 Download the binary zip package from
3926 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3930 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3931 This should unpack to a group of sub-directories.
3932 An example directory structure after unpacking the mingw32 package is:
3937 bin for the executables, c:
3945 lib for the include and libraries.
3948 Adjust your environment variable PATH to include the location of the bin
3949 directory or start sdcc using the full path.
3952 Windows Install Using the Setup Program
3953 \begin_inset LatexCommand \label{sub:Windows-Install}
3960 Download the setup program
3962 sdcc-x.y.z-setup.exe
3964 for an official release from
3967 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3971 or a setup program for one of the snapshots
3973 sdcc-yyyymmdd-xxxx-setup.exe
3976 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3981 A windows typical installer will guide you through the installation process.
3985 \begin_inset LatexCommand \index{VPATH}
3992 SDCC supports the VPATH feature provided by configure and make.
3993 It allows to separate the source and build trees.
4025 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4026 # extract source to directory sdcc
4031 mkdir sdcc.build\SpecialChar ~
4040 # put output in sdcc.build
4050 ../sdcc/configure\SpecialChar ~
4058 # configure is doing all the magic!
4070 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4071 It automagically computes the variables srcdir, top_srcdir and top_buildir
4077 the generated files will be in ~/sdcc.build, while the source files stay
4080 This is not only usefull for building different binaries, e.g.
4081 when cross compiling.
4082 It also gives you a much better overview in the source tree when all the
4083 generated files are not scattered between the source files.
4084 And the best thing is: if you want to change a file you can leave the original
4085 file untouched in the source directory.
4086 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4087 Makefile.dep` and `make`.
4092 will do the rest for you!
4095 Building the Documentation
4108 -enable-doc to the configure arguments to build the documentation together
4109 with all the other stuff.
4110 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4111 dvips and makeindex) to get the job done.
4112 Another possibility is to change to the doc directory and to type
4116 \begin_inset Quotes srd
4120 \begin_inset Quotes srd
4127 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4130 \begin_inset LatexCommand \url{http://www.lyx.org}
4134 as editor is straightforward.
4135 Prebuilt documentation in html and pdf format is available from
4136 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4143 Reading the Documentation
4144 \begin_inset LatexCommand \index{Documentation}
4151 Currently reading the document in pdf format is recommended, as for unknown
4152 reason the hyperlinks are working there whereas in the html version they
4159 If you should know why please drop us a note
4165 You'll find the pdf version
4166 \begin_inset LatexCommand \index{PDF version of this document}
4171 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4179 \begin_inset LatexCommand \index{HTML version of this document}
4184 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4190 This documentation is in some aspects different from a commercial documentation:
4194 It tries to document SDCC for several processor architectures in one document
4195 (commercially these probably would be separate documents/products).
4197 \begin_inset LatexCommand \index{Status of documentation}
4201 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4203 Z80, PIC14, PIC16 and HC08.
4206 There are many references pointing away from this documentation.
4207 Don't let this distract you.
4209 was a reference like
4210 \begin_inset LatexCommand \url{http://www.opencores.org}
4214 together with a statement
4215 \begin_inset Quotes sld
4218 some processors which are targetted by SDCC can be implemented in a
4235 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4240 \begin_inset Quotes srd
4244 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4249 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4254 \begin_inset Quotes sld
4257 have you ever heard of an open source compiler that compiles a subset of
4259 \begin_inset Quotes srd
4262 we expect you to have a quick look there and come back.
4263 If you read this you are on the right track.
4266 Some sections attribute more space to problems, restrictions and warnings
4267 than to the solution.
4270 The installation section and the section about the debugger is intimidating.
4273 There are still lots of typos and there are more different writing styles
4277 Testing the SDCC Compiler
4278 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4285 The first thing you should do after installing your SDCC compiler is to
4301 \begin_inset LatexCommand \index{version}
4308 at the prompt, and the program should run and output its version like:
4313 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4317 If it doesn't run, or gives a message about not finding sdcc program, then
4318 you need to check over your installation.
4319 Make sure that the sdcc bin directory is in your executable search path
4320 defined by the PATH environment setting (
4325 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4332 Install trouble-shooting for suggestions
4335 Make sure that the sdcc program is in the bin folder, if not perhaps something
4336 did not install correctly.
4344 is commonly installed as described in section
4345 \begin_inset Quotes sld
4348 Install and search paths
4349 \begin_inset Quotes srd
4358 Make sure the compiler works on a very simple example.
4359 Type in the following test.c program using your favorite
4385 Compile this using the following command:
4394 If all goes well, the compiler will generate a test.asm and test.rel file.
4395 Congratulations, you've just compiled your first program with SDCC.
4396 We used the -c option to tell SDCC not to link the generated code, just
4397 to keep things simple for this step.
4405 The next step is to try it with the linker.
4415 If all goes well the compiler will link with the libraries and produce
4416 a test.ihx output file.
4421 (no test.ihx, and the linker generates warnings), then the problem is most
4430 usr/local/share/sdcc/lib directory
4437 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4444 Install trouble-shooting for suggestions).
4452 The final test is to ensure
4460 header files and libraries.
4461 Edit test.c and change it to the following:
4478 strcpy(str1, "testing");
4485 Compile this by typing
4492 This should generate a test.ihx output file, and it should give no warnings
4493 such as not finding the string.h file.
4494 If it cannot find the string.h file, then the problem is that
4498 cannot find the /usr/local/share/sdcc/include directory
4505 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4512 Install trouble-shooting section for suggestions).
4530 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4534 to find exactly where SDCC is looking for the include and lib files.
4537 Install Trouble-shooting
4538 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4543 \begin_inset LatexCommand \index{Install trouble-shooting}
4550 If SDCC does not build correctly
4553 A thing to try is starting from scratch by unpacking the .tgz source package
4554 again in an empty directory.
4562 ./configure 2>&1 | tee configure.log
4576 make 2>&1 | tee make.log
4583 If anything goes wrong, you can review the log files to locate the problem.
4584 Or a relevant part of this can be attached to an email that could be helpful
4585 when requesting help from the mailing list.
4589 \begin_inset Quotes sld
4593 \begin_inset Quotes srd
4600 \begin_inset Quotes sld
4604 \begin_inset Quotes srd
4607 command is a script that analyzes your system and performs some configuration
4608 to ensure the source package compiles on your system.
4609 It will take a few minutes to run, and will compile a few tests to determine
4610 what compiler features are installed.
4614 \begin_inset Quotes sld
4618 \begin_inset Quotes srd
4624 This runs the GNU make tool, which automatically compiles all the source
4625 packages into the final installed binary executables.
4629 \begin_inset Quotes sld
4633 \begin_inset Quotes erd
4639 This will install the compiler, other executables libraries and include
4640 files into the appropriate directories.
4642 \begin_inset LatexCommand \ref{sub:Install-paths}
4648 \begin_inset LatexCommand \ref{sub:Search-Paths}
4653 about install and search paths.
4655 On most systems you will need super-user privileges to do this.
4661 SDCC is not just a compiler, but a collection of tools by various developers.
4662 These include linkers, assemblers, simulators and other components.
4663 Here is a summary of some of the components.
4664 Note that the included simulator and assembler have separate documentation
4665 which you can find in the source package in their respective directories.
4666 As SDCC grows to include support for other processors, other packages from
4667 various developers are included and may have their own sets of documentation.
4671 You might want to look at the files which are installed in <installdir>.
4672 At the time of this writing, we find the following programs for gcc-builds:
4676 In <installdir>/bin:
4679 sdcc - The compiler.
4682 sdcpp - The C preprocessor.
4685 asx8051 - The assembler for 8051 type processors.
4692 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4695 aslink -The linker for 8051 type processors.
4702 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4705 s51 - The ucSim 8051 simulator.
4708 sdcdb - The source debugger.
4711 packihx - A tool to pack (compress) Intel hex files.
4714 In <installdir>/share/sdcc/include
4720 In <installdir>/share/sdcc/lib
4723 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4727 In <installdir>/share/sdcc/doc
4733 As development for other processors proceeds, this list will expand to include
4734 executables to support processors like AVR, PIC, etc.
4740 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4741 the assembler and linkage editor.
4744 sdcpp - The C-Preprocessor
4748 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4752 is a modified version of the GNU cpp
4753 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4758 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4763 The C preprocessor is used to pull in #include sources, process #ifdef
4764 statements, #defines and so on.
4775 - The Assemblers and Linkage Editors
4778 This is retargettable assembler & linkage editor, it was developed by Alan
4780 John Hartman created the version for 8051, and I (Sandeep) have made some
4781 enhancements and bug fixes for it to work properly with SDCC.
4788 \begin_inset LatexCommand \index{s51}
4792 is a freeware, opensource simulator developed by Daniel Drotos.
4793 The simulator is built as part of the build process.
4794 For more information visit Daniel's web site at:
4795 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4800 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4804 sdcdb - Source Level Debugger
4808 \begin_inset LatexCommand \index{SDCDB (debugger)}
4812 is the companion source level debugger.
4813 More about SDCDB in section
4814 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4819 The current version of the debugger uses Daniel's Simulator S51
4820 \begin_inset LatexCommand \index{s51}
4824 , but can be easily changed to use other simulators.
4833 Single Source File Projects
4836 For single source file 8051 projects the process is very simple.
4837 Compile your programs with the following command
4840 "sdcc sourcefile.c".
4844 This will compile, assemble and link your source file.
4845 Output files are as follows:
4849 \begin_inset LatexCommand \index{<file>.asm}
4854 \begin_inset LatexCommand \index{Assembler source}
4858 file created by the compiler
4862 \begin_inset LatexCommand \index{<file>.lst}
4867 \begin_inset LatexCommand \index{Assembler listing}
4871 file created by the Assembler
4875 \begin_inset LatexCommand \index{<file>.rst}
4880 \begin_inset LatexCommand \index{Assembler listing}
4884 file updated with linkedit information, created by linkage editor
4888 \begin_inset LatexCommand \index{<file>.sym}
4893 \begin_inset LatexCommand \index{Symbol listing}
4897 for the sourcefile, created by the assembler
4901 \begin_inset LatexCommand \index{<file>.rel}
4906 \begin_inset LatexCommand \index{<file>.o}
4911 \begin_inset LatexCommand \index{Object file}
4915 created by the assembler, input to Linkage editor
4919 \begin_inset LatexCommand \index{<file>.map}
4924 \begin_inset LatexCommand \index{Memory map}
4928 for the load module, created by the Linker
4932 \begin_inset LatexCommand \index{<file>.mem}
4936 - A file with a summary of the memory usage
4940 \begin_inset LatexCommand \index{<file>.ihx}
4944 - The load module in Intel hex format
4945 \begin_inset LatexCommand \index{Intel hex format}
4949 (you can select the Motorola S19 format
4950 \begin_inset LatexCommand \index{Motorola S19 format}
4965 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4970 If you need another format you might want to use
4977 \begin_inset LatexCommand \index{objdump (tool)}
4988 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4993 Both formats are documented in the documentation of srecord
4994 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5002 \begin_inset LatexCommand \index{<file>.adb}
5006 - An intermediate file containing debug information needed to create the
5018 \begin_inset LatexCommand \index{-\/-debug}
5026 \begin_inset LatexCommand \index{<file>.cdb}
5030 - An optional file (with -
5040 -debug) containing debug information.
5041 The format is documented in cdbfileformat.pdf
5046 \begin_inset LatexCommand \index{<file> (no extension)}
5050 An optional AOMF or AOMF51
5051 \begin_inset LatexCommand \index{AOMF, AOMF51}
5056 \begin_inset LatexCommand \label{OMF file}
5060 file containing debug information (generated with option -
5087 ormat is commonly used by third party tools (debuggers
5088 \begin_inset LatexCommand \index{Debugger}
5092 , simulators, emulators)
5096 \begin_inset LatexCommand \index{<file>.dump*}
5100 - Dump file to debug the compiler it self (generated with option -
5110 -dumpall) (see section
5111 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5117 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5123 \begin_inset Quotes sld
5126 Anatomy of the compiler
5127 \begin_inset Quotes srd
5133 Postprocessing the Intel Hex
5134 \begin_inset LatexCommand \index{Intel hex format}
5141 In most cases this won't be needed but the Intel Hex file
5142 \begin_inset LatexCommand \index{<file>.ihx}
5146 which is generated by SDCC might include lines of varying length and the
5147 addresses within the file are not guaranteed to be strictly ascending.
5148 If your toolchain or a bootloader does not like this you can use the tool
5154 \begin_inset LatexCommand \index{packihx (tool)}
5158 which is part of the SDCC distribution:
5165 packihx sourcefile.ihx >sourcefile.hex
5172 The separately available
5177 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5181 package additionally allows to set undefined locations to a predefined
5182 value, to insert checksums
5183 \begin_inset LatexCommand \index{checksum}
5187 of various flavours (crc, add, xor) and to perform other manipulations
5188 (convert, split, crop, offset, ...).
5196 srec_cat\SpecialChar ~
5198 sourcefile.ihx -intel\SpecialChar ~
5200 -o sourcefile.hex -intel
5207 An example for a more complex command line
5213 the command backfills
5214 \begin_inset LatexCommand \index{backfill unused memory}
5218 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5220 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5221 will be interpreted as an
5229 (where an emergency routine could sit).
5240 srec_cat\SpecialChar ~
5241 sourcefile.ihx -intel\SpecialChar ~
5243 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5244 -little-endian-checksum-nega
5245 tive 0xfffe 0x02 0x02\SpecialChar ~
5247 -o sourcefile.hex -intel
5256 The srecord package is available at
5257 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5264 Projects with Multiple Source Files
5267 SDCC can compile only ONE file at a time.
5268 Let us for example assume that you have a project containing the following
5273 foo1.c (contains some functions)
5275 foo2.c (contains some more functions)
5277 foomain.c (contains more functions and the function main)
5285 The first two files will need to be compiled separately with the commands:
5317 Then compile the source file containing the
5322 \begin_inset LatexCommand \index{Linker}
5326 the files together with the following command:
5334 foomain.c\SpecialChar ~
5335 foo1.rel\SpecialChar ~
5340 \begin_inset LatexCommand \index{<file>.rel}
5352 can be separately compiled as well:
5363 sdcc foomain.rel foo1.rel foo2.rel
5370 The file containing the
5385 file specified in the command line, since the linkage editor processes
5386 file in the order they are presented to it.
5387 The linker is invoked from SDCC using a script file with extension .lnk
5388 \begin_inset LatexCommand \index{<file>.lnk}
5393 You can view this file to troubleshoot linking problems such as those arising
5394 from missing libraries.
5397 Projects with Additional Libraries
5398 \begin_inset LatexCommand \index{Libraries}
5405 Some reusable routines may be compiled into a library, see the documentation
5406 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5410 \begin_inset LatexCommand \index{<file>.lib}
5417 Libraries created in this manner can be included in the command line.
5418 Make sure you include the -L <library-path> option to tell the linker where
5419 to look for these files if they are not in the current directory.
5420 Here is an example, assuming you have the source file
5432 (if that is not the same as your current project):
5439 sdcc foomain.c foolib.lib -L mylib
5450 must be an absolute path name.
5454 The most efficient way to use libraries is to keep separate modules in separate
5456 The lib file now should name all the modules.rel
5457 \begin_inset LatexCommand \index{<file>.rel}
5462 For an example see the standard library file
5466 in the directory <installdir>/share/lib/small.
5469 Using sdcclib to Create and Manage Libraries
5470 \begin_inset LatexCommand \index{sdcclib}
5477 Alternatively, instead of having a .rel file for each entry on the library
5478 file as described in the preceding section, sdcclib can be used to embed
5479 all the modules belonging to such library in the library file itself.
5480 This results in a larger library file, but it greatly reduces the number
5481 of disk files accessed by the linker.
5482 Additionally, the packed library file contains an index of all include
5483 modules and symbols that significantly speeds up the linking process.
5484 To display a list of options supported by sdcclib type:
5493 \begin_inset LatexCommand \index{sdcclib}
5504 To create a new library file, start by compiling all the required modules.
5542 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5544 The next step is to add the .rel files to the library file:
5552 sdcclib libint.lib _divsint.rel
5555 \begin_inset LatexCommand \index{sdcclib}
5565 sdcclib libint.lib _divuint.rel
5571 sdcclib libint.lib _modsint.rel
5577 sdcclib libint.lib _moduint.rel
5583 sdcclib libint.lib _mulint.rel
5590 If the file already exists in the library, it will be replaced.
5591 To see what modules and symbols are included in the library, options -s
5592 and -m are available.
5600 sdcclib -s libint.lib
5603 \begin_inset LatexCommand \index{sdcclib}
5712 \added_space_bottom bigskip
5713 If the source files are compiled using -
5724 \begin_inset LatexCommand \index{-\/-debug}
5728 , the corresponding debug information file .adb will be include in the library
5730 The library files created with sdcclib are plain text files, so they can
5731 be viewed with a text editor.
5732 It is not recomended to modify a library file created with sdcclib using
5733 a text editor, as there are file indexes numbers located accross the file
5734 used by the linker to quickly locate the required module to link.
5735 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5736 it can be safely deleted, since all the information required for linking
5737 is embedded in the library file itself.
5738 Library files created using sdcclib are used as described in the preceding
5742 Command Line Options
5743 \begin_inset LatexCommand \index{Command Line Options}
5750 Processor Selection Options
5751 \begin_inset LatexCommand \index{Options processor selection}
5756 \begin_inset LatexCommand \index{Processor selection options}
5762 \labelwidthstring 00.00.0000
5767 \begin_inset LatexCommand \index{-mmcs51}
5773 Generate code for the Intel MCS51
5774 \begin_inset LatexCommand \index{MCS51}
5778 family of processors.
5779 This is the default processor target.
5781 \labelwidthstring 00.00.0000
5786 \begin_inset LatexCommand \index{-mds390}
5792 Generate code for the Dallas DS80C390
5793 \begin_inset LatexCommand \index{DS80C390}
5799 \labelwidthstring 00.00.0000
5804 \begin_inset LatexCommand \index{-mds400}
5810 Generate code for the Dallas DS80C400
5811 \begin_inset LatexCommand \index{DS80C400}
5817 \labelwidthstring 00.00.0000
5822 \begin_inset LatexCommand \index{-mhc08}
5828 Generate code for the Freescale/Motorola HC08
5829 \begin_inset LatexCommand \index{HC08}
5833 family of processors.
5835 \labelwidthstring 00.00.0000
5840 \begin_inset LatexCommand \index{-mz80}
5846 Generate code for the Zilog Z80
5847 \begin_inset LatexCommand \index{Z80}
5851 family of processors.
5853 \labelwidthstring 00.00.0000
5858 \begin_inset LatexCommand \index{-mgbz80}
5864 Generate code for the GameBoy Z80
5865 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5869 processor (Not actively maintained).
5871 \labelwidthstring 00.00.0000
5876 \begin_inset LatexCommand \index{-mavr}
5882 Generate code for the Atmel AVR
5883 \begin_inset LatexCommand \index{AVR}
5887 processor (Not maintained, not complete).
5888 AVR users should probably have a look at winavr
5889 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5894 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5901 I think it is fair to direct users there for now.
5902 Open source is also about avoiding unnecessary work .
5903 But I didn't find the 'official' link.
5905 \labelwidthstring 00.00.0000
5910 \begin_inset LatexCommand \index{-mpic14}
5916 Generate code for the Microchip PIC 14
5917 \begin_inset LatexCommand \index{PIC14}
5921 -bit processors (p16f84 and variants.
5922 In development, not complete).
5925 p16f627 p16f628 p16f84 p16f873 p16f877?
5927 \labelwidthstring 00.00.0000
5932 \begin_inset LatexCommand \index{-mpic16}
5938 Generate code for the Microchip PIC 16
5939 \begin_inset LatexCommand \index{PIC16}
5943 -bit processors (p18f452 and variants.
5944 In development, not complete).
5946 \labelwidthstring 00.00.0000
5952 Generate code for the Toshiba TLCS-900H
5953 \begin_inset LatexCommand \index{TLCS-900H}
5957 processor (Not maintained, not complete).
5959 \added_space_bottom bigskip \labelwidthstring 00.00.0000
5964 \begin_inset LatexCommand \index{-mxa51}
5970 Generate code for the Phillips XA51
5971 \begin_inset LatexCommand \index{XA51}
5975 processor (Not maintained, not complete).
5978 Preprocessor Options
5979 \begin_inset LatexCommand \index{Options preprocessor}
5984 \begin_inset LatexCommand \index{Preprocessor options}
5989 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5995 \labelwidthstring 00.00.0000
6000 \begin_inset LatexCommand \index{-I<path>}
6006 The additional location where the pre processor will look for <..h> or
6007 \begin_inset Quotes eld
6011 \begin_inset Quotes erd
6016 \labelwidthstring 00.00.0000
6021 \begin_inset LatexCommand \index{-D<macro[=value]>}
6027 Command line definition of macros.
6028 Passed to the preprocessor.
6030 \labelwidthstring 00.00.0000
6035 \begin_inset LatexCommand \index{-M}
6041 Tell the preprocessor to output a rule suitable for make describing the
6042 dependencies of each object file.
6043 For each source file, the preprocessor outputs one make-rule whose target
6044 is the object file name for that source file and whose dependencies are
6045 all the files `#include'd in it.
6046 This rule may be a single line or may be continued with `
6048 '-newline if it is long.
6049 The list of rules is printed on standard output instead of the preprocessed
6052 \begin_inset LatexCommand \index{-E}
6058 \labelwidthstring 00.00.0000
6063 \begin_inset LatexCommand \index{-C}
6069 Tell the preprocessor not to discard comments.
6070 Used with the `-E' option.
6072 \labelwidthstring 00.00.0000
6077 \begin_inset LatexCommand \index{-MM}
6088 Like `-M' but the output mentions only the user header files included with
6090 \begin_inset Quotes eld
6094 System header files included with `#include <file>' are omitted.
6096 \labelwidthstring 00.00.0000
6101 \begin_inset LatexCommand \index{-Aquestion(answer)}
6107 Assert the answer answer for question, in case it is tested with a preprocessor
6108 conditional such as `#if #question(answer)'.
6109 `-A-' disables the standard assertions that normally describe the target
6112 \labelwidthstring 00.00.0000
6117 \begin_inset LatexCommand \index{-Umacro}
6123 Undefine macro macro.
6124 `-U' options are evaluated after all `-D' options, but before any `-include'
6125 and `-imacros' options.
6127 \labelwidthstring 00.00.0000
6132 \begin_inset LatexCommand \index{-dM}
6138 Tell the preprocessor to output only a list of the macro definitions that
6139 are in effect at the end of preprocessing.
6140 Used with the `-E' option.
6142 \labelwidthstring 00.00.0000
6147 \begin_inset LatexCommand \index{-dD}
6153 Tell the preprocessor to pass all macro definitions into the output, in
6154 their proper sequence in the rest of the output.
6156 \labelwidthstring 00.00.0000
6161 \begin_inset LatexCommand \index{-dN}
6172 Like `-dD' except that the macro arguments and contents are omitted.
6173 Only `#define name' is included in the output.
6175 \labelwidthstring 00.00.0000
6179 -pedantic-parse-number
6180 \begin_inset LatexCommand \index{-pedantic-parse-number}
6191 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6192 and the macro LO_B(3) gets expanded.
6193 See also #pragma pedantic_parse_number in section
6194 \begin_inset LatexCommand \ref{sec:Pragmas}
6200 Note: this functionality is not in conformance with standard!
6202 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6207 preprocessorOption[,preprocessorOption]
6210 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6215 Pass the preprocessorOption to the preprocessor
6220 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6225 SDCC uses an adapted version of the preprocessor
6229 of the GNU Compiler Collection
6230 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6239 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6243 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6248 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6256 \begin_inset LatexCommand \index{Options linker}
6261 \begin_inset LatexCommand \index{Linker options}
6267 \labelwidthstring 00.00.0000
6287 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6292 \begin_inset LatexCommand \index{-L -\/-lib-path}
6299 <absolute path to additional libraries> This option is passed to the linkage
6300 editor's additional libraries
6301 \begin_inset LatexCommand \index{Libraries}
6306 The path name must be absolute.
6307 Additional library files may be specified in the command line.
6308 See section Compiling programs for more details.
6310 \labelwidthstring 00.00.0000
6327 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6332 <Value> The start location of the external ram
6333 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6337 , default value is 0.
6338 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6348 -xram-loc 0x8000 or -
6360 \labelwidthstring 00.00.0000
6377 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6382 <Value> The start location of the code
6383 \begin_inset LatexCommand \index{code}
6387 segment, default value 0.
6388 Note when this option is used the interrupt vector table
6389 \begin_inset LatexCommand \index{interrupt vector table}
6393 is also relocated to the given address.
6394 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6404 -code-loc 0x8000 or -
6416 \labelwidthstring 00.00.0000
6433 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6438 <Value> By default the stack
6439 \begin_inset LatexCommand \index{stack}
6443 is placed after the data segment.
6444 Using this option the stack can be placed anywhere in the internal memory
6446 The value entered can be in Hexadecimal or Decimal format, e.g.
6457 -stack-loc 0x20 or -
6468 Since the sp register is incremented before a push or call, the initial
6469 sp will be set to one byte prior the provided value.
6470 The provided value should not overlap any other memory areas such as used
6471 register banks or the data segment and with enough space for the current
6489 \begin_inset LatexCommand \index{-\/-pack-iram}
6493 option (which is now a default setting) will override this setting, so
6494 you should also specify the
6510 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6514 option if you need to manually place the stack.
6516 \labelwidthstring 00.00.0000
6533 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6538 <Value> By default the external stack
6539 \begin_inset LatexCommand \index{xstack}
6543 is placed after the pdata
6544 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6549 Using this option the xstack can be placed anywhere in the external memory
6551 The value entered can be in Hexadecimal or Decimal format, e.g.
6562 -xstack-loc 0x8000 or -
6573 The provided value should not overlap any other memory areas such as the
6574 pdata or xdata segment and with enough space for the current application.
6576 \labelwidthstring 00.00.0000
6593 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6598 <Value> The start location of the internal ram data
6599 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6604 The value entered can be in Hexadecimal or Decimal format, eg.
6626 (By default, the start location of the internal ram data segment is set
6627 as low as possible in memory, taking into account the used register banks
6628 and the bit segment at address 0x20.
6629 For example if register banks 0 and 1 are used without bit variables, the
6630 data segment will be set, if -
6640 -data-loc is not used, to location 0x10.)
6642 \labelwidthstring 00.00.0000
6659 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6664 <Value> The start location of the indirectly addressable internal ram
6665 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6669 of the 8051, default value is 0x80.
6670 The value entered can be in Hexadecimal or Decimal format, eg.
6681 -idata-loc 0x88 or -
6693 \labelwidthstring 00.00.0000
6710 <Value> The start location of the bit
6711 \begin_inset LatexCommand \index{bit}
6715 addressable internal ram of the 8051.
6721 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6724 \labelwidthstring 00.00.0000
6739 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6748 The linker output (final object code) is in Intel Hex format.
6749 \begin_inset LatexCommand \index{Intel hex format}
6753 This is the default option.
6754 The format itself is documented in the documentation of srecord
6755 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6761 \labelwidthstring 00.00.0000
6776 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6785 The linker output (final object code) is in Motorola S19 format
6786 \begin_inset LatexCommand \index{Motorola S19 format}
6791 The format itself is documented in the documentation of srecord.
6793 \labelwidthstring 00.00.0000
6808 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6813 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6822 The linker output (final object code) is in ELF format
6823 \begin_inset LatexCommand \index{ELF format}
6828 (Currently only supported for the HC08
6829 \begin_inset LatexCommand \index{HC08}
6835 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6840 linkOption[,linkOption]
6843 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6848 Pass the linkOption to the linker.
6849 If a bootloader is used an option like
6850 \begin_inset Quotes sld
6855 \begin_inset Quotes srd
6858 would be typical to set the start of the code segment.
6859 See also #pragma constseg and #pragma codeseg in section
6860 \begin_inset LatexCommand \ref{sec:Pragmas}
6865 File sdcc/as/doc/asxhtm.html has more on linker options.
6869 \begin_inset LatexCommand \index{Options MCS51}
6874 \begin_inset LatexCommand \index{MCS51 options}
6880 \labelwidthstring 00.00.0000
6895 \begin_inset LatexCommand \index{-\/-model-small}
6906 Generate code for Small Model programs, see section Memory Models for more
6908 This is the default model.
6910 \labelwidthstring 00.00.0000
6925 \begin_inset LatexCommand \index{-\/-model-medium}
6931 Generate code for Medium model programs, see section Memory Models for
6933 If this option is used all source files in the project have to be compiled
6935 It must also be used when invoking the linker.
6937 \labelwidthstring 00.00.0000
6952 \begin_inset LatexCommand \index{-\/-model-large}
6958 Generate code for Large model programs, see section Memory Models for more
6960 If this option is used all source files in the project have to be compiled
6962 It must also be used when invoking the linker.
6964 \labelwidthstring 00.00.0000
6979 \begin_inset LatexCommand \index{-\/-xstack}
6985 Uses a pseudo stack in the pdata
6986 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6990 area (usually the first 256 bytes in the external ram) for allocating variables
6991 and passing parameters.
6993 \begin_inset LatexCommand \ref{sub:External-Stack}
6998 External Stack for more details.
7000 \labelwidthstring 00.00.0000
7018 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7022 Causes the linker to check if the internal ram usage is within limits of
7025 \labelwidthstring 00.00.0000
7043 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7047 Causes the linker to check if the external ram usage is within limits of
7050 \labelwidthstring 00.00.0000
7068 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7072 Causes the linker to check if the code memory usage is within limits of
7075 \labelwidthstring 00.00.0000
7093 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7097 Causes the linker to check if there is at minimum <Value> bytes for stack.
7099 \labelwidthstring 00.00.0000
7117 \begin_inset LatexCommand \index{-\/-pack-iram}
7121 Causes the linker to use unused register banks for data variables and pack
7122 data, idata and stack together.
7123 This is the default now.
7125 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7143 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7147 Causes the linker to use old style for allocating memory areas.
7150 DS390 / DS400 Options
7151 \begin_inset LatexCommand \index{Options DS390}
7156 \begin_inset LatexCommand \index{DS390}
7162 \labelwidthstring 00.00.0000
7179 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7189 Generate 24-bit flat mode code.
7190 This is the one and only that the ds390 code generator supports right now
7191 and is default when using
7196 See section Memory Models for more details.
7198 \labelwidthstring 00.00.0000
7213 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7219 disable interrupts during ESP:SP updates.
7221 \labelwidthstring 00.00.0000
7238 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7242 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7243 This is the one and only that the ds390 code generator supports right now
7244 and is default when using
7249 In this mode, the stack is located in the lower 1K of the internal RAM,
7250 which is mapped to 0x400000.
7251 Note that the support is incomplete, since it still uses a single byte
7252 as the stack pointer.
7253 This means that only the lower 256 bytes of the potential 1K stack space
7254 will actually be used.
7255 However, this does allow you to reclaim the precious 256 bytes of low RAM
7256 for use for the DATA and IDATA segments.
7257 The compiler will not generate any code to put the processor into 10 bit
7259 It is important to ensure that the processor is in this mode before calling
7260 any re-entrant functions compiled with this option.
7261 In principle, this should work with the
7274 \begin_inset LatexCommand \index{-\/-stack-auto}
7280 option, but that has not been tested.
7281 It is incompatible with the
7294 \begin_inset LatexCommand \index{-\/-xstack}
7301 It also only makes sense if the processor is in 24 bit contiguous addressing
7314 -model-flat24 option
7318 \labelwidthstring 00.00.0000
7333 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7339 insert call to function __stack_probe at each function prologue.
7341 \labelwidthstring 00.00.0000
7356 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7362 <nnnn> LibraryID used in -mTININative.
7365 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7380 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7386 generate code for DS390 Arithmetic Accelerator.
7391 \begin_inset LatexCommand \index{Options Z80}
7396 \begin_inset LatexCommand \index{Z80}
7402 \labelwidthstring 00.00.0000
7419 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7429 Force a called function to always save BC.
7431 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7448 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7452 When linking, skip the standard crt0.o object file.
7453 You must provide your own crt0.o for your system when linking.
7457 Optimization Options
7458 \begin_inset LatexCommand \index{Options optimization}
7463 \begin_inset LatexCommand \index{Optimization options}
7469 \labelwidthstring 00.00.0000
7484 \begin_inset LatexCommand \index{-\/-nogcse}
7490 Will not do global subexpression elimination, this option may be used when
7491 the compiler creates undesirably large stack/data spaces to store compiler
7501 \begin_inset LatexCommand \index{sloc (spill location)}
7506 A warning message will be generated when this happens and the compiler
7507 will indicate the number of extra bytes it allocated.
7508 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7510 \begin_inset LatexCommand \index{\#pragma nogcse}
7514 can be used to turn off global subexpression elimination
7515 \begin_inset LatexCommand \index{Subexpression elimination}
7519 for a given function only.
7521 \labelwidthstring 00.00.0000
7536 \begin_inset LatexCommand \index{-\/-noinvariant}
7542 Will not do loop invariant optimizations, this may be turned off for reasons
7543 explained for the previous option.
7544 For more details of loop optimizations performed see Loop Invariants in
7546 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7551 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7553 \begin_inset LatexCommand \index{\#pragma noinvariant}
7557 can be used to turn off invariant optimizations for a given function only.
7559 \labelwidthstring 00.00.0000
7574 \begin_inset LatexCommand \index{-\/-noinduction}
7580 Will not do loop induction optimizations, see section strength reduction
7582 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7584 \begin_inset LatexCommand \index{\#pragma noinduction}
7588 can be used to turn off induction optimizations for a given function only.
7590 \labelwidthstring 00.00.0000
7605 \begin_inset LatexCommand \index{-\/-nojtbound}
7616 Will not generate boundary condition check when switch statements
7617 \begin_inset LatexCommand \index{switch statement}
7621 are implemented using jump-tables.
7623 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7628 Switch Statements for more details.
7629 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7631 \begin_inset LatexCommand \index{\#pragma nojtbound}
7635 can be used to turn off boundary checking for jump tables for a given function
7638 \labelwidthstring 00.00.0000
7653 \begin_inset LatexCommand \index{-\/-noloopreverse}
7662 Will not do loop reversal
7663 \begin_inset LatexCommand \index{Loop reversing}
7669 \labelwidthstring 00.00.0000
7686 \begin_inset LatexCommand \index{-\/-nolabelopt }
7690 Will not optimize labels (makes the dumpfiles more readable).
7692 \labelwidthstring 00.00.0000
7707 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7713 Will not memcpy initialized data from code space into xdata space.
7714 This saves a few bytes in code space if you don't have initialized data
7715 \begin_inset LatexCommand \index{Variable initialization}
7721 \labelwidthstring 00.00.0000
7736 \begin_inset LatexCommand \index{-\/-nooverlay}
7742 The compiler will not overlay parameters and local variables of any function,
7743 see section Parameters and local variables for more details.
7745 \labelwidthstring 00.00.0000
7760 \begin_inset LatexCommand \index{-\/-no-peep}
7766 Disable peep-hole optimization with built-in rules.
7768 \labelwidthstring 00.00.0000
7785 \begin_inset LatexCommand \index{-\/-peep-file}
7790 <filename> This option can be used to use additional rules to be used by
7791 the peep hole optimizer.
7793 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7798 Peep Hole optimizations for details on how to write these rules.
7800 \labelwidthstring 00.00.0000
7815 \begin_inset LatexCommand \index{-\/-peep-asm}
7821 Pass the inline assembler code through the peep hole optimizer.
7822 This can cause unexpected changes to inline assembler code, please go through
7823 the peephole optimizer
7824 \begin_inset LatexCommand \index{Peephole optimizer}
7828 rules defined in the source file tree '<target>/peeph.def' before using
7831 \labelwidthstring 00.00.0000
7846 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7852 The compiler will optimize code generation towards fast code, possibly
7853 at the expense of code size.
7855 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7870 \begin_inset LatexCommand \index{-\/-opt-code-size}
7876 The compiler will optimize code generation towards compact code, possibly
7877 at the expense of code speed.
7881 \begin_inset LatexCommand \index{Options other}
7887 \labelwidthstring 00.00.0000
7903 \begin_inset LatexCommand \index{-\/-compile-only}
7908 \begin_inset LatexCommand \index{-c -\/-compile-only}
7914 will compile and assemble the source, but will not call the linkage editor.
7916 \labelwidthstring 00.00.0000
7935 \begin_inset LatexCommand \index{-\/-c1mode}
7941 reads the preprocessed source from standard input and compiles it.
7942 The file name for the assembler output must be specified using the -o option.
7944 \labelwidthstring 00.00.0000
7949 \begin_inset LatexCommand \index{-E}
7955 Run only the C preprocessor.
7956 Preprocess all the C source files specified and output the results to standard
7959 \labelwidthstring 00.00.0000
7965 \begin_inset LatexCommand \index{-o <path/file>}
7971 The output path resp.
7972 file where everything will be placed.
7973 If the parameter is a path, it must have a trailing slash (or backslash
7974 for the Windows binaries) to be recognized as a path.
7977 \labelwidthstring 00.00.0000
7992 \begin_inset LatexCommand \index{-\/-stack-auto}
8003 All functions in the source file will be compiled as
8008 \begin_inset LatexCommand \index{reentrant}
8013 the parameters and local variables will be allocated on the stack
8014 \begin_inset LatexCommand \index{stack}
8020 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8024 Parameters and Local Variables for more details.
8025 If this option is used all source files in the project should be compiled
8027 It automatically implies --int-long-reent and --float-reent.
8030 \labelwidthstring 00.00.0000
8045 \begin_inset LatexCommand \index{-\/-callee-saves}
8049 function1[,function2][,function3]....
8052 The compiler by default uses a caller saves convention for register saving
8053 across function calls, however this can cause unnecessary register pushing
8054 & popping when calling small functions from larger functions.
8055 This option can be used to switch the register saving convention for the
8056 function names specified.
8057 The compiler will not save registers when calling these functions, no extra
8058 code will be generated at the entry & exit (function prologue
8061 \begin_inset LatexCommand \index{function prologue}
8070 \begin_inset LatexCommand \index{function epilogue}
8076 ) for these functions to save & restore the registers used by these functions,
8077 this can SUBSTANTIALLY reduce code & improve run time performance of the
8079 In the future the compiler (with inter procedural analysis) will be able
8080 to determine the appropriate scheme to use for each function call.
8081 DO NOT use this option for built-in functions such as _mulint..., if this
8082 option is used for a library function the appropriate library function
8083 needs to be recompiled with the same option.
8084 If the project consists of multiple source files then all the source file
8085 should be compiled with the same -
8095 -callee-saves option string.
8096 Also see #pragma\SpecialChar ~
8098 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8104 \labelwidthstring 00.00.0000
8119 \begin_inset LatexCommand \index{-\/-debug}
8128 When this option is used the compiler will generate debug information.
8129 The debug information collected in a file with .cdb extension can be used
8131 For more information see documentation for SDCDB.
8132 Another file with no extension contains debug information in AOMF or AOMF51
8133 \begin_inset LatexCommand \index{AOMF, AOMF51}
8137 format which is commonly used by third party tools.
8139 \labelwidthstring 00.00.0000
8144 \begin_inset LatexCommand \index{-S}
8155 Stop after the stage of compilation proper; do not assemble.
8156 The output is an assembler code file for the input file specified.
8158 \labelwidthstring 00.00.0000
8173 \begin_inset LatexCommand \index{-\/-int-long-reent}
8179 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8180 Note by default these libraries are compiled as non-reentrant.
8181 See section Installation for more details.
8183 \labelwidthstring 00.00.0000
8198 \begin_inset LatexCommand \index{-\/-cyclomatic}
8207 This option will cause the compiler to generate an information message for
8208 each function in the source file.
8209 The message contains some
8213 information about the function.
8214 The number of edges and nodes the compiler detected in the control flow
8215 graph of the function, and most importantly the
8217 cyclomatic complexity
8218 \begin_inset LatexCommand \index{Cyclomatic complexity}
8224 see section on Cyclomatic Complexity for more details.
8226 \labelwidthstring 00.00.0000
8241 \begin_inset LatexCommand \index{-\/-float-reent}
8247 Floating point library is compiled as reentrant
8248 \begin_inset LatexCommand \index{reentrant}
8253 See section Installation for more details.
8255 \labelwidthstring 00.00.0000
8270 \begin_inset LatexCommand \index{-\/-main-return}
8276 This option can be used if the code generated is called by a monitor program
8277 or if the main routine includes an endless loop.
8278 This option results in slightly smaller code and saves two bytes of stack
8280 The return from the 'main'
8281 \begin_inset LatexCommand \index{main return}
8285 function will return to the function calling main.
8286 The default setting is to lock up i.e.
8293 \labelwidthstring 00.00.0000
8308 \begin_inset LatexCommand \index{-\/-nostdinc}
8314 This will prevent the compiler from passing on the default include path
8315 to the preprocessor.
8317 \labelwidthstring 00.00.0000
8332 \begin_inset LatexCommand \index{-\/-nostdlib}
8338 This will prevent the compiler from passing on the default library
8339 \begin_inset LatexCommand \index{Libraries}
8345 \labelwidthstring 00.00.0000
8360 \begin_inset LatexCommand \index{-\/-verbose}
8366 Shows the various actions the compiler is performing.
8368 \labelwidthstring 00.00.0000
8373 \begin_inset LatexCommand \index{-V}
8379 Shows the actual commands the compiler is executing.
8381 \labelwidthstring 00.00.0000
8396 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8402 Hides your ugly and inefficient c-code from the asm file, so you can always
8403 blame the compiler :)
8405 \labelwidthstring 00.00.0000
8420 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8426 Will not include peep-hole comments in the generated files.
8428 \labelwidthstring 00.00.0000
8443 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8449 Include i-codes in the asm file.
8450 Sounds like noise but is most helpful for debugging the compiler itself.
8452 \labelwidthstring 00.00.0000
8467 \begin_inset LatexCommand \index{-\/-less-pedantic}
8473 Disable some of the more pedantic warnings
8474 \begin_inset LatexCommand \index{Warnings}
8478 (jwk burps: please be more specific here, please!).
8480 \labelwidthstring 00.00.0000
8494 -disable-warning\SpecialChar ~
8496 \begin_inset LatexCommand \index{-\/-disable-warning}
8502 Disable specific warning with number <nnnn>.
8504 \labelwidthstring 00.00.0000
8519 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8525 Display the directories in the compiler's search path
8527 \labelwidthstring 00.00.0000
8542 \begin_inset LatexCommand \index{-\/-vc}
8548 Display errors and warnings using MSVC style, so you can use SDCC with
8549 the visual studio IDE
8550 \begin_inset LatexCommand \index{IDE}
8555 With SDCC both offering a GCC-like (the default) and a MSVC-like
8556 \begin_inset LatexCommand \index{MSVC output style}
8560 output style, integration into most programming editors should be straightforwa
8563 \labelwidthstring 00.00.0000
8578 \begin_inset LatexCommand \index{-\/-use-stdout}
8584 Send errors and warnings to stdout instead of stderr.
8586 \labelwidthstring 00.00.0000
8591 asmOption[,asmOption]
8594 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8599 Pass the asmOption to the assembler
8600 \begin_inset LatexCommand \index{Options assembler}
8605 \begin_inset LatexCommand \index{Assembler options}
8610 See file sdcc/as/doc/asxhtm.html for assembler options.cd
8612 \labelwidthstring 00.00.0000
8627 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8633 Generally follow the C89 standard, but allow SDCC features that conflict
8634 with the standard (default).
8636 \labelwidthstring 00.00.0000
8651 \begin_inset LatexCommand \index{-\/-std-c89}
8657 Follow the C89 standard and disable SDCC features that conflict with the
8660 \labelwidthstring 00.00.0000
8675 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8681 Generally follow the C99 standard, but allow SDCC features that conflict
8682 with the standard (incomplete support).
8684 \labelwidthstring 00.00.0000
8699 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8705 Follow the C99 standard and disable SDCC features that conflict with the
8706 standard (incomplete support).
8708 \labelwidthstring 00.00.0000
8725 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8730 <Name> The name to be used for the code
8731 \begin_inset LatexCommand \index{code}
8735 segment, default CSEG.
8736 This is useful if you need to tell the compiler to put the code in a special
8737 segment so you can later on tell the linker to put this segment in a special
8739 Can be used for instance when using bank switching to put the code in a
8742 \labelwidthstring 00.00.0000
8759 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8764 <Name> The name to be used for the const
8765 \begin_inset LatexCommand \index{code}
8769 segment, default CONST.
8770 This is useful if you need to tell the compiler to put the const data in
8771 a special segment so you can later on tell the linker to put this segment
8772 in a special place in memory.
8773 Can be used for instance when using bank switching to put the const data
8776 \labelwidthstring 00.00.0000
8790 -fdollars-in-identifiers
8791 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
8797 Permit '$' as an identifier character
8799 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8811 a SDCC compiler option but if you want
8815 warnings you can use a separate tool dedicated to syntax checking like
8817 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8822 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8827 \begin_inset LatexCommand \url{http://www.splint.org}
8832 To make your source files parseable by splint you will have to include
8838 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8842 in your source file and add brackets around extended keywords (like
8845 \begin_inset Quotes sld
8858 \begin_inset Quotes srd
8866 \begin_inset Quotes sld
8869 __interrupt\SpecialChar ~
8871 \begin_inset Quotes srd
8879 Splint has an excellent on line manual at
8880 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8884 and it's capabilities go beyond pure syntax checking.
8885 You'll need to tell splint the location of SDCC's include files so a typical
8886 command line could look like this:
8890 splint\SpecialChar ~
8892 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8897 Intermediate Dump Options
8898 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8903 \begin_inset LatexCommand \index{Options intermediate dump}
8908 \begin_inset LatexCommand \index{Intermediate dump options}
8915 The following options are provided for the purpose of retargetting and debugging
8917 They provide a means to dump the intermediate code (iCode
8918 \begin_inset LatexCommand \index{iCode}
8922 ) generated by the compiler in human readable form at various stages of
8923 the compilation process.
8924 More on iCodes see chapter
8925 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8930 \begin_inset Quotes srd
8933 The anatomy of the compiler
8934 \begin_inset Quotes srd
8939 \labelwidthstring 00.00.0000
8954 \begin_inset LatexCommand \index{-\/-dumpraw}
8960 This option will cause the compiler to dump the intermediate code into
8963 <source filename>.dumpraw
8965 just after the intermediate code has been generated for a function, i.e.
8966 before any optimizations are done.
8968 \begin_inset LatexCommand \index{Basic blocks}
8972 at this stage ordered in the depth first number, so they may not be in
8973 sequence of execution.
8975 \labelwidthstring 00.00.0000
8990 \begin_inset LatexCommand \index{-\/-dumpgcse}
8996 Will create a dump of iCode's, after global subexpression elimination
8997 \begin_inset LatexCommand \index{Global subexpression elimination}
9003 <source filename>.dumpgcse.
9005 \labelwidthstring 00.00.0000
9020 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9026 Will create a dump of iCode's, after deadcode elimination
9027 \begin_inset LatexCommand \index{Dead-code elimination}
9033 <source filename>.dumpdeadcode.
9035 \labelwidthstring 00.00.0000
9050 \begin_inset LatexCommand \index{-\/-dumploop}
9059 Will create a dump of iCode's, after loop optimizations
9060 \begin_inset LatexCommand \index{Loop optimization}
9066 <source filename>.dumploop.
9068 \labelwidthstring 00.00.0000
9083 \begin_inset LatexCommand \index{-\/-dumprange}
9092 Will create a dump of iCode's, after live range analysis
9093 \begin_inset LatexCommand \index{Live range analysis}
9099 <source filename>.dumprange.
9101 \labelwidthstring 00.00.0000
9116 \begin_inset LatexCommand \index{-\/-dumlrange}
9122 Will dump the life ranges
9123 \begin_inset LatexCommand \index{Live range analysis}
9129 \labelwidthstring 00.00.0000
9144 \begin_inset LatexCommand \index{-\/-dumpregassign}
9153 Will create a dump of iCode's, after register assignment
9154 \begin_inset LatexCommand \index{Register assignment}
9160 <source filename>.dumprassgn.
9162 \labelwidthstring 00.00.0000
9177 \begin_inset LatexCommand \index{-\/-dumplrange}
9183 Will create a dump of the live ranges of iTemp's
9185 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9200 \begin_inset LatexCommand \index{-\/-dumpall}
9211 Will cause all the above mentioned dumps to be created.
9214 Redirecting output on Windows Shells
9216 \added_space_bottom bigskip
9217 By default SDCC writes it's error messages to
9218 \begin_inset Quotes sld
9222 \begin_inset Quotes srd
9226 To force all messages to
9227 \begin_inset Quotes sld
9231 \begin_inset Quotes srd
9255 \begin_inset LatexCommand \index{-\/-use-stdout}
9260 Additionally, if you happen to have visual studio installed in your windows
9261 machine, you can use it to compile your sources using a custom build and
9277 \begin_inset LatexCommand \index{-\/-vc}
9282 Something like this should work:
9326 -model-large -c $(InputPath)
9329 Environment variables
9330 \begin_inset LatexCommand \index{Environment variables}
9337 SDCC recognizes the following environment variables:
9339 \labelwidthstring 00.00.0000
9344 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9350 SDCC installs a signal handler
9351 \begin_inset LatexCommand \index{signal handler}
9355 to be able to delete temporary files after an user break (^C) or an exception.
9356 If this environment variable is set, SDCC won't install the signal handler
9357 in order to be able to debug SDCC.
9359 \labelwidthstring 00.00.0000
9366 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9372 Path, where temporary files will be created.
9373 The order of the variables is the search order.
9374 In a standard *nix environment these variables are not set, and there's
9375 no need to set them.
9376 On Windows it's recommended to set one of them.
9378 \labelwidthstring 00.00.0000
9383 \begin_inset LatexCommand \index{SDCC\_HOME}
9390 \begin_inset LatexCommand \ref{sub:Install-paths}
9396 \begin_inset Quotes sld
9400 \begin_inset Quotes srd
9405 \labelwidthstring 00.00.0000
9410 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9417 \begin_inset LatexCommand \ref{sub:Search-Paths}
9423 \begin_inset Quotes sld
9427 \begin_inset Quotes srd
9432 \labelwidthstring 00.00.0000
9437 \begin_inset LatexCommand \index{SDCC\_LIB}
9444 \begin_inset LatexCommand \ref{sub:Search-Paths}
9450 \begin_inset Quotes sld
9454 \begin_inset Quotes srd
9459 \added_space_bottom bigskip
9460 There are some more environment variables recognized by SDCC, but these
9461 are solely used for debugging purposes.
9462 They can change or disappear very quickly, and will never be documented.
9465 Storage Class Language Extensions
9468 MCS51/DS390 Storage Class
9469 \begin_inset LatexCommand \index{Storage class}
9476 In addition to the ANSI storage classes SDCC allows the following MCS51
9477 specific storage classes:
9478 \layout Subsubsection
9481 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9486 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9491 \begin_inset LatexCommand \index{near (storage class)}
9496 \begin_inset LatexCommand \index{\_\_near (storage class)}
9507 storage class for the Small Memory model (
9515 or the more ANSI-C compliant forms
9523 can be used synonymously).
9524 Variables declared with this storage class will be allocated in the directly
9525 addressable portion of the internal RAM of a 8051, e.g.:
9530 __data unsigned char test_data;
9533 Writing 0x01 to this variable generates the assembly code:
9538 75*00 01\SpecialChar ~
9544 \layout Subsubsection
9547 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9552 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9557 \begin_inset LatexCommand \index{far (storage class)}
9562 \begin_inset LatexCommand \index{\_\_far (storage class)}
9569 Variables declared with this storage class will be placed in the external
9575 storage class for the Large Memory model, e.g.:
9580 __xdata unsigned char test_xdata;
9583 Writing 0x01 to this variable generates the assembly code:
9588 90s00r00\SpecialChar ~
9617 \layout Subsubsection
9620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9632 Variables declared with this storage class will be allocated into the indirectly
9633 addressable portion of the internal ram of a 8051, e.g.:
9638 __idata unsigned char test_idata;
9641 Writing 0x01 to this variable generates the assembly code:
9670 Please note, the first 128 byte of idata physically access the same RAM
9672 The original 8051 had 128 byte idata memory, nowadays most devices have
9673 256 byte idata memory.
9675 \begin_inset LatexCommand \index{stack}
9679 is located in idata memory.
9680 \layout Subsubsection
9683 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9688 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9695 Paged xdata access is just as straightforward as using the other addressing
9697 It is typically located at the start of xdata and has a maximum size of
9699 The following example writes 0x01 to the pdata variable.
9700 Please note, pdata access physically accesses xdata memory.
9701 The high byte of the address is determined by port P2
9702 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9706 (or in case of some 8051 variants by a separate Special Function Register,
9708 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9717 storage class for the Medium Memory model, e.g.:
9722 __pdata unsigned char test_pdata;
9725 Writing 0x01 to this variable generates the assembly code:
9769 \begin_inset LatexCommand \index{-\/-xstack}
9773 option is used the pdata memory area is followed by the xstack memory area
9774 and the sum of their sizes is limited to 256 bytes.
9775 \layout Subsubsection
9778 \begin_inset LatexCommand \index{code}
9783 \begin_inset LatexCommand \index{\_\_code}
9790 'Variables' declared with this storage class will be placed in the code
9796 __code unsigned char test_code;
9799 Read access to this variable generates the assembly code:
9804 90s00r6F\SpecialChar ~
9807 mov dptr,#_test_code
9836 indexed arrays of characters in code memory can be accessed efficiently:
9841 __code char test_array[] = {'c','h','e','a','p'};
9844 Read access to this array using an 8-bit unsigned index generates the assembly
9861 90s00r41\SpecialChar ~
9864 mov dptr,#_test_array
9879 \layout Subsubsection
9882 \begin_inset LatexCommand \index{bit}
9887 \begin_inset LatexCommand \index{\_\_bit}
9894 This is a data-type and a storage class specifier.
9895 When a variable is declared as a bit, it is allocated into the bit addressable
9896 memory of 8051, e.g.:
9904 Writing 1 to this variable generates the assembly code:
9920 The bit addressable memory consists of 128 bits which are located from 0x20
9921 to 0x2f in data memory.
9924 Apart from this 8051 specific storage class most architectures support ANSI-C
9926 \begin_inset LatexCommand \index{bitfields}
9936 Not really meant as examples, but nevertheless showing what bitfields are
9937 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9941 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9942 signed modifier are implemented as unsigned.
9943 \layout Subsubsection
9946 \begin_inset LatexCommand \index{sfr}
9951 \begin_inset LatexCommand \index{\_\_sfr}
9956 \begin_inset LatexCommand \index{sfr16}
9961 \begin_inset LatexCommand \index{\_\_sfr16}
9966 \begin_inset LatexCommand \index{sfr32}
9971 \begin_inset LatexCommand \index{\_\_sfr32}
9976 \begin_inset LatexCommand \index{\_\_sbit}
9981 \begin_inset LatexCommand \index{sbit}
9988 Like the bit keyword,
9990 sfr / sfr16 / sfr32 / sbit
9992 signify both a data-type and storage class, they are used to describe the
10013 variables of a 8051, eg:
10019 \begin_inset LatexCommand \index{at}
10024 \begin_inset LatexCommand \index{\_\_at}
10028 (0x80) P0;\SpecialChar ~
10029 /* special function register P0 at location 0x80 */
10033 /* 16 bit special function register combination for timer 0
10037 with the high byte at location 0x8C and the low byte at location 0x8A */
10039 __sfr16 __at (0x8C8A) TMR0;
10044 \begin_inset LatexCommand \index{at}
10049 \begin_inset LatexCommand \index{\_\_at}
10053 (0xd7) CY;\SpecialChar ~
10055 \begin_inset LatexCommand \index{Flags}
10060 \begin_inset LatexCommand \index{Carry flag}
10067 Special function registers which are located on an address dividable by
10068 8 are bit-addressable, an
10072 addresses a specific bit within these sfr.
10074 16 Bit and 32 bit special function register combinations which require a
10075 certain access order are better not declared using
10084 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10085 this is not guaranteed.
10090 Please note, if you use a header file which was written for another compiler
10091 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10097 Specifically the syntax
10100 sfr P0 = 0x80;\SpecialChar ~
10107 by SDCC to an assignment of 0x80 to a variable called P0
10110 \begin_inset Marginal
10124 Nevertheless it is possible to write header files
10125 \begin_inset LatexCommand \index{Header files}
10130 \begin_inset LatexCommand \index{Include files}
10134 which can be shared among different compilers (see section
10135 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10141 \layout Subsubsection
10144 \begin_inset LatexCommand \index{Pointer}
10148 to MCS51/DS390 specific memory spaces
10151 SDCC allows (via language extensions) pointers to explicitly point to any
10152 of the memory spaces
10153 \begin_inset LatexCommand \index{Memory model}
10158 In addition to the explicit pointers, the compiler uses (by default) generic
10159 pointers which can be used to point to any of the memory spaces.
10163 Pointer declaration examples:
10168 /* pointer physically in internal ram pointing to object in external ram
10171 __xdata unsigned char * __data p;
10175 /* pointer physically in external ram pointing to object in internal ram
10178 __data unsigned char * __xdata p;
10182 /* pointer physically in code rom pointing to data in xdata space */
10184 __xdata unsigned char * __code p;
10188 /* pointer physically in code space pointing to data in code space */
10190 __code unsigned char * __code p;
10194 /* generic pointer physically located in xdata space */
10196 unsigned char * __xdata p;
10200 /* generic pointer physically located in default memory space */
10206 /* the following is a function pointer
10207 \begin_inset LatexCommand \index{function pointer}
10211 physically located in data space */
10213 char (* __data fp)(void);
10216 Well you get the idea.
10221 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10234 The highest order byte of the
10238 pointers contains the data space information.
10239 Assembler support routines are called whenever data is stored or retrieved
10245 These are useful for developing reusable library
10246 \begin_inset LatexCommand \index{Libraries}
10251 Explicitly specifying the pointer
10252 \begin_inset LatexCommand \index{pointer}
10256 type will generate the most efficient code.
10257 \layout Subsubsection
10259 Notes on MCS51 memory
10260 \begin_inset LatexCommand \index{MCS51 memory}
10267 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10268 RAM memory which is structured as follows:
10272 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10275 - Bytes 20-2F - 16 bytes to hold 128 bit
10276 \begin_inset LatexCommand \index{bit}
10282 - Bytes 30-7F - 80 bytes for general purpose use.
10287 Additionally some members of the MCS51 family may have up to 128 bytes of
10288 additional, indirectly addressable, internal RAM memory (
10293 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10298 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10303 Furthermore, some chips may have some built in external memory (
10308 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10313 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10317 ) which should not be confused with the internal, directly addressable RAM
10323 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10328 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10333 Sometimes this built in
10337 memory has to be activated before using it (you can probably find this
10338 information on the datasheet of the microcontroller your are using, see
10340 \begin_inset LatexCommand \ref{sub:Startup-Code}
10348 Normally SDCC will only use the first bank
10349 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10353 of registers (register bank 0), but it is possible to specify that other
10354 banks of registers (keyword
10361 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10366 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10372 ) should be used in interrupt
10373 \begin_inset LatexCommand \index{interrupt}
10378 \begin_inset LatexCommand \index{\_\_interrupt}
10383 By default, the compiler will place the stack after the last byte of allocated
10384 memory for variables.
10385 For example, if the first 2 banks of registers are used, and only four
10390 variables, it will position the base of the internal stack at address 20
10392 This implies that as the stack
10393 \begin_inset LatexCommand \index{stack}
10397 grows, it will use up the remaining register banks, and the 16 bytes used
10398 by the 128 bit variables, and 80 bytes for general purpose use.
10399 If any bit variables are used, the data variables will be placed in unused
10400 register banks and after the byte holding the last bit variable.
10401 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10406 variables will be placed starting from address 0x10 to 0x20 and continue
10419 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10423 to specify the start address of the
10438 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10442 to specify the size of the total internal RAM (
10456 By default the 8051 linker will place the stack after the last byte of (i)data
10469 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10473 allows you to specify the start of the stack, i.e.
10474 you could start it after any data in the general purpose area.
10475 If your microcontroller has additional indirectly addressable internal
10480 ) you can place the stack on it.
10481 You may also need to use -
10492 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10496 to set the start address of the external RAM (
10511 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10515 to specify its size.
10516 Same goes for the code memory, using -
10527 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10542 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10547 If in doubt, don't specify any options and see if the resulting memory
10548 layout is appropriate, then you can adjust it.
10550 \added_space_bottom bigskip
10551 The linker generates two files with memory allocation information.
10552 The first, with extension .map
10553 \begin_inset LatexCommand \index{<file>.map}
10557 shows all the variables and segments.
10558 The second with extension .mem
10559 \begin_inset LatexCommand \index{<file>.mem}
10563 shows the final memory layout.
10564 The linker will complain either if memory segments overlap, there is not
10565 enough memory, or there is not enough space for stack.
10566 If you get any linking warnings and/or errors related to stack or segments
10567 allocation, take a look at either the .map or .mem files to find out what
10569 The .mem file may even suggest a solution to the problem.
10572 Z80/Z180 Storage Class
10573 \begin_inset LatexCommand \index{Z80!Storage class}
10577 Language Extensions
10578 \layout Subsubsection
10581 \begin_inset LatexCommand \index{sfr}
10586 \begin_inset LatexCommand \index{\_\_sfr}
10590 (in/out to 8-bit addresses)
10594 \begin_inset LatexCommand \index{Z80}
10598 family has separate address spaces for memory and
10608 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10613 \begin_inset LatexCommand \index{Z80!I/O memory}
10618 \begin_inset LatexCommand \index{Z180!I/O memory}
10622 is accessed with special instructions, e.g.:
10627 sfr at 0x78 IoPort;\SpecialChar ~
10629 /* define a var in I/O space at 78h called IoPort */
10633 Writing 0x01 to this variable generates the assembly code:
10638 3E 01\SpecialChar ~
10646 D3 78\SpecialChar ~
10653 \layout Subsubsection
10656 \begin_inset LatexCommand \index{sfr}
10661 \begin_inset LatexCommand \index{\_\_sfr}
10665 (in/out to 16-bit addresses)
10672 is used to support 16 bit addresses in I/O memory e.g.:
10678 \begin_inset LatexCommand \index{at}
10683 \begin_inset LatexCommand \index{\_\_at}
10690 Writing 0x01 to this variable generates the assembly code:
10695 01 23 01\SpecialChar ~
10700 3E 01\SpecialChar ~
10708 ED 79\SpecialChar ~
10715 \layout Subsubsection
10718 \begin_inset LatexCommand \index{sfr}
10723 \begin_inset LatexCommand \index{\_\_sfr}
10727 (in0/out0 to 8 bit addresses on Z180
10728 \begin_inset LatexCommand \index{Z180}
10733 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10739 \added_space_bottom bigskip
10740 The compiler option -
10751 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10755 =180 (80) and a compiler #pragma\SpecialChar ~
10757 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10761 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10771 If you include the file z180.h this will be set automatically.
10775 \begin_inset LatexCommand \index{HC08!Storage class}
10779 Language Extensions
10780 \layout Subsubsection
10783 \begin_inset LatexCommand \index{data (hc08 storage class)}
10788 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10795 The data storage class declares a variable that resides in the first 256
10796 bytes of memory (the direct page).
10798 \begin_inset LatexCommand \index{HC08}
10802 is most efficient at accessing variables (especially pointers) stored here.
10803 \layout Subsubsection
10806 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10811 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10817 \added_space_bottom bigskip
10818 The xdata storage class declares a variable that can reside anywhere in
10820 This is the default if no storage class is specified.
10824 Absolute Addressing
10825 \begin_inset LatexCommand \index{Absolute addressing}
10832 Data items can be assigned an absolute address with the
10835 \begin_inset LatexCommand \index{at}
10840 \begin_inset LatexCommand \index{\_\_at}
10846 keyword, in addition to a storage class, e.g.:
10852 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10857 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10862 \begin_inset LatexCommand \index{at}
10867 \begin_inset LatexCommand \index{\_\_at}
10871 0x7ffe unsigned int chksum;
10874 or, better conforming to ISO/IEC 9899 C:
10879 __xdata __at (0x7ffe) unsigned int chksum;
10882 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10883 of the external ram.
10888 reserve any space for variables declared in this way
10889 \begin_inset Marginal
10900 (they are implemented with an equate in the assembler).
10901 Thus it is left to the programmer to make sure there are no overlaps with
10902 other variables that are declared without the absolute address.
10903 The assembler listing file (.lst
10904 \begin_inset LatexCommand \index{<file>.lst}
10908 ) and the linker output files (.rst
10909 \begin_inset LatexCommand \index{<file>.rst}
10914 \begin_inset LatexCommand \index{<file>.map}
10918 ) are good places to look for such overlaps.
10919 Variables with an absolute address are
10922 \begin_inset Marginal
10936 \begin_inset LatexCommand \index{Variable initialization}
10943 In case of memory mapped I/O devices the keyword
10947 has to be used to tell the compiler that accesses might not be removed:
10953 \begin_inset LatexCommand \index{volatile}
10958 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10963 \begin_inset LatexCommand \index{at}
10967 (0x8000) unsigned char PORTA_8255;
10970 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10975 \begin_inset LatexCommand \index{Aligned array}
10982 starts at a block (256 byte) boundary
10983 \begin_inset LatexCommand \index{block boundary}
10988 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10994 Absolute addresses can be specified for variables in all storage classes,
11001 \begin_inset LatexCommand \index{bit}
11006 \begin_inset LatexCommand \index{at}
11013 The above example will allocate the variable at offset 0x02 in the bit-addressab
11015 There is no real advantage to assigning absolute addresses to variables
11016 in this manner, unless you want strict control over all the variables allocated.
11017 One possible use would be to write hardware portable code.
11018 For example, if you have a routine that uses one or more of the microcontroller
11019 I/O pins, and such pins are different for two different hardwares, you
11020 can declare the I/O pins in your routine using:
11026 \begin_inset LatexCommand \index{volatile}
11030 __bit MOSI;\SpecialChar ~
11034 /* master out, slave in */
11036 extern volatile __bit MISO;\SpecialChar ~
11040 /* master in, slave out */
11042 extern volatile __bit MCLK;\SpecialChar ~
11050 /* Input and Output of a byte on a 3-wire serial bus.
11055 If needed adapt polarity of clock, polarity of data and bit order
11060 unsigned char spi_io(unsigned char out_byte)
11084 MOSI = out_byte & 0x80;
11114 /* _asm nop _endasm; */\SpecialChar ~
11122 /* for slow peripherals */
11173 Then, someplace in the code for the first hardware you would use
11179 \begin_inset LatexCommand \index{at}
11184 \begin_inset LatexCommand \index{\_\_at}
11188 (0x80) MOSI;\SpecialChar ~
11192 /* I/O port 0, bit 0 */
11194 __bit __at (0x81) MISO;\SpecialChar ~
11198 /* I/O port 0, bit 1 */
11200 __bit __at (0x82) MCLK;\SpecialChar ~
11204 /* I/O port 0, bit 2 */
11207 Similarly, for the second hardware you would use
11212 __bit __at (0x83) MOSI;\SpecialChar ~
11216 /* I/O port 0, bit 3 */
11218 __bit __at (0x91) MISO;\SpecialChar ~
11222 /* I/O port 1, bit 1 */
11225 \begin_inset LatexCommand \index{bit}
11229 __at (0x92) MCLK;\SpecialChar ~
11233 /* I/O port 1, bit 2 */
11235 \added_space_bottom bigskip
11236 and you can use the same hardware dependent routine without changes, as
11237 for example in a library.
11238 This is somehow similar to sbit, but only one absolute address has to be
11239 specified in the whole project.
11243 \begin_inset LatexCommand \index{Parameters}
11248 \begin_inset LatexCommand \index{function parameter}
11253 \begin_inset LatexCommand \index{local variables}
11258 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11265 Automatic (local) variables and parameters to functions can either be placed
11266 on the stack or in data-space.
11267 The default action of the compiler is to place these variables in the internal
11268 RAM (for small model) or external RAM (for large model).
11269 This in fact makes them similar to
11272 \begin_inset LatexCommand \index{static}
11278 so by default functions are non-reentrant
11279 \begin_inset LatexCommand \index{reentrant}
11288 They can be placed on the stack
11289 \begin_inset LatexCommand \index{stack}
11306 \begin_inset LatexCommand \index{-\/-stack-auto}
11314 #pragma\SpecialChar ~
11318 \begin_inset LatexCommand \index{\#pragma stackauto}
11325 \begin_inset LatexCommand \index{reentrant}
11331 keyword in the function declaration, e.g.:
11336 unsigned char foo(char i) __reentrant
11350 Since stack space on 8051 is limited, the
11368 option should be used sparingly.
11369 Note that the reentrant keyword just means that the parameters & local
11370 variables will be allocated to the stack, it
11374 mean that the function is register bank
11375 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11384 \begin_inset LatexCommand \index{local variables}
11388 can be assigned storage classes and absolute
11389 \begin_inset LatexCommand \index{Absolute addressing}
11398 unsigned char foo()
11406 __xdata unsigned char i;
11419 \begin_inset LatexCommand \index{at}
11423 (0x31) unsigned char j;
11435 In the above example the variable
11439 will be allocated in the external ram,
11443 in bit addressable space and
11462 or when a function is declared as
11466 this should only be done for static variables.
11470 \begin_inset LatexCommand \index{function parameter}
11474 however are not allowed any storage class
11475 \begin_inset LatexCommand \index{Storage class}
11479 , (storage classes for parameters will be ignored), their allocation is
11480 governed by the memory model in use, and the reentrancy options.
11483 It is however allowed to use bit parameters in reentrant functions and also
11484 non-static local bit variables are supported.
11485 Efficient use is limited to 8 semi-bitregisters in bit space.
11486 They are pushed and popped to stack
11487 \begin_inset LatexCommand \index{stack}
11491 as a single byte just like the normal registers.
11495 \begin_inset LatexCommand \label{sub:Overlaying}
11500 \begin_inset LatexCommand \index{Overlaying}
11508 \begin_inset LatexCommand \index{reentrant}
11512 functions SDCC will try to reduce internal ram space usage by overlaying
11513 parameters and local variables of a function (if possible).
11514 Parameters and local variables
11515 \begin_inset LatexCommand \index{local variables}
11519 of a function will be allocated to an overlayable segment if the function
11522 no other function calls and the function is non-reentrant and the memory
11524 \begin_inset LatexCommand \index{Memory model}
11531 If an explicit storage class
11532 \begin_inset LatexCommand \index{Storage class}
11536 is specified for a local variable, it will NOT be overlayed.
11539 Note that the compiler (not the linkage editor) makes the decision for overlayin
11541 Functions that are called from an interrupt service routine
11542 \begin_inset Marginal
11552 should be preceded by a #pragma\SpecialChar ~
11554 \begin_inset LatexCommand \index{\#pragma nooverlay}
11558 if they are not reentrant.
11561 Also note that the compiler does not do any processing of inline assembler
11562 code, so the compiler might incorrectly assign local variables and parameters
11563 of a function into the overlay segment if the inline assembler code calls
11564 other c-functions that might use the overlay.
11565 In that case the #pragma\SpecialChar ~
11566 nooverlay should be used.
11569 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11571 \begin_inset LatexCommand \index{Multiplication}
11576 \begin_inset LatexCommand \index{Division}
11580 will NOT be overlayed since these are implemented using external functions,
11589 \begin_inset LatexCommand \index{\#pragma nooverlay}
11595 void set_error(unsigned char errcd)
11611 void some_isr () __interrupt
11612 \begin_inset LatexCommand \index{interrupt}
11641 \added_space_bottom bigskip
11642 In the above example the parameter
11650 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11652 not present, this could cause unpredictable runtime behavior when called
11653 from an interrupt service routine.
11654 The #pragma\SpecialChar ~
11655 nooverlay ensures that the parameters and local variables for
11656 the function are NOT overlayed.
11659 Interrupt Service Routines
11660 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11667 General Information
11682 outines to be coded in C, with some extended keywords.
11687 void timer_isr (void) __interrupt (1) __using (1)
11701 The optional number following the
11704 \begin_inset LatexCommand \index{interrupt}
11709 \begin_inset LatexCommand \index{\_\_interrupt}
11715 keyword is the interrupt number this routine will service.
11716 When present, the compiler will insert a call to this routine in the interrupt
11718 \begin_inset LatexCommand \index{interrupt vector table}
11722 for the interrupt number specified.
11723 If you have multiple source files in your project, interrupt service routines
11724 can be present in any of them, but a prototype of the isr MUST be present
11725 or included in the file that contains the function
11730 The optional (8051 specific) keyword
11733 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11738 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11744 can be used to tell the compiler to use the specified register bank when
11745 generating code for this function.
11748 Interrupt service routines open the door for some very interesting bugs:
11749 \layout Subsubsection
11752 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11756 Common interrupt pitfall: variable not declared
11761 If an interrupt service routine changes variables which are accessed by
11762 other functions these variables have to be declared
11767 \begin_inset LatexCommand \index{volatile}
11773 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11778 \layout Subsubsection
11781 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11785 Common interrupt pitfall:
11790 If the access to these variables is not
11793 \begin_inset LatexCommand \index{atomic}
11800 the processor needs more than one instruction for the access and could
11801 be interrupted while accessing the variable) the interrupt must be disabled
11802 during the access to avoid inconsistent data.
11805 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11806 should be protected by disabling interrupts.
11807 You're not automatically on the safe side if you use 8 bit variables though.
11808 We need an example here: f.e.
11809 on the 8051 the harmless looking
11810 \begin_inset Quotes srd
11815 flags\SpecialChar ~
11820 \begin_inset Quotes sld
11829 \begin_inset Quotes srd
11834 flags\SpecialChar ~
11839 \begin_inset Quotes sld
11842 from within an interrupt routine might get lost if the interrupt occurs
11845 \begin_inset Quotes sld
11850 counter\SpecialChar ~
11855 \begin_inset Quotes srd
11858 is not atomic on the 8051 even if
11862 is located in data memory.
11864 Bugs like these are hard to reproduce and can cause a lot of trouble.
11866 \layout Subsubsection
11869 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11873 Common interrupt pitfall:
11878 The return address and the registers used in the interrupt service routine
11879 are saved on the stack
11880 \begin_inset LatexCommand \index{stack}
11884 so there must be sufficient stack space.
11885 If there isn't variables or registers (or even the return address itself)
11892 \begin_inset LatexCommand \index{stack overflow}
11896 is most likely to happen if the interrupt occurs during the
11897 \begin_inset Quotes sld
11901 \begin_inset Quotes srd
11904 subroutine when the stack is already in use for f.e.
11905 many return addresses.
11906 \layout Subsubsection
11909 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11913 Common interrupt pitfall:
11915 use of non-reentrant functions
11918 A special note here, int (16 bit) and long (32 bit) integer division
11919 \begin_inset LatexCommand \index{Division}
11924 \begin_inset LatexCommand \index{Multiplication}
11929 \begin_inset LatexCommand \index{Modulus}
11934 \begin_inset LatexCommand \index{Floating point support}
11938 operations are implemented using external support routines.
11939 If an interrupt service routine needs to do any of these operations then
11940 the support routines (as mentioned in a following section) will have to
11941 be recompiled using the
11954 \begin_inset LatexCommand \index{-\/-stack-auto}
11960 option and the source file will need to be compiled using the
11975 \begin_inset LatexCommand \index{-\/-int-long-reent}
11982 Note, the type promotion
11983 \begin_inset LatexCommand \index{type promotion}
11987 required by ANSI C can cause 16 bit routines to be used
11988 \begin_inset Marginal
11999 without the programmer being aware of it.
12003 (unsigned char)(tail-1)
12005 within the if clause in section
12006 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12012 \added_space_bottom bigskip
12013 Calling other functions from an interrupt service routine is not recommended,
12014 avoid it if possible.
12015 Note that when some function is called from an interrupt service routine
12016 it should be preceded by a #pragma\SpecialChar ~
12018 \begin_inset LatexCommand \index{\#pragma nooverlay}
12022 if it is not reentrant.
12023 Furthermore nonreentrant functions should not be called from the main program
12024 while the interrupt service routine might be active.
12025 They also must not be called from low priority interrupt service routines
12026 while a high priority interrupt service routine might be active.
12027 You could use semaphores or make the function
12031 if all parameters are passed in registers.
12034 \begin_inset LatexCommand \ref{sub:Overlaying}
12039 about Overlaying and section
12040 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12045 about Functions using private register banks.
12048 MCS51/DS390 Interrupt Service Routines
12052 \begin_inset LatexCommand \index{interrupt}
12056 numbers and the corresponding address & descriptions for the Standard 8051/8052
12058 SDCC will automatically adjust the
12059 \begin_inset LatexCommand \index{interrupt vector table}
12063 to the maximum interrupt number specified.
12069 \begin_inset Tabular
12070 <lyxtabular version="3" rows="9" columns="3">
12072 <column alignment="center" valignment="top" leftline="true" width="0in">
12073 <column alignment="left" valignment="top" leftline="true" width="0in">
12074 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12075 <row topline="true" bottomline="true">
12076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12101 <row topline="true">
12102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12127 <row topline="true">
12128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12153 <row topline="true">
12154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12179 <row topline="true">
12180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12205 <row topline="true">
12206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12231 <row topline="true">
12232 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12257 <row topline="true">
12258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12282 <row topline="true" bottomline="true">
12283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12316 If the interrupt service routine is defined without
12319 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12324 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12330 a register bank or with register bank 0 (
12334 0), the compiler will save the registers used by itself on the stack upon
12335 entry and restore them at exit, however if such an interrupt service routine
12336 calls another function then the entire register bank will be saved on the
12338 This scheme may be advantageous for small interrupt service routines which
12339 have low register usage.
12341 \added_space_bottom bigskip
12342 If the interrupt service routine is defined to be using a specific register
12347 & psw are saved and restored, if such an interrupt service routine calls
12348 another function (using another register bank) then the entire register
12349 bank of the called function will be saved on the stack
12350 \begin_inset LatexCommand \index{stack}
12355 This scheme is recommended for larger interrupt service routines.
12359 \begin_inset LatexCommand \index{HC08}
12363 Interrupt Service Routines
12365 \added_space_bottom bigskip
12366 Since the number of interrupts
12367 \begin_inset LatexCommand \index{HC08!interrupt}
12371 available is chip specific and the interrupt vector table always ends at
12372 the last byte of memory, the interrupt numbers corresponds to the interrupt
12373 vectors in reverse order of address.
12374 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12375 2 will use the interrupt vector at 0xfffa, and so on.
12376 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12377 this way; instead see section
12378 \begin_inset LatexCommand \ref{sub:Startup-Code}
12382 for details on customizing startup.
12385 Z80 Interrupt Service Routines
12389 \begin_inset LatexCommand \index{Z80}
12393 uses several different methods for determining the correct interrupt
12394 \begin_inset LatexCommand \index{Z80!interrupt}
12398 vector depending on the hardware implementation.
12399 Therefore, SDCC ignores the optional interrupt number and does not attempt
12400 to generate an interrupt vector table.
12403 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12404 instruction to return from the interrupt.
12405 To write an interrupt handler for the non-maskable interrupt, which needs
12406 a RETN instruction instead, add the
12415 void nmi_isr (void) critical interrupt
12428 \added_space_bottom bigskip
12429 However if you need to create a non-interruptable interrupt service routine
12430 you would also require the
12435 To distinguish between this and an nmi_isr you must provide an interrupt
12439 Enabling and Disabling Interrupts
12442 Critical Functions and Critical Statements
12445 A special keyword may be associated with a block or a function declaring
12451 SDCC will generate code to disable all interrupts
12452 \begin_inset LatexCommand \index{interrupt}
12456 upon entry to a critical function and restore the interrupt enable to the
12457 previous state before returning.
12458 Nesting critical functions will need one additional byte on the stack
12459 \begin_inset LatexCommand \index{stack}
12468 int foo () __critical
12469 \begin_inset LatexCommand \index{critical}
12474 \begin_inset LatexCommand \index{\_\_critical}
12499 The critical attribute maybe used with other attributes like
12509 may also be used to disable interrupts more locally:
12517 More than one statement could have been included in the block.
12520 Enabling and Disabling Interrupts directly
12524 \begin_inset LatexCommand \index{interrupt}
12528 can also be disabled and enabled directly (8051):
12533 EA = 0;\SpecialChar ~
12596 EA = 1;\SpecialChar ~
12663 On other architectures which have seperate opcodes for enabling and disabling
12664 interrupts you might want to make use of defines with inline assembly
12665 \begin_inset LatexCommand \index{Assembler routines}
12670 \begin_inset LatexCommand \index{HC08!interrupt}
12680 \begin_inset LatexCommand \index{\_asm}
12689 \begin_inset LatexCommand \index{\_endasm}
12698 #define SEI _asm\SpecialChar ~
12710 Note: it is sometimes sufficient to disable only a specific interrupt source
12712 a timer or serial interrupt by manipulating an
12715 \begin_inset LatexCommand \index{interrupt mask}
12725 Usually the time during which interrupts are disabled should be kept as
12727 This minimizes both
12732 \begin_inset LatexCommand \index{interrupt latency}
12736 (the time between the occurrence of the interrupt and the execution of
12737 the first code in the interrupt routine) and
12742 \begin_inset LatexCommand \index{interrupt jitter}
12746 (the difference between the shortest and the longest interrupt latency).
12747 These really are something different, f.e.
12748 a serial interrupt has to be served before its buffer overruns so it cares
12749 for the maximum interrupt latency, whereas it does not care about jitter.
12750 On a loudspeaker driven via a digital to analog converter which is fed
12751 by an interrupt a latency of a few milliseconds might be tolerable, whereas
12752 a much smaller jitter will be very audible.
12755 You can reenable interrupts within an interrupt routine and on some architecture
12756 s you can make use of two (or more) levels of
12758 interrupt priorities
12761 \begin_inset LatexCommand \index{interrupt priority}
12766 On some architectures which don't support interrupt priorities these can
12767 be implemented by manipulating the interrupt mask and reenabling interrupts
12768 within the interrupt routine.
12769 Check there is sufficient space on the stack
12770 \begin_inset LatexCommand \index{stack}
12774 and don't add complexity unless you have to.
12779 \begin_inset LatexCommand \index{semaphore}
12783 locking (mcs51/ds390)
12786 Some architectures (mcs51/ds390) have an atomic
12787 \begin_inset LatexCommand \index{atomic}
12800 These type of instructions are typically used in preemptive multitasking
12801 systems, where a routine f.e.
12802 claims the use of a data structure ('acquires a lock
12803 \begin_inset LatexCommand \index{lock}
12807 on it'), makes some modifications and then releases the lock when the data
12808 structure is consistent again.
12809 The instruction may also be used if interrupt and non-interrupt code have
12810 to compete for a resource.
12811 With the atomic bit test and clear instruction interrupts
12812 \begin_inset LatexCommand \index{interrupt}
12816 don't have to be disabled for the locking operation.
12820 SDCC generates this instruction if the source follows this pattern:
12826 \begin_inset LatexCommand \index{volatile}
12830 bit resource_is_free;
12834 if (resource_is_free)
12844 resource_is_free=0;
12857 resource_is_free=1;
12864 Note, mcs51 and ds390 support only an atomic
12865 \begin_inset LatexCommand \index{atomic}
12873 instruction (as opposed to atomic bit test and
12878 Functions using private register banks
12879 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12886 Some architectures have support for quickly changing register sets.
12887 SDCC supports this feature with the
12890 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12895 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12901 attribute (which tells the compiler to use a register bank
12902 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12906 other than the default bank zero).
12907 It should only be applied to
12910 \begin_inset LatexCommand \index{interrupt}
12916 functions (see footnote below).
12917 This will in most circumstances make the generated ISR code more efficient
12918 since it will not have to save registers on the stack.
12925 attribute will have no effect on the generated code for a
12929 function (but may occasionally be useful anyway
12935 possible exception: if a function is called ONLY from 'interrupt' functions
12936 using a particular bank, it can be declared with the same 'using' attribute
12937 as the calling 'interrupt' functions.
12938 For instance, if you have several ISRs using bank one, and all of them
12939 call memcpy(), it might make sense to create a specialized version of memcpy()
12940 'using 1', since this would prevent the ISR from having to save bank zero
12941 to the stack on entry and switch to bank zero before calling the function
12948 (pending: Note, nowadays the
12952 attribute has an effect on
12956 the generated code for a
12971 function using a non-zero bank will assume that it can trash that register
12972 bank, and will not save it.
12973 Since high-priority interrupts
12974 \begin_inset LatexCommand \index{interrupts}
12979 \begin_inset LatexCommand \index{interrupt priority}
12983 can interrupt low-priority ones on the 8051 and friends, this means that
12984 if a high-priority ISR
12988 a particular bank occurs while processing a low-priority ISR
12992 the same bank, terrible and bad things can happen.
12993 To prevent this, no single register bank should be
12997 by both a high priority and a low priority ISR.
12998 This is probably most easily done by having all high priority ISRs use
12999 one bank and all low priority ISRs use another.
13000 If you have an ISR which can change priority at runtime, you're on your
13001 own: I suggest using the default bank zero and taking the small performance
13004 \added_space_bottom bigskip
13005 It is most efficient if your ISR calls no other functions.
13006 If your ISR must call other functions, it is most efficient if those functions
13007 use the same bank as the ISR (see note 1 below); the next best is if the
13008 called functions use bank zero.
13009 It is very inefficient to call a function using a different, non-zero bank
13015 \begin_inset LatexCommand \label{sub:Startup-Code}
13020 \begin_inset LatexCommand \index{Startup code}
13027 MCS51/DS390 Startup Code
13030 The compiler inserts a call to the C routine
13032 _sdcc_external_startup()
13033 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13042 at the start of the CODE area.
13043 This routine is in the runtime library
13044 \begin_inset LatexCommand \index{Runtime library}
13049 By default this routine returns 0, if this routine returns a non-zero value,
13050 the static & global variable initialization will be skipped and the function
13051 main will be invoked.
13052 Otherwise static & global variables will be initialized before the function
13056 _sdcc_external_startup()
13058 routine to your program to override the default if you need to setup hardware
13059 or perform some other critical operation prior to static & global variable
13061 \begin_inset LatexCommand \index{Variable initialization}
13066 On some mcs51 variants xdata
13067 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13071 memory has to be explicitly enabled before it can be accessed or if the
13073 \begin_inset LatexCommand \index{watchdog}
13077 needs to be disabled, this is the place to do it.
13078 The startup code clears all internal data memory, 256 bytes by default,
13079 but from 0 to n-1 if
13092 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13099 (recommended for Chipcon CC1010).
13101 \added_space_bottom bigskip
13102 See also the compiler options
13121 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13140 \begin_inset LatexCommand \index{-\/-main-return}
13145 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13149 about MCS51-variants.
13154 \added_space_bottom bigskip
13156 \begin_inset LatexCommand \index{HC08}
13160 startup code follows the same scheme as the MCS51 startup code.
13165 \added_space_bottom bigskip
13167 \begin_inset LatexCommand \index{Z80}
13171 the startup code is inserted by linking with crt0.o which is generated from
13172 sdcc/device/lib/z80/crt0.s.
13173 If you need a different startup code you can use the compiler option
13194 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13198 and provide your own crt0.o.
13202 Inline Assembler Code
13203 \begin_inset LatexCommand \index{Assembler routines}
13210 A Step by Step Introduction
13211 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13218 Starting from a small snippet of c-code this example shows for the MCS51
13219 how to use inline assembly, access variables, a function parameter and
13220 an array in xdata memory.
13221 The example uses an MCS51 here but is easily adapted for other architectures.
13222 This is a buffer routine which should be optimized:
13228 unsigned char __far
13229 \begin_inset LatexCommand \index{far (storage class)}
13234 \begin_inset LatexCommand \index{\_\_far (storage class)}
13239 \begin_inset LatexCommand \index{at}
13244 \begin_inset LatexCommand \index{\_\_at}
13248 (0x7f00) buf[0x100];
13249 \begin_inset LatexCommand \index{Aligned array}
13255 unsigned char head, tail;\SpecialChar ~
13273 \begin_inset LatexCommand \index{interrupt}
13325 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13337 void to_buffer( unsigned char c )
13345 if( head != (unsigned char)(tail-1) )\SpecialChar ~
13351 \begin_inset LatexCommand \index{promotion to signed int}
13356 \begin_inset LatexCommand \index{type promotion}
13361 \begin_inset Marginal
13382 buf[ head++ ] = c;\SpecialChar ~
13398 /* access to a 256 byte aligned array */
13403 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13404 then a corresponding buffer.asm file is generated.
13405 We define a new function
13409 in file buffer.c in which we cut and paste the generated code, removing
13410 unwanted comments and some ':'.
13412 \begin_inset Quotes sld
13416 \begin_inset Quotes srd
13420 \begin_inset Quotes sld
13424 \begin_inset Quotes srd
13427 to the beginning and the end of the function body:
13433 /* With a cut and paste from the .asm file, we have something to start with.
13438 The function is not yet OK! (registers aren't saved) */
13440 void to_buffer_asm( unsigned char c )
13449 \begin_inset LatexCommand \index{\_asm}
13454 \begin_inset LatexCommand \index{\_\_asm}
13468 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13474 \begin_inset LatexCommand \index{promotion to signed int}
13479 \begin_inset LatexCommand \index{type promotion}
13531 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
13532 \begin_inset LatexCommand \index{Aligned array}
13597 \begin_inset LatexCommand \index{\_endasm}
13602 \begin_inset LatexCommand \index{\_\_endasm}
13611 The new file buffer.c should compile with only one warning about the unreferenced
13612 function argument 'c'.
13613 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
13614 (1) and finally have:
13620 unsigned char __far __at(0x7f00) buf[0x100];
13622 unsigned char head, tail;
13624 #define USE_ASSEMBLY (1)
13632 void to_buffer( unsigned char c )
13640 if( head != (unsigned char)(tail-1) )
13660 void to_buffer( unsigned char c )
13668 c; // to avoid warning: unreferenced function argument
13675 \begin_inset LatexCommand \index{\_asm}
13680 \begin_inset LatexCommand \index{\_\_asm}
13694 ; save used registers here.
13705 ; If we were still using r2,r3 we would have to push them here.
13708 ; if( head != (unsigned char)(tail-1) )
13751 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13775 ; buf[ head++ ] = c;
13786 a,dpl \SpecialChar ~
13793 ; dpl holds lower byte of function argument
13804 dpl,_head \SpecialChar ~
13807 ; buf is 0x100 byte aligned so head can be used directly
13849 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13861 ; restore used registers here
13868 \begin_inset LatexCommand \index{\_endasm}
13873 \begin_inset LatexCommand \index{\_\_endasm}
13884 The inline assembler code can contain any valid code understood by the assembler
13885 , this includes any assembler directives and comment lines.
13886 The assembler does not like some characters like ':' or ''' in comments.
13887 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13888 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13893 \begin_inset LatexCommand \index{Assembler documentation}
13898 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
13906 The compiler does not do any validation of the code within the
13909 \begin_inset LatexCommand \index{\_asm}
13914 \begin_inset LatexCommand \index{\_\_asm}
13922 \begin_inset LatexCommand \index{\_endasm}
13927 \begin_inset LatexCommand \index{\_\_endasm}
13936 Specifically it will not know which registers are used and thus register
13938 \begin_inset LatexCommand \index{push/pop}
13942 has to be done manually.
13946 It is recommended that each assembly instruction (including labels) be placed
13947 in a separate line (as the example shows).
13961 \begin_inset LatexCommand \index{-\/-peep-asm}
13967 command line option is used, the inline assembler code will be passed through
13968 the peephole optimizer
13969 \begin_inset LatexCommand \index{Peephole optimizer}
13974 There are only a few (if any) cases where this option makes sense, it might
13975 cause some unexpected changes in the inline assembler code.
13976 Please go through the peephole optimizer rules defined in file
13980 before using this option.
13984 \begin_inset LatexCommand \label{sub:Naked-Functions}
13989 \begin_inset LatexCommand \index{Naked functions}
13996 A special keyword may be associated with a function declaring it as
13999 \begin_inset LatexCommand \index{\_naked}
14004 \begin_inset LatexCommand \index{\_\_naked}
14015 function modifier attribute prevents the compiler from generating prologue
14016 \begin_inset LatexCommand \index{function prologue}
14021 \begin_inset LatexCommand \index{function epilogue}
14025 code for that function.
14026 This means that the user is entirely responsible for such things as saving
14027 any registers that may need to be preserved, selecting the proper register
14028 bank, generating the
14032 instruction at the end, etc.
14033 Practically, this means that the contents of the function must be written
14034 in inline assembler.
14035 This is particularly useful for interrupt functions, which can have a large
14036 (and often unnecessary) prologue/epilogue.
14037 For example, compare the code generated by these two functions:
14043 \begin_inset LatexCommand \index{volatile}
14047 data unsigned char counter;
14051 void simpleInterrupt(void) __interrupt
14052 \begin_inset LatexCommand \index{interrupt}
14057 \begin_inset LatexCommand \index{\_\_interrupt}
14075 void nakedInterrupt(void) __interrupt (2) __naked
14084 \begin_inset LatexCommand \index{\_asm}
14089 \begin_inset LatexCommand \index{\_\_asm}
14106 _counter ; does not change flags, no need to save psw
14118 ; MUST explicitly include ret or reti in _naked function.
14125 \begin_inset LatexCommand \index{\_endasm}
14130 \begin_inset LatexCommand \index{\_\_endasm}
14139 For an 8051 target, the generated simpleInterrupt looks like:
14148 example, recent versions of SDCC generate
14154 code for simpleInterrupt() and nakedInterrupt()!
14294 whereas nakedInterrupt looks like:
14309 _counter ; does not change flags, no need to save psw
14327 ; MUST explicitly include ret or reti in _naked function
14330 The related directive #pragma exclude
14331 \begin_inset LatexCommand \index{\#pragma exclude}
14335 allows a more fine grained control over pushing & popping
14336 \begin_inset LatexCommand \index{push/pop}
14343 While there is nothing preventing you from writing C code inside a
14347 function, there are many ways to shoot yourself in the foot doing this,
14348 and it is recommended that you stick to inline assembler.
14351 Use of Labels within Inline Assembler
14354 SDCC allows the use of in-line assembler with a few restrictions regarding
14356 In older versions of the compiler all labels defined within inline assembler
14365 where nnnn is a number less than 100 (which implies a limit of utmost 100
14366 inline assembler labels
14380 \begin_inset LatexCommand \index{\_asm}
14385 \begin_inset LatexCommand \index{\_\_asm}
14415 \begin_inset LatexCommand \index{\_endasm}
14420 \begin_inset LatexCommand \index{\_\_endasm}
14427 Inline assembler code cannot reference any C-Labels, however it can reference
14429 \begin_inset LatexCommand \index{Labels}
14433 defined by the inline assembler, e.g.:
14458 ; some assembler code
14478 /* some more c code */
14480 clabel:\SpecialChar ~
14482 /* inline assembler cannot reference this label */
14494 $0003: ;label (can be referenced by inline assembler only)
14501 \begin_inset LatexCommand \index{\_endasm}
14506 \begin_inset LatexCommand \index{\_\_endasm}
14516 /* some more c code */
14521 In other words inline assembly code can access labels defined in inline
14522 assembly within the scope of the function.
14523 The same goes the other way, i.e.
14524 labels defines in inline assembly can not be accessed by C statements.
14527 Interfacing with Assembler Code
14528 \begin_inset LatexCommand \index{Assembler routines}
14535 Global Registers used for Parameter Passing
14536 \begin_inset LatexCommand \index{Parameter passing}
14543 The compiler always uses the global registers
14546 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14551 \begin_inset LatexCommand \index{DPTR}
14556 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
14565 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
14571 to pass the first parameter to a routine.
14572 The second parameter onwards is either allocated on the stack (for reentrant
14583 -stack-auto is used) or in data / xdata memory (depending on the memory
14588 Assembler Routine (non-reentrant)
14591 In the following example
14592 \begin_inset LatexCommand \index{reentrant}
14597 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
14601 the function c_func calls an assembler routine asm_func, which takes two
14603 \begin_inset LatexCommand \index{function parameter}
14612 extern int asm_func(unsigned char, unsigned char);
14616 int c_func (unsigned char i, unsigned char j)
14624 return asm_func(i,j);
14638 return c_func(10,9);
14643 The corresponding assembler function is:
14648 .globl _asm_func_PARM_2
14749 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14766 Note here that the return values
14767 \begin_inset LatexCommand \index{return value}
14771 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14773 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14774 b' & 'acc' for four byte values.
14777 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14778 the parameter number starting from 1, and counting from the left.
14779 The first parameter is passed in
14780 \begin_inset Quotes eld
14784 \begin_inset Quotes erd
14787 for a one byte parameter,
14788 \begin_inset Quotes eld
14792 \begin_inset Quotes erd
14796 \begin_inset Quotes eld
14800 \begin_inset Quotes erd
14803 for three bytes and
14804 \begin_inset Quotes eld
14808 \begin_inset Quotes erd
14811 for a four bytes parameter.
14812 The variable name for the second parameter will be _<function_name>_PARM_2.
14816 Assemble the assembler routine with the following command:
14823 asx8051 -losg asmfunc.asm
14830 Then compile and link the assembler routine to the C source file with the
14838 sdcc cfunc.c asmfunc.rel
14841 Assembler Routine (reentrant)
14845 \begin_inset LatexCommand \index{reentrant}
14850 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14854 the second parameter
14855 \begin_inset LatexCommand \index{function parameter}
14859 onwards will be passed on the stack, the parameters are pushed from right
14861 after the call the leftmost parameter will be on the top of the stack.
14862 Here is an example:
14867 extern int asm_func(unsigned char, unsigned char);
14871 int c_func (unsigned char i, unsigned char j) reentrant
14879 return asm_func(i,j);
14893 return c_func(10,9);
14898 The corresponding assembler routine is:
14997 \added_space_bottom bigskip
14998 The compiling and linking procedure remains the same, however note the extra
14999 entry & exit linkage required for the assembler code, _bp is the stack
15000 frame pointer and is used to compute the offset into the stack for parameters
15001 and local variables.
15005 \begin_inset LatexCommand \index{int (16 bit)}
15010 \begin_inset LatexCommand \index{long (32 bit)}
15017 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15018 multiplication and modulus operations are implemented by support routines.
15019 These support routines are all developed in ANSI-C to facilitate porting
15020 to other MCUs, although some model specific assembler optimizations are
15022 The following files contain the described routines, all of them can be
15023 found in <installdir>/share/sdcc/lib.
15029 \begin_inset Tabular
15030 <lyxtabular version="3" rows="11" columns="2">
15032 <column alignment="left" valignment="top" leftline="true" width="0">
15033 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15034 <row topline="true" bottomline="true">
15035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
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 16 bit multiplication
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 signed 16 bit division (calls _divuint)
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 unsigned 16 bit division
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 signed 16 bit modulus (calls _moduint)
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 unsigned 16 bit modulus
15146 <row topline="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 32 bit multiplication
15164 <row topline="true">
15165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15178 signed 32 division (calls _divulong)
15182 <row topline="true">
15183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15196 unsigned 32 division
15200 <row topline="true">
15201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15214 signed 32 bit modulus (calls _modulong)
15218 <row topline="true" bottomline="true">
15219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15232 unsigned 32 bit modulus
15245 Since they are compiled as
15250 \begin_inset LatexCommand \index{reentrant}
15255 \begin_inset LatexCommand \index{interrupt}
15259 service routines should not do any of the above operations.
15260 If this is unavoidable then the above routines will need to be compiled
15274 \begin_inset LatexCommand \index{-\/-stack-auto}
15280 option, after which the source program will have to be compiled with
15293 \begin_inset LatexCommand \index{-\/-int-long-reent}
15300 Notice that you don't have to call these routines directly.
15301 The compiler will use them automatically every time an integer operation
15305 Floating Point Support
15306 \begin_inset LatexCommand \index{Floating point support}
15313 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15314 The floating point support routines are derived from gcc's floatlib.c and
15315 consist of the following routines:
15323 \begin_inset Tabular
15324 <lyxtabular version="3" rows="17" columns="2">
15326 <column alignment="left" valignment="top" leftline="true" width="0">
15327 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15328 <row topline="true" bottomline="true">
15329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
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 add 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 subtract 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 divide floating point numbers
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 multiply floating point numbers
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 char
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 char
15571 <row topline="true">
15572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15603 convert floating point to unsigned int
15607 <row topline="true">
15608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15639 convert floating point to signed int
15643 <row topline="true">
15644 <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 floating point to unsigned long
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 floating point to signed long
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 char 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 char to floating point number
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 int to floating point
15832 <row topline="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 int to floating point numbers
15868 <row topline="true">
15869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15900 convert unsigned long to floating point number
15904 <row topline="true" bottomline="true">
15905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15936 convert long to floating point number
15948 \added_space_bottom bigskip
15949 These support routines are developed in ANSI-C so there is room for space
15950 and speed improvement
15956 These floating point routines (
15960 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15965 Note if all these routines are used simultaneously the data space might
15967 For serious floating point usage the large model might be needed.
15968 Also notice that you don't have to call this routines directly.
15969 The compiler will use them automatically every time a floating point operation
15974 \begin_inset LatexCommand \index{Libraries}
15983 <pending: this is messy and incomplete - a little more information is in
15984 sdcc/doc/libdoc.txt
15989 Compiler support routines (_gptrget, _mulint etc.)
15992 Stdclib functions (puts, printf, strcat etc.)
15993 \layout Subsubsection
15998 getchar(), putchar()
16002 \begin_inset LatexCommand \index{<stdio.h>}
16006 As usual on embedded systems you have to provide your own
16009 \begin_inset LatexCommand \index{getchar()}
16018 \begin_inset LatexCommand \index{putchar()}
16025 SDCC does not know whether the system connects to a serial line with or
16026 without handshake, LCD, keyboard or other device.
16040 You'll find examples for serial routines f.e.
16041 in sdcc/device/lib.
16042 For the mcs51 this minimalistic polling
16046 routine might be a start:
16051 void putchar (char c) {
16057 while (!TI)\SpecialChar ~
16060 /* assumes UART is initialized */
16093 \begin_inset LatexCommand \index{printf()}
16103 does not support float (except on ds390).
16104 To enable this recompile it with the option
16117 \begin_inset LatexCommand \index{USE\_FLOATS}
16123 on the command line.
16137 \begin_inset LatexCommand \index{-\/-model-large}
16143 for the mcs51 port, since this uses a lot of memory.
16146 If you're short on code memory you might want to use
16149 \begin_inset LatexCommand \index{printf\_small()}
16164 For the mcs51 there additionally are assembly versions
16167 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16173 (subset of printf using less than 270 bytes) and
16176 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16185 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16191 (floating-point aware version of printf_fast) which should fit the requirements
16192 of many embedded systems (printf_fast() can be customized by unsetting
16197 support long variables and field widths).
16198 Be shure to only use only one of these printf options within a project.
16203 Feature matrix of different
16211 \begin_inset Tabular
16212 <lyxtabular version="3" rows="9" columns="7">
16213 <features islongtable="true">
16214 <column alignment="left" valignment="center" leftline="true" width="14col%">
16215 <column alignment="center" valignment="top" leftline="true" width="0">
16216 <column alignment="center" valignment="top" leftline="true" width="12col%">
16217 <column alignment="center" valignment="top" leftline="true" width="10col%">
16218 <column alignment="center" valignment="top" leftline="true" width="0">
16219 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
16220 <column alignment="center" valignment="top" rightline="true" width="0">
16221 <row topline="true" bottomline="true" endhead="true">
16222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16239 \begin_inset LatexCommand \index{printf}
16246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16289 <row topline="true" endhead="true">
16290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16359 <row topline="true" endhead="true">
16360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16365 code size (small\SpecialChar ~
16367 large) in\SpecialChar ~
16371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16392 0.45 / 0.47 (+ _ltoa)
16395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16420 <row topline="true">
16421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16563 <row topline="true">
16564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16569 long (32 bit) support
16572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16630 <row topline="true">
16631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16636 byte arguments on stack
16639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16688 <row topline="true">
16689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16695 \begin_inset LatexCommand \index{Floating point support}
16702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16739 %f (limited\SpecialChar ~
16743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16752 <row topline="true">
16753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16758 float formats %e %g
16761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16810 <row topline="true" bottomline="true">
16811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16873 \layout Subsubsection
16876 \begin_inset LatexCommand \index{malloc.h}
16883 As of SDCC 2.6.2 you no longer need to call an initialization routine before
16884 using dynamic memory allocation
16885 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
16890 \begin_inset LatexCommand \index{heap (malloc)}
16894 space of 1024 bytes is provided for malloc to allocate memory from.
16895 If you need a different heap size you need to recompile _heap.c with the
16896 required size defined in HEAP_SIZE.
16897 It is recommended to make a copy of this file into your project directory
16898 and compile it there with:
16903 sdcc -c _heap.c -D HEAD_SIZE=2048
16906 And then link it with:
16911 sdcc main.rel _heap.rel
16914 Math functions (sinf, powf, sqrtf etc.)
16915 \layout Subsubsection
16920 See definitions in file <math.h>.
16927 \begin_inset LatexCommand \index{Libraries}
16931 included in SDCC should have a license at least as liberal as the GNU Lesser
16932 General Public License
16933 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
16944 license statements for the libraries are missing.
16945 sdcc/device/lib/ser_ir.c
16949 come with a GPL (as opposed to LGPL) License - this will not be liberal
16950 enough for many embedded programmers.
16953 If you have ported some library or want to share experience about some code
16955 falls into any of these categories Busses (I
16956 \begin_inset Formula $^{\textrm{2}}$
16959 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
16960 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
16961 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
16962 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
16967 would certainly like to hear about it.
16969 \added_space_bottom bigskip
16970 Programmers coding for embedded systems are not especially famous for being
16971 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
16972 e these references are very valuable.
16973 Let's help to create a climate where information is shared.
16979 MCS51 Memory Models
16980 \begin_inset LatexCommand \index{Memory model}
16985 \begin_inset LatexCommand \index{MCS51 memory model}
16990 \layout Subsubsection
16992 Small, Medium and Large
16995 SDCC allows three memory models for MCS51 code,
17004 Modules compiled with different memory models should
17008 be combined together or the results would be unpredictable.
17009 The library routines supplied with the compiler are compiled as small,
17011 The compiled library modules are contained in separate directories as small,
17012 medium and large so that you can link to the appropriate set.
17015 When the medium or large model is used all variables declared without a
17016 storage class will be allocated into the external ram, this includes all
17017 parameters and local variables (for non-reentrant
17018 \begin_inset LatexCommand \index{reentrant}
17023 When the small model is used variables without storage class are allocated
17024 in the internal ram.
17027 Judicious usage of the processor specific storage classes
17028 \begin_inset LatexCommand \index{Storage class}
17032 and the 'reentrant' function type will yield much more efficient code,
17033 than using the large model.
17034 Several optimizations are disabled when the program is compiled using the
17035 large model, it is therefore recommended that the small model be used unless
17036 absolutely required.
17037 \layout Subsubsection
17040 \begin_inset LatexCommand \label{sub:External-Stack}
17045 \begin_inset LatexCommand \index{stack}
17050 \begin_inset LatexCommand \index{External stack (mcs51)}
17057 The external stack (-
17068 \begin_inset LatexCommand \index{-\/-xstack}
17072 ) is located in pdata
17073 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17077 memory (usually at the start of the external ram segment) and uses all
17078 unused space in pdata (max.
17090 -xstack option is used to compile the program, the parameters and local
17092 \begin_inset LatexCommand \index{local variables}
17096 of all reentrant functions are allocated in this area.
17097 This option is provided for programs with large stack space requirements.
17098 When used with the -
17109 \begin_inset LatexCommand \index{-\/-stack-auto}
17113 option, all parameters and local variables are allocated on the external
17114 stack (note: support libraries will need to be recompiled with the same
17116 There is a predefined target in the library makefile).
17119 The compiler outputs the higher order address byte of the external ram segment
17121 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
17126 \begin_inset LatexCommand \ref{sub:MCS51-variants}
17130 ), therefore when using the External Stack option, this port
17134 be used by the application program.
17138 \begin_inset LatexCommand \index{Memory model}
17143 \begin_inset LatexCommand \index{DS390 memory model}
17150 The only model supported is Flat 24
17151 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
17156 This generates code for the 24 bit contiguous addressing mode of the Dallas
17158 In this mode, up to four meg of external RAM or code space can be directly
17160 See the data sheets at www.dalsemi.com for further information on this part.
17164 Note that the compiler does not generate any code to place the processor
17165 into 24 bitmode (although
17169 in the ds390 libraries will do that for you).
17175 \begin_inset LatexCommand \index{Tinibios (DS390)}
17179 , the boot loader or similar code must ensure that the processor is in 24
17180 bit contiguous addressing mode before calling the SDCC startup code.
17198 option, variables will by default be placed into the XDATA segment.
17203 Segments may be placed anywhere in the 4 meg address space using the usual
17215 Note that if any segments are located above 64K, the -r flag must be passed
17216 to the linker to generate the proper segment relocations, and the Intel
17217 HEX output format must be used.
17218 The -r flag can be passed to the linker by using the option
17222 on the SDCC command line.
17223 However, currently the linker can not handle code segments > 64k.
17227 \begin_inset LatexCommand \label{sec:Pragmas}
17232 \begin_inset LatexCommand \index{Pragmas}
17239 SDCC supports the following #pragma directives:
17247 \begin_inset LatexCommand \index{\#pragma save}
17251 - this will save most current options to the save/restore stack.
17252 See #pragma\SpecialChar ~
17261 \begin_inset LatexCommand \index{\#pragma restore}
17265 - will restore saved options from the last save.
17266 saves & restores can be nested.
17267 SDCC uses a save/restore stack: save pushes current options to the stack,
17268 restore pulls current options from the stack.
17269 See #pragma\SpecialChar ~
17280 \begin_inset LatexCommand \index{\#pragma callee\_saves}
17285 \begin_inset LatexCommand \index{function prologue}
17289 function1[,function2[,function3...]] - The compiler by default uses a caller
17290 saves convention for register saving across function calls, however this
17291 can cause unnecessary register pushing & popping
17292 \begin_inset LatexCommand \index{push/pop}
17296 when calling small functions from larger functions.
17297 This option can be used to switch off the register saving convention for
17298 the function names specified.
17299 The compiler will not save registers when calling these functions, extra
17300 code need to be manually inserted at the entry & exit for these functions
17301 to save & restore the registers used by these functions, this can SUBSTANTIALLY
17302 reduce code & improve run time performance of the generated code.
17303 In the future the compiler (with inter procedural analysis) may be able
17304 to determine the appropriate scheme to use for each function call.
17315 -callee-saves command line option is used, the function names specified
17316 in #pragma\SpecialChar ~
17318 \begin_inset LatexCommand \index{\#pragma callee\_saves}
17322 is appended to the list of functions specified in the command line.
17330 \begin_inset LatexCommand \index{\#pragma exclude}
17334 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
17335 of pairs of push/pop
17336 \begin_inset LatexCommand \index{push/pop}
17345 \begin_inset LatexCommand \index{interrupt}
17358 The directive should be placed immediately before the ISR function definition
17359 and it affects ALL ISR functions following it.
17360 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
17361 exclude\SpecialChar ~
17363 \begin_inset LatexCommand \index{\#pragma exclude}
17368 See also the related keyword _naked
17369 \begin_inset LatexCommand \index{\_naked}
17374 \begin_inset LatexCommand \index{\_\_naked}
17386 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
17390 - the compiler will not warn you anymore for obvious mistakes, you'r on
17399 \begin_inset LatexCommand \index{\#pragma disable\_warning}
17403 - the compiler will not warn you anymore about warning number <nnnn>.
17411 \begin_inset LatexCommand \index{\#pragma nogcse}
17415 - will stop global common subexpression elimination.
17423 \begin_inset LatexCommand \index{\#pragma noinduction}
17427 - will stop loop induction optimizations.
17435 \begin_inset LatexCommand \index{\#pragma noinvariant}
17439 - will not do loop invariant optimizations.
17440 For more details see Loop Invariants in section
17441 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
17453 \begin_inset LatexCommand \index{\#pragma noiv}
17457 - Do not generate interrupt
17458 \begin_inset LatexCommand \index{interrupt}
17463 \begin_inset LatexCommand \index{interrupt vector table}
17467 entries for all ISR functions defined after the pragma.
17468 This is useful in cases where the interrupt vector table must be defined
17469 manually, or when there is a secondary, manually defined interrupt vector
17471 for the autovector feature of the Cypress EZ-USB FX2).
17472 More elegantly this can be achieved by obmitting the optional interrupt
17473 number after the interrupt keyword, see section
17474 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
17487 \begin_inset LatexCommand \index{\#pragma nojtbound}
17491 - will not generate code for boundary value checking, when switch statements
17492 are turned into jump-tables (dangerous).
17493 For more details see section
17494 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
17506 \begin_inset LatexCommand \index{\#pragma noloopreverse}
17510 - Will not do loop reversal optimization
17518 \begin_inset LatexCommand \index{\#pragma nooverlay}
17522 - the compiler will not overlay the parameters and local variables of a
17531 \begin_inset LatexCommand \index{\#pragma stackauto}
17546 \begin_inset LatexCommand \index{-\/-stack-auto}
17551 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
17555 Parameters and Local Variables.
17563 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
17567 - The compiler will optimize code generation towards fast code, possibly
17568 at the expense of code size.
17569 Currently this has little effect.
17577 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
17581 - The compiler will optimize code generation towards compact code, possibly
17582 at the expense of code speed.
17583 Currently this has little effect.
17591 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
17595 - The compiler will attempt to generate code that is both compact and fast,
17596 as long as meeting one goal is not a detriment to the other (this is the
17606 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
17610 - Generally follow the C89 standard, but allow SDCC features that conflict
17611 with the standard (default).
17619 \begin_inset LatexCommand \index{\#pragma std\_c89}
17623 - Follow the C89 standard and disable SDCC features that conflict with the
17632 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
17636 - Generally follow the C99 standard, but allow SDCC features that conflict
17637 with the standard (incomplete support).
17645 \begin_inset LatexCommand \index{\#pragma std\_c99}
17649 - Follow the C99 standard and disable SDCC features that conflict with the
17650 standard (incomplete support).
17658 \begin_inset LatexCommand \index{\#pragma codeseg}
17662 - Use this name (max.
17663 8 characters) for the code segment.
17682 \begin_inset LatexCommand \index{\#pragma constseg}
17686 - Use this name (max.
17687 8 characters) for the const segment.
17701 The preprocessor SDCPP
17702 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
17706 supports the following #pragma directives:
17711 pedantic_parse_number
17714 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17718 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
17719 parsed properly and the macro LO_B(3) gets expanded.
17721 Below is an example on how to use this pragma.
17724 Note: this functionality is not in conformance with standard!
17729 #pragma pedantic_parse_number +
17730 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
17738 #define LO_B(x) ((x) & 0xff)
17742 unsigned char foo(void)
17749 unsigned char c=0xfe-LO_B(3);
17768 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17772 (+ | -) - switch _asm _endasm block preprocessing on / off.
17774 You use this prama to define multilines of assembly code.
17775 This will prevent the preprocessor from changing the formating required
17777 Below is an example on how to use this pragma.
17782 #pragma preproc_asm -
17783 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
17789 #define MYDELAY _asm
17794 nop ;my assembly comment...
17808 #pragma preproc_asm +
17843 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17847 (+ | -) - Allow "naked" hash in macro definition, for example:
17851 #define DIR_LO(x) #(x & 0xff)
17856 Below is an example on how to use this pragma.
17861 #pragma preproc_asm +
17863 #pragma sdcc_hash +
17864 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
17879 mov R6_B3, #(x & 0xff)
17886 mov R7_B3, #((x >> 8) & 0xff)
17910 The pragma's are intended to be used to turn-on or off certain optimizations
17911 which might cause the compiler to generate extra stack / data space to
17912 store compiler generated temporary variables.
17913 This usually happens in large functions.
17914 Pragma directives should be used as shown in the following example, they
17915 are used to control options & optimizations for a given function; pragmas
17916 should be placed before and/or after a function, placing pragma's inside
17917 a function body could have unpredictable results.
17923 \begin_inset LatexCommand \index{\#pragma save}
17934 /* save the current settings */
17937 \begin_inset LatexCommand \index{\#pragma nogcse}
17946 /* turnoff global subexpression elimination */
17948 #pragma noinduction
17949 \begin_inset LatexCommand \index{\#pragma noinduction}
17953 /* turn off induction optimizations */
17976 \begin_inset LatexCommand \index{\#pragma restore}
17980 /* turn the optimizations back on */
17983 The compiler will generate a warning message when extra space is allocated.
17984 It is strongly recommended that the save and restore pragma's be used when
17985 changing options for a function.
17994 Defines Created by the Compiler
17997 The compiler creates the following #defines
17998 \begin_inset LatexCommand \index{\#defines}
18003 \begin_inset LatexCommand \index{Defines created by the compiler}
18013 \begin_inset Tabular
18014 <lyxtabular version="3" rows="11" columns="2">
18016 <column alignment="left" valignment="top" leftline="true" width="3in">
18017 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
18018 <row topline="true" bottomline="true">
18019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18040 <row topline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18047 \begin_inset LatexCommand \index{SDCC}
18054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18060 Since version 2.5.6 the version number as an int (ex.
18065 <row topline="true">
18066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18072 \begin_inset LatexCommand \index{SDCC\_mcs51}
18077 \begin_inset LatexCommand \index{SDCC\_ds390}
18082 \begin_inset LatexCommand \index{SDCC\_z80}
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18094 depending on the model used (e.g.: -mds390)
18098 <row topline="true">
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18105 \begin_inset LatexCommand \index{\_\_mcs51}
18110 \begin_inset LatexCommand \index{\_\_ds390}
18115 \begin_inset LatexCommand \index{\_\_hc08}
18120 \begin_inset LatexCommand \index{\_\_z80}
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18132 depending on the model used (e.g.
18137 <row topline="true">
18138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18144 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18174 <row topline="true">
18175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18181 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
18188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18211 <row topline="true">
18212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18218 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
18225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18248 <row topline="true">
18249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18255 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
18262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18285 <row topline="true">
18286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18292 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
18299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18322 <row topline="true">
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18329 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
18336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18349 <row topline="true" bottomline="true">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18356 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
18363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18383 Notes on supported Processors
18387 \begin_inset LatexCommand \label{sub:MCS51-variants}
18392 \begin_inset LatexCommand \index{MCS51 variants}
18399 MCS51 processors are available from many vendors and come in many different
18401 While they might differ considerably in respect to Special Function Registers
18402 the core MCS51 is usually not modified or is kept compatible.
18406 pdata access by SFR
18409 With the upcome of devices with internal xdata and flash memory devices
18411 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18415 as dedicated I/O port is becoming more popular.
18416 Switching the high byte for pdata
18417 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18421 access which was formerly done by port P2 is then achieved by a Special
18423 \begin_inset LatexCommand \index{sfr}
18428 In well-established MCS51 tradition the address of this
18432 is where the chip designers decided to put it.
18433 Needless to say that they didn't agree on a common name either.
18434 So that the startup code can correctly initialize xdata variables, you
18435 should define an sfr with the name _XPAGE
18438 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
18444 at the appropriate location if the default, port P2, is not used for this.
18450 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
18455 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
18460 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
18463 For more exotic implementations further customizations may be needed.
18465 \begin_inset LatexCommand \ref{sub:Startup-Code}
18469 for other possibilities.
18472 Other Features available by SFR
18474 \added_space_bottom bigskip
18475 Some MCS51 variants offer features like Double DPTR
18476 \begin_inset LatexCommand \index{DPTR}
18480 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
18481 These are currently not used for the MCS51 port.
18482 If you absolutely need them you can fall back to inline assembly or submit
18488 \added_space_bottom bigskip
18490 \begin_inset LatexCommand \index{DS80C400}
18495 \begin_inset LatexCommand \index{DS400}
18499 microcontroller has a rich set of peripherals.
18500 In its built-in ROM library it includes functions to access some of the
18501 features, among them is a TCP stack with IP4 and IP6 support.
18502 Library headers (currently in beta status) and other files are provided
18506 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
18514 The Z80 and gbz80 port
18517 SDCC can target both the Zilog Z80
18518 \begin_inset LatexCommand \index{Z80}
18522 and the Nintendo Gameboy's Z80-like gbz80
18523 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
18528 The Z80 port is passed through the same
18531 \begin_inset LatexCommand \index{Regression test}
18538 \begin_inset LatexCommand \ref{sec:Quality-control}
18542 ) as the MCS51 and DS390 ports, so floating point support, support for long
18543 variables and bitfield support is fine.
18544 See mailing lists and forums about interrupt routines.
18546 \added_space_bottom bigskip
18547 As always, the code is the authoritative reference - see z80/ralloc.c and
18550 \begin_inset LatexCommand \index{Z80!stack}
18554 frame is similar to that generated by the IAR Z80 compiler.
18555 IX is used as the base pointer, HL and IY are used as a temporary registers,
18556 and BC and DE are available for holding variables.
18558 \begin_inset LatexCommand \index{Z80!return value}
18562 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
18564 The gbz80 port use the same set of registers for the return values, but
18565 in a different order of significance: E (one byte), DE (two bytes), or
18572 The port to the Freescale/Motorola HC08
18573 \begin_inset LatexCommand \index{HC08}
18577 family has been added in October 2003, and is still undergoing some basic
18579 The code generator is complete, but the register allocation is still quite
18581 Some of the SDCC's standard C library functions have embedded non-HC08
18582 inline assembly and so are not yet usable.
18584 \added_space_bottom bigskip
18585 The HC08 port passes the regression test suite (see section
18586 \begin_inset LatexCommand \ref{sec:Quality-control}
18597 \begin_inset LatexCommand \index{PIC14}
18601 port still requires a major effort from the development community.
18602 However it can work for simple code.
18603 It passes its (smaller set of) regression tests
18604 \begin_inset LatexCommand \index{Regression test (PIC14)}
18610 sdcc/src/regression
18615 C code and 14bit PIC code page
18616 \begin_inset LatexCommand \index{code page (pic14)}
18621 \begin_inset LatexCommand \index{RAM bank (pic14)}
18628 The linker organizes allocation for the code page and RAM banks.
18629 It does not have intimate knowledge of the code flow.
18630 It will put all the code section of a single asm file into a single code
18632 In order to make use of multiple code pages, separate asm files must be
18634 The compiler treats all functions of a single C file as being in the same
18635 code page unless it is non static.
18639 To get the best follow these guide lines:
18642 Make local functions static, as non static functions require code page selection
18646 For devices that have multiple code pages it is more efficient to use the
18647 same number of files as pages, i.e.
18648 for the 16F877 use 4 separate files and i.e.
18649 for the 16F874 use 2 separate files.
18650 This way the linker can put the code for each file into different code
18651 pages and there's less page selection overhead.
18654 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
18655 instruction set), use 'unsigned char' whereever possible instead of 'int'.
18658 Creating a device include file
18661 For generating a device include file
18662 \begin_inset LatexCommand \index{PIC14!Header files}
18666 use the support perl script inc2h.pl kept in directory support/script.
18672 For the interrupt function, use the keyword '__interrupt'
18673 \begin_inset LatexCommand \index{PIC14!interrupt}
18677 with level number of 0 (PIC14 only has 1 interrupt so this number is only
18678 there to avoid a syntax error - it ought to be fixed).
18684 void Intr(void) __interrupt 0
18690 T0IF = 0; /* Clear timer interrupt */
18695 Linking and assembling
18698 For assembling you can use either GPUTILS'
18699 \begin_inset LatexCommand \index{gputils (pic tools)}
18703 gpasm.exe or MPLAB's mpasmwin.exe.
18704 GPUTILS is available from
18705 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18710 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
18711 If you use MPLAB and an interrupt function then the linker script file
18712 vectors section will need to be enlarged to link with mplink.
18735 sdcc -S -V -mpic14 -p16F877 $<
18749 $(PRJ).hex: $(OBJS)
18759 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
18781 sdcc -S -V -mpic14 -p16F877 $<
18791 mpasmwin /q /o $*.asm
18795 $(PRJ).hex: $(OBJS)
18805 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
18808 Please note that indentations within a
18812 have to be done with a tabulator character.
18815 Command-line options
18818 Besides the switches common to all SDCC backends, the PIC14 port accepts
18819 the following options (for an updated list see sdcc -
18831 \labelwidthstring 00.00.0000
18844 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
18848 emit debug info in assembly output
18850 \labelwidthstring 00.00.0000
18863 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
18867 disable (slightly faulty) optimization on pCode
18869 \labelwidthstring 00.00.0000
18882 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
18886 sets the lowest address of the argument passing stack (defaults to a suitably
18887 large shared databank to reduce BANKSEL overhead)
18889 \labelwidthstring 00.00.0000
18902 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
18906 sets the size if the argument passing stack (default: 16, minimum: 4)
18910 \layout Subsubsection
18912 error: missing definition for symbol
18913 \begin_inset Quotes sld
18917 \begin_inset Quotes srd
18923 The PIC14 port uses library routines to provide more complex operations
18924 like multiplication, division/modulus and (generic) pointer dereferencing.
18925 In order to add these routines to your project, you must link with PIC14's
18931 For single source file projects this is done automatically, more complex
18936 to the linker's arguments.
18937 Make sure you also add an include path for the library (using the -I switch
18939 \layout Subsubsection
18941 Processor mismatch in file
18942 \begin_inset Quotes sld
18946 \begin_inset Quotes srd
18952 This warning can usually be ignored due to the very good compatibility amongst
18954 \begin_inset LatexCommand \index{PIC14}
18961 You might also consider recompiling the library for your specific device
18962 by changing the ARCH=p16f877 (default target) entry in
18964 device/lib/pic/Makefile.in
18968 device/lib/pic/Makefile
18970 to reflect your device.
18971 This might even improve performance for smaller devices as unneccesary
18972 BANKSELs migth be removed.
18976 \layout Subsubsection
18981 Currently, data can only be initialized if it resides in the source file
18987 Data in other source files will silently
18995 \begin_inset Marginal
19010 \begin_inset LatexCommand \index{PIC16}
19018 \begin_inset LatexCommand \index{PIC16}
19022 port is the portion of SDCC that is responsible to produce code for the
19024 \begin_inset LatexCommand \index{Microchip}
19028 (TM) microcontrollers with 16 bit core.
19029 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
19030 Currently supported devices are:
19034 \begin_inset Tabular
19035 <lyxtabular version="3" rows="4" columns="6">
19037 <column alignment="center" valignment="top" leftline="true" width="0">
19038 <column alignment="center" valignment="top" leftline="true" width="0">
19039 <column alignment="center" valignment="top" leftline="true" width="0">
19040 <column alignment="center" valignment="top" leftline="true" width="0">
19041 <column alignment="center" valignment="top" leftline="true" width="0">
19042 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19043 <row topline="true">
19044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19093 <row topline="true">
19094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19143 <row topline="true">
19144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19193 <row topline="true" bottomline="true">
19194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19250 PIC16 port supports the standard command line arguments as supposed, with
19251 the exception of certain cases that will be mentioned in the following
19254 \labelwidthstring 00.00.0000
19267 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
19283 \labelwidthstring 00.00.0000
19296 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
19300 All function arguments are passed on stack by default.
19303 There is no need to specify this in the command line.
19305 \labelwidthstring 00.00.0000
19317 -fommit-frame-pointer
19318 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
19322 Frame pointer will be omitted when the function uses no local variables.
19325 Port Specific Options
19326 \begin_inset LatexCommand \index{Options PIC16}
19333 The port specific options appear after the global options in the sdcc --help
19335 \layout Subsubsection
19340 General options enable certain port features and optimizations.
19342 \labelwidthstring 00.00.0000
19354 -pstack-model=[model] Used in conjuction with the command above.
19355 Defines the stack model to be used, valid stack models are :
19358 \labelwidthstring 00.00.0000
19364 Selects small stack model.
19365 8 bit stack and frame pointers.
19366 Supports 256 bytes stack size.
19368 \labelwidthstring 00.00.0000
19374 Selects large stack model.
19375 16 bit stack and frame pointers.
19376 Supports 65536 bytes stack size.
19379 \labelwidthstring 00.00.0000
19391 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
19392 unitialized data variables with [kword].
19393 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
19395 \labelwidthstring 00.00.0000
19407 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
19408 Useful for bootloaders.
19410 \labelwidthstring 00.00.0000
19422 -asm= sets the full path and name of an external assembler to call.
19424 \labelwidthstring 00.00.0000
19436 -link= sets the full path and name of an external linker to call.
19438 \labelwidthstring 00.00.0000
19451 \begin_inset LatexCommand \index{PIC16!MPLAB}
19455 compatibility option.
19456 Currently only suppresses special gpasm directives.
19457 \layout Subsubsection
19459 Optimization Options
19461 \labelwidthstring 00.00.0000
19473 -optimize-goto Try to use (conditional) BRA instead of GOTO
19475 \labelwidthstring 00.00.0000
19487 -optimize-cmp Try to optimize some compares.
19489 \labelwidthstring 00.00.0000
19501 -optimize-df Analyze the dataflow of the generated code and improve it.
19503 \labelwidthstring 00.00.0000
19515 -obanksel=nn Set optimization level for inserting BANKSELs.
19520 \labelwidthstring 00.00.0000
19524 \labelwidthstring 00.00.0000
19526 1 checks previous used register and if it is the same then does not emit
19527 BANKSEL, accounts only for labels.
19529 \labelwidthstring 00.00.0000
19531 2 tries to check the location of (even different) symbols and removes BANKSELs
19532 if they are in the same bank.
19537 Important: There might be problems if the linker script has data sections
19538 across bank borders!
19540 \layout Subsubsection
19544 \labelwidthstring 00.00.0000
19556 -nodefaultlibs do not link default libraries when linking
19558 \labelwidthstring 00.00.0000
19570 -no-crt Don't link the default run-time modules
19572 \labelwidthstring 00.00.0000
19584 -use-crt= Use a custom run-time module instead of the defaults.
19585 \layout Subsubsection
19590 Debugging options enable extra debugging information in the output files.
19592 \labelwidthstring 00.00.0000
19604 -debug-xtra Similar to -
19615 \begin_inset LatexCommand \index{-\/-debug}
19619 , but dumps more information.
19621 \labelwidthstring 00.00.0000
19633 -debug-ralloc Force register allocator to dump <source>.d file with debugging
19635 <source> is the name of the file compiled.
19637 \labelwidthstring 00.00.0000
19649 -pcode-verbose Enable pcode debugging information in translation.
19651 \labelwidthstring 00.00.0000
19663 -denable-peeps Force the usage of peepholes.
19666 \labelwidthstring 00.00.0000
19678 -gstack Trace push/pops for stack pointer overflow
19680 \labelwidthstring 00.00.0000
19692 -call-tree dump call tree in .calltree file
19695 Enviromental Variables
19698 There is a number of enviromental variables that can be used when running
19699 SDCC to enable certain optimizations or force a specific program behaviour.
19700 these variables are primarily for debugging purposes so they can be enabled/dis
19704 Currently there is only two such variables available:
19706 \labelwidthstring 00.00.0000
19708 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
19709 bitfields is optimized by directly loading FSR0 with the address of the
19710 bitfield structure.
19711 Normally SDCC will cast the bitfield structure to a bitfield pointer and
19713 This step saves data ram and code space for functions that perform heavy
19716 80 bytes of code space are saved when compiling malloc.c with this option).
19719 \labelwidthstring 00.00.0000
19721 NO_REG_OPT do not perform pCode registers optimization.
19722 This should be used for debugging purposes.
19723 In some where bugs in the pcode optimizer are found, users can benefit
19724 from temporarily disabling the optimizer until the bug is fixed.
19727 Preprocessor Macros
19731 \begin_inset LatexCommand \index{PIC16}
19735 port defines the following preprocessor macros while translating a source.
19739 \begin_inset Tabular
19740 <lyxtabular version="3" rows="6" columns="2">
19742 <column alignment="center" valignment="top" leftline="true" width="0">
19743 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19744 <row topline="true" bottomline="true">
19745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19762 <row topline="true">
19763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19776 Port identification
19780 <row topline="true">
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19804 Port identification (same as above)
19808 <row topline="true">
19809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19822 MCU Identification.
19827 is the microcontrol identification number, i.e.
19832 <row topline="true">
19833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19856 MCU Identification (same as above)
19860 <row topline="true" bottomline="true">
19861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19874 nnn = SMALL or LARGE respectively according to the stack model used
19885 In addition the following macros are defined when calling assembler:
19889 \begin_inset Tabular
19890 <lyxtabular version="3" rows="4" columns="2">
19892 <column alignment="center" valignment="top" leftline="true" width="0">
19893 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19894 <row topline="true" bottomline="true">
19895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19912 <row topline="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19926 MCU Identification.
19931 is the microcontrol identification number, i.e.
19936 <row topline="true">
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19950 nnn = SMALL or LARGE respectively according to the memory model used for
19955 <row topline="true" bottomline="true">
19956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19969 nnn = SMALL or LARGE respectively according to the stack model used
19984 \begin_inset LatexCommand \index{PIC16}
19988 port uses the following directories for searching header files and libraries.
19992 \begin_inset Tabular
19993 <lyxtabular version="3" rows="3" columns="4">
19995 <column alignment="center" valignment="top" leftline="true" width="0">
19996 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19997 <column alignment="center" valignment="top" width="0">
19998 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19999 <row topline="true" bottomline="true">
20000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20033 <row topline="true">
20034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20039 PREFIX/sdcc/include/pic16
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20047 PIC16 specific headers
20050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20067 <row topline="true" bottomline="true">
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20073 PREFIX/sdcc/lib/pic16
20076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20081 PIC16 specific libraries
20084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20109 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
20117 \begin_inset LatexCommand \index{PIC16}
20121 port currently supports the following pragmas:
20123 \labelwidthstring 00.00.0000
20126 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
20131 \begin_inset LatexCommand \index{PIC16!stack}
20135 forces the code generator to initialize the stack & frame pointers at a
20137 This is an adhoc solution for cases where no STACK directive is available
20138 in the linker script or gplink is not instructed to create a stack section.
20140 The stack pragma should be used only once in a project.
20141 Multiple pragmas may result in indeterminate behaviour of the program.
20147 The old format (ie.
20148 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
20149 cross page boundaries (or even exceed the available data RAM) and crash
20151 Make sure that stack does not cross page boundaries when using the SMALL
20157 The format is as follows:
20160 #pragma stack bottom_address [stack_size]
20167 is the lower bound of the stack section.
20168 The stack pointer initially will point at address (bottom_address+stack_size-1).
20176 /* initializes stack of 100 bytes at RAM address 0x200 */
20179 #pragma stack 0x200 100
20182 If the stack_size field is omitted then a stack is created with the default
20184 This size might be enough for most programs, but its not enough for operations
20185 with deep function nesting or excessive stack usage.
20187 \labelwidthstring 00.00.0000
20190 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
20194 place a function symbol at static FLASH address
20202 /* place function test_func at 0x4000 */
20205 #pragma code test_func 0x4000
20209 \labelwidthstring 00.00.0000
20211 library instructs the linker to use a library module.
20216 #pragma library module_name
20223 can be any library or object file (including its path).
20224 Note that there are four reserved keywords which have special meaning.
20229 \begin_inset Tabular
20230 <lyxtabular version="3" rows="6" columns="3">
20232 <column alignment="center" valignment="top" leftline="true" width="0">
20233 <column alignment="block" valignment="top" leftline="true" width="20page%">
20234 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20235 <row topline="true" bottomline="true">
20236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20261 <row topline="true">
20262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20277 ignore all library pragmas
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20291 <row topline="true">
20292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20323 <row topline="true">
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 link the Math libarary
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20355 <row topline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20371 link the I/O library
20374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20387 <row topline="true" bottomline="true">
20388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20403 link the debug library
20406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20425 * is the device number, i.e.
20426 452 for PIC18F452 MCU.
20429 This feature allows for linking with specific libraries withoug having to
20430 explicit name them in the command line.
20435 keyword will reject all modules specified by the library pragma.
20437 \labelwidthstring 00.00.0000
20439 udata pragma udata instructs the compiler to emit code so that linker will
20440 place a variable at a specific memory bank
20448 /* places variable foo at bank2 */
20451 #pragma udata bank2 foo
20457 In order for this pragma to work extra SECTION directives should be added
20458 in the .lkr script.
20459 In the following example a sample .lkr file is shown:
20464 // Sample linker script for the PIC18F452 processor
20470 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
20473 CODEPAGE NAME=page START=0x2A END=0x7FFF
20476 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
20479 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
20482 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
20485 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
20488 ACCESSBANK NAME=accessram START=0x0 END=0x7F
20493 DATABANK NAME=gpr0 START=0x80 END=0xFF
20496 DATABANK NAME=gpr1 START=0x100 END=0x1FF
20499 DATABANK NAME=gpr2 START=0x200 END=0x2FF
20502 DATABANK NAME=gpr3 START=0x300 END=0x3FF
20505 DATABANK NAME=gpr4 START=0x400 END=0x4FF
20508 DATABANK NAME=gpr5 START=0x500 END=0x5FF
20511 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
20516 SECTION NAME=CONFIG ROM=config
20521 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
20524 SECTION NAME=bank1 RAM=gpr1 # should be added to link
20527 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
20530 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
20533 SECTION NAME=bank4 RAM=gpr4
20536 SECTION NAME=bank5 RAM=gpr5
20539 The linker will recognise the section name set in the pragma statement and
20540 will position the variable at the memory bank set with the RAM field at
20541 the SECTION line in the linker script file.
20545 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
20552 There is one main header file
20553 \begin_inset LatexCommand \index{PIC16!Header files}
20557 that can be included to the source files using the pic16
20558 \begin_inset LatexCommand \index{PIC16}
20568 This header file contains the definitions for the processor special registers,
20569 so it is necessary if the source accesses them.
20570 It can be included by adding the following line in the beginning of the
20574 #include <pic18fregs.h>
20577 The specific microcontroller is selected within the pic18fregs.h automatically,
20578 so the same source can be used with a variety of devices.
20585 \begin_inset LatexCommand \index{PIC16!Libraries}
20590 \begin_inset LatexCommand \index{PIC16}
20594 port depends on are the microcontroller device libraries which contain
20595 the symbol definitions for the microcontroller special function registers.
20596 These libraries have the format pic18fxxxx.lib, where
20600 is the microcontroller identification number.
20601 The specific library is selected automatically by the compiler at link
20602 stage according to the selected device.
20605 Libraries are created with gplib which is part of the gputils package
20606 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
20611 \layout Subsubsection*
20613 Building the libraries
20616 Before using SDCC/pic16 there are some libraries that need to be compiled.
20617 This process is not done automatically by SDCC since not all users use
20618 SDCC for pic16 projects.
20619 So each user should compile the libraries separately.
20622 The steps to compile the pic16 libraries under Linux are:
20625 cd device/lib/pic16
20640 su -c 'make install' # install the libraries, you need the root password
20643 If you need to install the headers too, do:
20649 su -c 'make install' # install the headers, you need the root password
20652 There exist a special target to build the I/O libraries.
20653 This target is not automatically build because it will build the I/O library
20659 This way building will take quite a lot of time.
20660 Users are advised to edit the
20662 device/lib/pic16/pics.build
20664 file and then execute:
20673 The following memory models are supported by the PIC16 port:
20682 Memory model affects the default size of pointers within the source.
20683 The sizes are shown in the next table:
20687 \begin_inset Tabular
20688 <lyxtabular version="3" rows="3" columns="3">
20690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20691 <column alignment="center" valignment="top" leftline="true" width="0">
20692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20693 <row topline="true" bottomline="true">
20694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20699 Pointer sizes according to memory model
20702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20719 <row topline="true" bottomline="true">
20720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20728 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20745 <row topline="true" bottomline="true">
20746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20754 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20778 It is advisable that all sources within a project are compiled with the
20780 If one wants to override the default memory model, this can be done by
20781 declaring a pointer as
20790 Far selects large memory model's pointers, while near selects small memory
20794 The standard device libraries (see
20795 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
20799 ) contain no reference to pointers, so they can be used with both memory
20807 \begin_inset LatexCommand \index{PIC16!stack}
20811 implementation for the PIC16 port uses two indirect registers, FSR1 and
20814 \labelwidthstring 00.00.0000
20816 FSR1 is assigned as stack pointer
20818 \labelwidthstring 00.00.0000
20820 FSR2 is assigned as frame pointer
20823 The following stack models are supported by the PIC16 port
20844 model means that only the FSRxL byte is used to access stack and frame,
20851 uses both FSRxL and FSRxH registers.
20852 The following table shows the stack/frame pointers sizes according to stack
20853 model and the maximum space they can address:
20857 \begin_inset Tabular
20858 <lyxtabular version="3" rows="3" columns="3">
20860 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20861 <column alignment="center" valignment="top" leftline="true" width="0">
20862 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20863 <row topline="true" bottomline="true">
20864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20869 Stack & Frame pointer sizes according to stack model
20872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20889 <row topline="true">
20890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20915 <row topline="true" bottomline="true">
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20952 stack model is currently not working properly throughout the code generator.
20953 So its use is not advised.
20954 Also there are some other points that need special care:
20959 Do not create stack sections with size more than one physical bank (that
20963 Stack sections should no cross physical bank limits (i.e.
20964 #pragma stack 0x50 0x100)
20967 These limitations are caused by the fact that only FSRxL is modified when
20968 using SMALL stack model, so no more than 256 bytes of stack can be used.
20969 This problem will disappear after LARGE model is fully implemented.
20975 In addition to the standard SDCC function keywords, PIC16
20976 \begin_inset LatexCommand \index{PIC16}
20980 port makes available two more:
20982 \labelwidthstring 00.00.0000
20985 \begin_inset LatexCommand \index{PIC16!wparam}
20989 Use the WREG to pass one byte of the first function argument.
20990 This improves speed but you may not use this for functions with arguments
20991 that are called via function pointers, otherwise the first byte of the
20992 first parameter will get lost.
20996 void func_wparam(int a) wparam
21002 /* WREG hold the lower part of a */
21005 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
21014 \labelwidthstring 00.00.0000
21017 \begin_inset LatexCommand \index{PIC16!shadowregs}
21021 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
21022 hardware shadow registers which hold the values of WREG, STATUS and BSR
21024 This can be done by adding the keyword
21032 keyword in the function's header.
21035 void isr_shadow(void) shadowregs interrupt 1
21051 instructs the code generator not to store/restore WREG, STATUS, BSR when
21052 entering/exiting the ISR.
21055 Function return values
21058 Return values from functions are placed to the appropriate registers following
21059 a modified Microchip policy optimized for SDCC.
21060 The following table shows these registers:
21064 \begin_inset Tabular
21065 <lyxtabular version="3" rows="6" columns="2">
21067 <column alignment="center" valignment="top" leftline="true" width="0">
21068 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21069 <row topline="true" bottomline="true">
21070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21083 destination register
21087 <row topline="true">
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21105 <row topline="true">
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21123 <row topline="true">
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21141 <row topline="true">
21142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21155 FSR0L:PRODH:PRODL:WREG
21159 <row topline="true" bottomline="true">
21160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21173 on stack, FSR0 points to the beginning
21188 \begin_inset LatexCommand \index{PIC16!interrupt}
21192 service routine (ISR) is declared using the
21199 void isr(void) interrupt
21217 is the interrupt number, which for PIC18F devices can be:
21221 \begin_inset Tabular
21222 <lyxtabular version="3" rows="4" columns="3">
21224 <column alignment="center" valignment="top" leftline="true" width="0">
21225 <column alignment="center" valignment="top" leftline="true" width="0">
21226 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21227 <row topline="true" bottomline="true">
21228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21251 Interrupt Vector Address
21255 <row topline="true">
21256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21281 <row topline="true">
21282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21313 HIGH priority interrupts
21316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21325 <row topline="true" bottomline="true">
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21339 LOW priority interrupts
21342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21358 When generating assembly code for ISR the code generator places a
21364 Interrupt Vector Address
21366 which points at the genetated ISR.
21367 This single GOTO instruction is part of an automatically generated
21369 interrupt entry point
21372 The actuall ISR code is placed as normally would in the code space.
21373 Upon interrupt request, the GOTO instruction is executed which jumps to
21375 When declaring interrupt functions as _naked this GOTO instruction is
21380 The whole interrupt functions is therefore placed at the Interrupt Vector
21381 Address of the specific interrupt.
21382 This is not a problem for the LOW priority interrupts, but it is a problem
21383 for the RESET and the HIGH priority interrupts because code may be written
21384 at the next interrupt´s vector address and cause undeterminate program
21385 behaviour if that interrupt is raised.
21391 This is not a problem when
21394 this is a HIGH interrupt ISR and LOW interrupts are
21401 when the ISR is small enough not to reach the next interrupt´s vector address.
21411 is possible to be omitted.
21412 This way a function is generated similar to an ISR, but it is not assigned
21416 When entering an interrupt, currently the PIC16
21417 \begin_inset LatexCommand \index{PIC16}
21421 port automatically saves the following registers:
21433 PROD (PRODL and PRODH)
21436 FSR0 (FSR0L and FSR0H)
21439 These registers are restored upon return from the interrupt routine.
21445 NOTE that when the _naked attribute is specified for an interrupt routine,
21446 then NO registers are stored or restored.
21455 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
21456 There are 3 types of generic pointers currently implemented data, code
21457 and eeprom pointers.
21458 They are differentiated by the value of the 7th and 6th bits of the upper
21463 \begin_inset Tabular
21464 <lyxtabular version="3" rows="5" columns="5">
21466 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21467 <column alignment="center" valignment="top" width="0">
21468 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21469 <column alignment="center" valignment="top" width="0">
21470 <column alignment="left" valignment="top" rightline="true" width="0">
21471 <row topline="true" bottomline="true">
21472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21501 rest of the pointer
21504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21513 <row topline="true" bottomline="true">
21514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21547 uuuuuu uuuuxxxx xxxxxxxx
21550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21555 a 12-bit data pointer in data RAM memory
21559 <row bottomline="true">
21560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
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">
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21593 uxxxxx xxxxxxxx xxxxxxxx
21596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21601 a 21-bit code pointer in FLASH memory
21605 <row bottomline="true">
21606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21639 uuuuuu uuuuuuxx xxxxxxxx
21642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21647 a 10-bit eeprom pointer in EEPROM memory
21651 <row bottomline="true">
21652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21685 xxxxxx xxxxxxxx xxxxxxxx
21688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21693 unimplemented pointer type
21704 Generic pointer are read and written with a set of library functions which
21705 read/write 1, 2, 3, 4 bytes.
21709 \layout Subsubsection
21711 Standard I/O Streams
21718 the type FILE is defined as:
21721 typedef char * FILE;
21724 This type is the stream type implemented I/O in the PIC18F devices.
21725 Also the standard input and output streams are declared in stdio.h:
21728 extern FILE * stdin;
21731 extern FILE * stdout;
21734 The FILE type is actually a generic pointer which defines one more type
21735 of generic pointers, the
21740 This new type has the format:
21744 \begin_inset Tabular
21745 <lyxtabular version="3" rows="2" columns="7">
21747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21748 <column alignment="center" valignment="top" width="0">
21749 <column alignment="center" valignment="top" leftline="true" width="0">
21750 <column alignment="center" valignment="top" leftline="true" width="0">
21751 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21752 <column alignment="center" valignment="top" width="0">
21753 <column alignment="left" valignment="top" rightline="true" width="0">
21754 <row topline="true" bottomline="true">
21755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21800 rest of the pointer
21803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21812 <row topline="true" bottomline="true">
21813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21870 upper byte high nubble is 0x2n, the rest are zeroes
21881 Currently implemented there are 3 types of streams defined:
21885 \begin_inset Tabular
21886 <lyxtabular version="3" rows="4" columns="4">
21888 <column alignment="center" valignment="top" leftline="true" width="0">
21889 <column alignment="center" valignment="top" leftline="true" width="0">
21890 <column alignment="center" valignment="top" leftline="true" width="0">
21891 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21892 <row topline="true" bottomline="true">
21893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21926 <row topline="true">
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21958 Writes/Reads characters via the USART peripheral
21962 <row topline="true">
21963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21994 Writes/Reads characters via the MSSP peripheral
21998 <row topline="true" bottomline="true">
21999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22030 Writes/Reads characters via used defined functions
22041 The stream identifiers are declared as macros in the stdio.h header.
22044 In the libc library there exist the functions that are used to write to
22045 each of the above streams.
22048 \labelwidthstring 00.00.0000
22060 _stream_usart_putchar writes a character at the USART stream
22062 \labelwidthstring 00.00.0000
22074 _stream_mssp_putchar writes a character at the MSSP stream
22076 \labelwidthstring 00.00.0000
22078 putchar dummy function.
22079 This writes a character to a user specified manner.
22082 In order to increase performance
22086 is declared in stdio.h as having its parameter in WREG (it has the wparam
22088 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
22089 in a user-friendly way.
22094 is the name of the variable that holds the character to print.
22095 An example follows:
22098 #include <pic18fregs.h>
22110 PORTA = c; /* dump character c to PORTA */
22123 stdout = STREAM_USER; /* this is not necessary, since stdout points
22126 * by default to STREAM_USER */
22129 printf (¨This is a printf test
22137 \layout Subsubsection
22142 PIC16 contains an implementation of the printf-family of functions.
22143 There exist the following functions:
22146 extern unsigned int sprintf(char *buf, char *fmt, ...);
22149 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
22154 extern unsigned int printf(char *fmt, ...);
22157 extern unsigned int vprintf(char *fmt, va_lista ap);
22162 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
22165 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
22168 For sprintf and vsprintf
22172 should normally be a data pointer where the resulting string will be placed.
22173 No range checking is done so the user should allocate the necessery buffer.
22174 For fprintf and vfprintf
22178 should be a stream pointer (i.e.
22179 stdout, STREAM_MSSP, etc...).
22180 \layout Subsubsection
22185 The PIC18F family of microcontrollers supports a number of interrupt sources.
22186 A list of these interrupts is shown in the following table:
22190 \begin_inset Tabular
22191 <lyxtabular version="3" rows="11" columns="4">
22193 <column alignment="left" valignment="top" leftline="true" width="0">
22194 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22195 <column alignment="left" valignment="top" leftline="true" width="0">
22196 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22197 <row topline="true" bottomline="true">
22198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22231 <row topline="true">
22232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22240 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22245 PORTB change interrupt
22248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22261 EEPROM/FLASH write complete interrupt
22265 <row topline="true">
22266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22279 INT0 external interrupt
22282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22295 Bus collision interrupt
22299 <row topline="true">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22313 INT1 external interrupt
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22329 Low voltage detect interrupt
22333 <row topline="true">
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22347 INT2 external interrupt
22350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22363 Parallel slave port interrupt
22367 <row topline="true">
22368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22381 CCP1 module interrupt
22384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22397 AD convertion complete interrupt
22401 <row topline="true">
22402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22415 CCP2 module interrupt
22418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22431 USART receive interrupt
22435 <row topline="true">
22436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22449 TMR0 overflow interrupt
22452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22465 USART transmit interrupt
22469 <row topline="true">
22470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22483 TMR1 overflow interrupt
22486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22499 SSP receive/transmit interrupt
22503 <row topline="true">
22504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22517 TMR2 matches PR2 interrupt
22520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22535 <row topline="true" bottomline="true">
22536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22549 TMR3 overflow interrupt
22552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22574 The prototypes for these names are defined in the header file
22581 In order to simplify signal handling, a number of macros is provided:
22583 \labelwidthstring 00.00.0000
22585 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
22586 high priority interrupts.
22591 is the function name to use.
22593 \labelwidthstring 00.00.0000
22595 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
22596 low priority interrupt.
22601 is the function name to use.
22603 \labelwidthstring 00.00.0000
22605 DEF_HANDLER(sig,handler) define a handler for signal
22609 \labelwidthstring 00.00.0000
22611 END_DEF end the declaration of the dispatch table.
22614 Additionally there are two more macros to simplify the declaration of the
22617 \labelwidthstring 00.00.0000
22621 SIGHANDLER(handler)
22623 this declares the function prototype for the
22629 \labelwidthstring 00.00.0000
22631 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
22634 An example of using the macros above is shown below:
22637 #include <pic18fregs.h>
22640 #include <signal.h>
22644 DEF_INTHIGH(high_int)
22647 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
22650 DEF_HANDLER(SIG_BCOL, _bcol_handler)
22657 SIGHANDLER(_tmr0_handler)
22663 /* action to be taken when timer 0 overflows */
22670 SIGHANDLERNAKED(_bcol_handler)
22679 /* action to be taken when bus collision occurs */
22695 Special care should be taken when using the above scheme:
22698 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
22701 when declaring SIGHANDLERNAKED handler never forget to use
22705 for proper returning.
22711 Here you can find some general tips for compiling programs with SDCC/pic16.
22712 \layout Subsubsection
22718 \begin_inset LatexCommand \index{PIC16!stack}
22722 size (that is 64 bytes) probably is enough for many programs.
22723 One must take care that when there are many levels of function nesting,
22724 or there is excessive usage of stack, its size should be extended.
22725 An example of such a case is the printf/sprintf family of functions.
22726 If you encounter problems like not being able to print integers, then you
22727 need to set the stack size around the maximum (256 for small stack model).
22728 The following diagram shows what happens when calling printf to print an
22732 printf () --> ltoa () --> ultoa () --> divschar ()
22735 It is should be understood that stack is easily consumed when calling complicate
22737 Using command line arguments like -
22747 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
22749 Other ways to reduce stack usage may exist.
22755 The PIC16 Port currently does not pass SDCC's regression test
22756 \begin_inset LatexCommand \index{Regression test (PIC16)}
22761 \begin_inset LatexCommand \ref{sec:Quality-control}
22765 ) and thus the nightly regression tests for the PIC16 target are currently
22766 disabled for all hosts except for
22771 This means you can see the result of the PIC16 regression tests f.e.
22772 by checking the log files in
22773 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
22777 (pick the most up to date file there, scroll down, lend a hand).
22783 There are several approaches to debugging your code.
22784 This chapter is meant to show your options and to give detail on some of
22789 When writing your code:
22792 write your code with debugging in mind (avoid duplicating code, put conceptually
22793 similar variables into structs, use structured code, have strategic points
22794 within your code where all variables are consistent, ...)
22797 run a syntax-checking tool like splint
22798 \begin_inset LatexCommand \index{splint (syntax checking tool)}
22803 \begin_inset LatexCommand \index{lint (syntax checking tool)}
22818 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22825 for the high level code use a C-compiler (like f.e.
22826 GCC) to compile run and debug the code on your host.
22838 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22842 ) on howto handle syntax extensions like __xdata, __at(), ...
22846 use another C-compiler to compile code for your target.
22847 Always an option but not recommended:) And not very likely to help you.
22848 If you seriously consider walking this path you should at least occasionally
22849 check portability of your code.
22850 Most commercial compiler vendors will offer an evaluation version so you
22851 can test compile your code or snippets of your code.
22854 Debugging on a simulator:
22857 there is a separate section about SDCDB (section
22858 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
22865 or (8051 specific) use a freeware/commercial simulator which interfaces
22867 \begin_inset LatexCommand \index{AOMF, AOMF51}
22872 \begin_inset LatexCommand \ref{OMF file}
22876 ) optionally generated by SDCC.
22879 Debugging On-target:
22882 use a MCU port pin to serially output debug data to the RS232 port of your
22884 You'll probably want some level shifting device typically involving a MAX232
22886 If the hardware serial port of the MCU is not available search for 'Software
22887 UART' in your favourite search machine.
22890 use an on-target monitor.
22891 In this context a monitor is a small program which usually accepts commands
22892 via a serial line and allows to set program counter, to single step through
22893 a program and read/write memory locations.
22894 For the 8051 good examples of monitors are paulmon and cmon51 (see section
22896 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
22903 toggle MCU port pins at strategic points within your code and use an oscilloscop
22907 digital oscilloscope
22910 \begin_inset LatexCommand \index{Oscilloscope}
22914 with deep trace memory is really helpful especially if you have to debug
22915 a realtime application.
22916 If you need to monitor more pins than your oscilloscope provides you can
22917 sometimes get away with a small R-2R network.
22918 On a single channel oscilloscope you could f.e.
22919 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
22921 \begin_inset Formula $\Omega$
22924 resistor and the other one by a 5\SpecialChar ~
22926 \begin_inset Formula $\Omega$
22929 resistor to the oscilloscope probe (check output drive capability of the
22930 pins you want to monitor).
22931 If you need to monitor many more pins a
22951 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
22956 Usually very expensive.
22957 And very nice to have too.
22958 And usually locks you (for years...) to the devices the ICE can emulate.
22962 use a remote debugger.
22963 In most 8-bit systems the symbol information is not available on the target,
22964 and a complete debugger is too bulky for the target system.
22965 Therefore usually a debugger on the host system connects to an on-target
22966 debugging stub which accepts only primitive commands.
22969 Terms to enter into your favourite search engine could be 'remote debugging',
22970 'gdb stub' or 'inferior debugger'.
22974 use an on target hardware debugger.
22975 Some of the more modern MCUs include hardware support for setting break
22976 points and monitoring/changing variables by using dedicated hardware pins.
22977 This facility doesn't require additional code to run on the target and
22982 doesn't affect runtime behaviour until a breakpoint is hit.
22983 For the mcs51 most hardware debuggers use the AOMF
22984 \begin_inset LatexCommand \index{AOMF, AOMF51}
22989 \begin_inset LatexCommand \ref{OMF file}
23000 if you are not familiar with any of the following terms you're likely to
23001 run into problems rather sooner than later:
23018 As an embedded programmer you
23022 to know them so why not look them up
23026 you have problems?)
23029 tell someone else about your problem (actually this is a surprisingly effective
23030 means to hunt down the bug even if the listener is not familiar with your
23032 As 'failure to communicate' is probably one of the job-induced deformations
23033 of an embedded programmer this is highly encouraged.
23036 Debugging with SDCDB
23037 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
23042 \begin_inset LatexCommand \index{SDCDB (debugger)}
23049 SDCC is distributed with a source level debugger
23050 \begin_inset LatexCommand \index{Debugger}
23055 The debugger uses a command line interface, the command repertoire of the
23056 debugger has been kept as close to gdb
23057 \begin_inset LatexCommand \index{gdb}
23061 (the GNU debugger) as possible.
23062 The configuration and build process is part of the standard compiler installati
23063 on, which also builds and installs the debugger in the target directory
23064 specified during configuration.
23065 The debugger allows you debug BOTH at the C source and at the ASM source
23069 Compiling for Debugging
23083 \begin_inset LatexCommand \index{-\/-debug}
23087 option must be specified for all files for which debug information is to
23089 The compiler generates a .adb file for each of these files.
23090 The linker creates the .cdb
23091 \begin_inset LatexCommand \index{<file>.cdb}
23096 \begin_inset LatexCommand \index{<file>.adb}
23100 files and the address information.
23101 This .cdb is used by the debugger.
23104 How the Debugger Works
23117 -debug option is specified the compiler generates extra symbol information
23118 some of which are put into the assembler source and some are put into the
23120 Then the linker creates the .cdb file from the individual .adb files with
23121 the address information for the symbols.
23122 The debugger reads the symbolic information generated by the compiler &
23123 the address information generated by the linker.
23124 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
23125 execution is controlled by the debugger.
23126 When a command is issued for the debugger, it translates it into appropriate
23127 commands for the simulator.
23128 (Currently SDCDM only connects to the simulator but
23133 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
23137 is an effort to connect directly to the hardware.)
23140 Starting the Debugger SDCDB
23143 The debugger can be started using the following command line.
23144 (Assume the file you are debugging has the file name foo).
23158 The debugger will look for the following files.
23161 foo.c - the source file.
23164 foo.cdb - the debugger symbol information file.
23167 foo.ihx - the Intel hex format
23168 \begin_inset LatexCommand \index{Intel hex format}
23175 SDCDB Command Line Options
23188 -directory=<source file directory> this option can used to specify the directory
23190 The debugger will look into the directory list specified for source, cdb
23192 The items in the directory list must be separated by ':', e.g.
23193 if the source files can be in the directories /home/src1 and /home/src2,
23204 -directory option should be -
23214 -directory=/home/src1:/home/src2.
23215 Note there can be no spaces in the option.
23219 -cd <directory> - change to the <directory>.
23222 -fullname - used by GUI front ends.
23225 -cpu <cpu-type> - this argument is passed to the simulator please see the
23226 simulator docs for details.
23229 -X <Clock frequency > this options is passed to the simulator please see
23230 the simulator docs for details.
23233 -s <serial port file> passed to simulator see the simulator docs for details.
23236 -S <serial in,out> passed to simulator see the simulator docs for details.
23239 -k <port number> passed to simulator see the simulator docs for details.
23242 SDCDB Debugger Commands
23245 As mentioned earlier the command interface for the debugger has been deliberatel
23246 y kept as close the GNU debugger gdb, as possible.
23247 This will help the integration with existing graphical user interfaces
23248 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
23249 If you use a graphical user interface for the debugger you can skip this
23251 \layout Subsubsection*
23253 break [line | file:line | function | file:function]
23256 Set breakpoint at specified line or function:
23265 sdcdb>break foo.c:100
23267 sdcdb>break funcfoo
23269 sdcdb>break foo.c:funcfoo
23270 \layout Subsubsection*
23272 clear [line | file:line | function | file:function ]
23275 Clear breakpoint at specified line or function:
23284 sdcdb>clear foo.c:100
23286 sdcdb>clear funcfoo
23288 sdcdb>clear foo.c:funcfoo
23289 \layout Subsubsection*
23294 Continue program being debugged, after breakpoint.
23295 \layout Subsubsection*
23300 Execute till the end of the current function.
23301 \layout Subsubsection*
23306 Delete breakpoint number 'n'.
23307 If used without any option clear ALL user defined break points.
23308 \layout Subsubsection*
23310 info [break | stack | frame | registers ]
23313 info break - list all breakpoints
23316 info stack - show the function call stack.
23319 info frame - show information about the current execution frame.
23322 info registers - show content of all registers.
23323 \layout Subsubsection*
23328 Step program until it reaches a different source line.
23329 Note: pressing <return> repeats the last command.
23330 \layout Subsubsection*
23335 Step program, proceeding through subroutine calls.
23336 \layout Subsubsection*
23341 Start debugged program.
23342 \layout Subsubsection*
23347 Print type information of the variable.
23348 \layout Subsubsection*
23353 print value of variable.
23354 \layout Subsubsection*
23359 load the given file name.
23360 Note this is an alternate method of loading file for debugging.
23361 \layout Subsubsection*
23366 print information about current frame.
23367 \layout Subsubsection*
23372 Toggle between C source & assembly source.
23373 \layout Subsubsection*
23375 ! simulator command
23378 Send the string following '!' to the simulator, the simulator response is
23380 Note the debugger does not interpret the command being sent to the simulator,
23381 so if a command like 'go' is sent the debugger can loose its execution
23382 context and may display incorrect values.
23383 \layout Subsubsection*
23390 My name is Bobby Brown"
23393 Interfacing SDCDB with DDD
23396 The screenshot was converted from png to eps with:
23397 \begin_inset Quotes sld
23400 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
23401 \begin_inset Quotes srd
23404 which produces a pretty compact eps file which is free from compression
23408 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
23409 as this broke the build system on Sourceforge (pdf-file was broken.
23410 pdflatex does not accept eps files).
23428 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
23434 shows a screenshot of a debugging session with DDD
23435 \begin_inset LatexCommand \index{DDD (debugger)}
23439 (Unix only) on a simulated 8032.
23440 The debugging session might not run as smoothly as the screenshot suggests.
23441 The debugger allows setting of breakpoints, displaying and changing variables,
23442 single stepping through C and assembler code.
23445 The source was compiled with
23468 -debug ddd_example.c
23481 and DDD was invoked with
23488 ddd -debugger "sdcdb -cpu 8032 ddd_example"
23497 Check that the double quotes or an apostroph within the command line survive
23498 the LyX tool chain.
23499 Previously the apostrophs got slanted in the PDF output so a cut and paste
23506 Interfacing SDCDB with XEmacs
23507 \begin_inset LatexCommand \index{XEmacs}
23512 \begin_inset LatexCommand \index{Emacs}
23519 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
23520 sdcdb.el and sdcdbsrc.el.
23521 These two files can be found in the $(prefix)/bin directory after the installat
23523 These files need to be loaded into XEmacs for the interface to work.
23524 This can be done at XEmacs startup time by inserting the following into
23525 your '.xemacs' file (which can be found in your HOME directory):
23531 (load-file sdcdbsrc.el)
23537 .xemacs is a lisp file so the () around the command is REQUIRED.
23538 The files can also be loaded dynamically while XEmacs is running, set the
23539 environment variable 'EMACSLOADPATH' to the installation bin directory
23540 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
23541 To start the interface enter the following command:
23555 You will prompted to enter the file name to be debugged.
23560 The command line options that are passed to the simulator directly are bound
23561 to default values in the file sdcdbsrc.el.
23562 The variables are listed below, these values maybe changed as required.
23565 sdcdbsrc-cpu-type '51
23568 sdcdbsrc-frequency '11059200
23571 sdcdbsrc-serial nil
23574 The following is a list of key mapping for the debugger interface.
23585 ;;key\SpecialChar ~
23599 binding\SpecialChar ~
23623 ;;---\SpecialChar ~
23637 -------\SpecialChar ~
23679 sdcdb-next-from-src\SpecialChar ~
23707 sdcdb-back-from-src\SpecialChar ~
23735 sdcdb-cont-from-src\SpecialChar ~
23745 SDCDB continue command
23763 sdcdb-step-from-src\SpecialChar ~
23791 sdcdb-whatis-c-sexp\SpecialChar ~
23801 SDCDB ptypecommand for data at
23868 sdcdbsrc-delete\SpecialChar ~
23882 SDCDB Delete all breakpoints if no arg
23931 given or delete arg (C-u arg x)
23949 sdcdbsrc-frame\SpecialChar ~
23964 SDCDB Display current frame if no arg,
24013 given or display frame arg
24080 sdcdbsrc-goto-sdcdb\SpecialChar ~
24090 Goto the SDCDB output buffer
24108 sdcdb-print-c-sexp\SpecialChar ~
24119 SDCDB print command for data at
24186 sdcdbsrc-goto-sdcdb\SpecialChar ~
24196 Goto the SDCDB output buffer
24214 sdcdbsrc-mode\SpecialChar ~
24230 Toggles Sdcdbsrc mode (turns it off)
24245 sdcdb-finish-from-src\SpecialChar ~
24253 SDCDB finish command
24268 sdcdb-break\SpecialChar ~
24286 Set break for line with point
24301 sdcdbsrc-mode\SpecialChar ~
24317 Toggle Sdcdbsrc mode
24332 sdcdbsrc-srcmode\SpecialChar ~
24355 Here are a few guidelines that will help the compiler generate more efficient
24356 code, some of the tips are specific to this compiler others are generally
24357 good programming practice.
24360 Use the smallest data type to represent your data-value.
24361 If it is known in advance that the value is going to be less than 256 then
24362 use an 'unsigned char' instead of a 'short' or 'int'.
24363 Please note, that ANSI C requires both signed and unsigned chars to be
24364 promoted to 'signed int'
24365 \begin_inset LatexCommand \index{promotion to signed int}
24370 \begin_inset Marginal
24381 before doing any operation.
24383 \begin_inset LatexCommand \index{type promotion}
24388 \begin_inset LatexCommand \label{type promotion}
24392 can be omitted, if the result is the same.
24393 The effect of the promotion rules together with the sign-extension is often
24400 unsigned char uc = 0xfe;
24402 if (uc * uc < 0) /* this is true! */
24421 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
24431 (unsigned char) -12 / (signed char) -3 = ...
24434 No, the result is not 4:
24439 (int) (unsigned char) -12 / (int) (signed char) -3 =
24441 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
24443 (int) 0x00f4 / (int) 0xfffd =
24445 (int) 0x00f4 / (int) 0xfffd =
24447 (int) 244 / (int) -3 =
24449 (int) -81 = (int) 0xffaf;
24452 Don't complain, that gcc gives you a different result.
24453 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
24454 Therefore the results are different.
24457 \begin_inset Quotes sld
24461 \begin_inset Quotes srd
24469 If well-defined overflow characteristics are important and negative values
24470 are not, or if you want to steer clear of sign-extension problems when
24471 manipulating bits or bytes, use one of the corresponding unsigned types.
24472 (Beware when mixing signed and unsigned values in expressions, though.)
24474 Although character types (especially unsigned char) can be used as "tiny"
24475 integers, doing so is sometimes more trouble than it's worth, due to unpredicta
24476 ble sign extension and increased code size.
24480 Use unsigned when it is known in advance that the value is not going to
24482 This helps especially if you are doing division or multiplication, bit-shifting
24483 or are using an array index.
24486 NEVER jump into a LOOP.
24489 Declare the variables to be local
24490 \begin_inset LatexCommand \index{local variables}
24494 whenever possible, especially loop control variables (induction).
24497 Have a look at the assembly listing to get a
24498 \begin_inset Quotes sld
24502 \begin_inset Quotes srd
24505 for the code generation.
24508 Porting code from or to other compilers
24509 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
24516 check whether endianness of the compilers differs and adapt where needed.
24519 check the device specific header files
24520 \begin_inset LatexCommand \index{Header files}
24525 \begin_inset LatexCommand \index{Include files}
24529 for compiler specific syntax.
24530 Eventually include the file <compiler.h
24531 \begin_inset LatexCommand \index{compiler.h (include file)}
24536 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
24540 to allow using common header files.
24543 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
24550 check whether the startup code contains the correct initialization (watchdog,
24554 check whether the sizes of short, int, long match.
24557 check if some 16 or 32 bit hardware registers require a specific addressing
24558 order (least significant or most significant byte first) and adapt if needed
24567 relate to time and not to lower/upper memory location here, so this is
24572 the same as endianness).
24575 check whether the keyword
24579 is used where needed.
24580 The compilers might differ in their optimization characteristics (as different
24581 versions of the same compiler might also use more clever optimizations
24582 this is good idea anyway).
24584 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
24591 check that the compilers are not told to supress warnings.
24594 check and convert compiler specific extensions (interrupts, memory areas,
24598 check for differences in type promotion.
24599 Especially check for math operations on
24608 For the sake of C99 compatibility SDCC will probably promote these to
24612 more often than other compilers.
24613 Eventually insert explicit casts to
24622 Also check that the ~\SpecialChar ~
24624 \begin_inset LatexCommand \index{\~\/ Operator}
24631 \begin_inset LatexCommand \index{bit}
24637 variables, use the !\SpecialChar ~
24640 \begin_inset LatexCommand \ref{type promotion}
24645 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
24652 check the assembly code generated for interrupt routines (f.e.
24653 for calls to possibly non-reentrant library functions).
24656 check whether timing loops result in proper timing (or preferably consider
24657 a rewrite of the code with timer based delays instead).
24660 check for differences in printf parameters (some compilers push (va_arg
24661 \begin_inset LatexCommand \index{vararg, va\_arg}
24665 ) char variables as
24669 others push them as
24675 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
24682 check the resulting memory map
24683 \begin_inset LatexCommand \index{Memory map}
24688 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
24689 ly idata, pdata, xdata).
24690 Eventually check if unexpected library functions are included.
24694 \begin_inset LatexCommand \index{Tools}
24698 included in the distribution
24702 \begin_inset Tabular
24703 <lyxtabular version="3" rows="12" columns="3">
24705 <column alignment="left" valignment="top" leftline="true" width="0pt">
24706 <column alignment="left" valignment="top" leftline="true" width="0pt">
24707 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
24708 <row topline="true" bottomline="true">
24709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24740 <row topline="true">
24741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24747 \begin_inset LatexCommand \index{uCsim}
24754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24759 Simulator for various architectures
24762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24771 <row topline="true">
24772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24786 \begin_inset LatexCommand \index{Header files}
24791 \begin_inset LatexCommand \index{Include files}
24798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24803 sdcc/support/scripts
24807 <row topline="true">
24808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24821 header file conversion
24824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24829 sdcc/support/scripts
24833 <row topline="true">
24834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24868 <row topline="true">
24869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24903 <row topline="true">
24904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24938 <row topline="true">
24939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24973 <row topline="true">
24974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25008 <row topline="true">
25009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25043 <row topline="true">
25044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25078 <row topline="true" bottomline="true">
25079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25093 \begin_inset LatexCommand \index{packihx (tool)}
25100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25128 \begin_inset LatexCommand \index{Documentation}
25132 included in the distribution
25136 \begin_inset Tabular
25137 <lyxtabular version="3" rows="10" columns="2">
25139 <column alignment="block" valignment="top" leftline="true" width="40col%">
25140 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
25141 <row topline="true" bottomline="true" endhead="true">
25142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25159 Filename / Where to get
25163 <row topline="true">
25164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25169 SDCC Compiler User Guide
25172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25177 You're reading it right now
25189 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
25197 <row topline="true">
25198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25223 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
25231 <row topline="true">
25232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25238 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
25243 \begin_inset LatexCommand \index{Assembler documentation}
25250 \begin_inset LatexCommand \index{aslink}
25255 \begin_inset LatexCommand \index{Linker documentation}
25262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25267 sdcc/as/doc/asxhtm.html
25279 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
25287 <row topline="true">
25288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25293 SDCC regression test
25294 \begin_inset LatexCommand \index{Regression test}
25301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25306 sdcc/doc/test_suite_spec.pdf
25318 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
25326 <row topline="true">
25327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25352 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
25360 <row topline="true">
25361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25366 Notes on debugging with SDCDB
25367 \begin_inset LatexCommand \index{SDCDB (debugger)}
25374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25379 sdcc/debugger/README
25391 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
25399 <row topline="true">
25400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25406 \begin_inset LatexCommand \index{uCsim}
25410 Software simulator for microcontrollers
25413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25448 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
25456 <row topline="true">
25457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25462 Temporary notes on the pic16
25463 \begin_inset LatexCommand \index{PIC16}
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25475 sdcc/src/pic16/NOTES
25487 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
25495 <row topline="true" bottomline="true">
25496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25501 SDCC internal documentation (debugging file format)
25504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25539 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
25556 Related open source tools
25557 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
25562 \begin_inset LatexCommand \index{Related tools}
25570 \begin_inset Tabular
25571 <lyxtabular version="3" rows="14" columns="3">
25573 <column alignment="left" valignment="top" leftline="true" width="0pt">
25574 <column alignment="block" valignment="top" leftline="true" width="30line%">
25575 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25576 <row topline="true" bottomline="true">
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25608 <row topline="true">
25609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25615 \begin_inset LatexCommand \index{gpsim (pic simulator)}
25622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25636 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
25644 <row topline="true">
25645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25651 \begin_inset LatexCommand \index{gputils (pic tools)}
25658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25672 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25680 <row topline="true">
25681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25703 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
25711 <row topline="true">
25712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25725 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
25729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25735 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
25743 <row topline="true">
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25750 \begin_inset LatexCommand \index{indent (source formatting tool)}
25757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25762 Formats C source - Master of the white spaces
25765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25771 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
25779 <row topline="true">
25780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25786 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
25793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25798 Object file conversion, checksumming, ...
25801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25807 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
25815 <row topline="true">
25816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25822 \begin_inset LatexCommand \index{objdump (tool)}
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25834 Object file conversion, ...
25837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25842 Part of binutils (should be there anyway)
25846 <row topline="true">
25847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25860 8051 monitor (hex up-/download, single step, disassemble)
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25869 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
25877 <row topline="true">
25878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25884 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
25891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25896 Source code documentation system
25899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25905 \begin_inset LatexCommand \url{http://www.doxygen.org}
25913 <row topline="true">
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25927 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
25930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25936 \begin_inset LatexCommand \url{http://www.kdevelop.org}
25944 <row topline="true">
25945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25958 8051 monitor (hex up-/download, single step, disassemble)
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25967 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
25975 <row topline="true">
25976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25982 \begin_inset LatexCommand \index{splint (syntax checking tool)}
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25994 Statically checks c sources (see
25995 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
26002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26008 \begin_inset LatexCommand \url{http://www.splint.org}
26016 <row topline="true" bottomline="true">
26017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26023 \begin_inset LatexCommand \index{DDD (debugger)}
26030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26035 Debugger, serves nicely as GUI to SDCDB
26036 \begin_inset LatexCommand \index{SDCDB (debugger)}
26043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26049 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
26066 Related documentation / recommended reading
26070 \begin_inset Tabular
26071 <lyxtabular version="3" rows="7" columns="3">
26073 <column alignment="left" valignment="top" leftline="true" width="0pt">
26074 <column alignment="left" valignment="top" leftline="true" width="0">
26075 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26076 <row topline="true" bottomline="true">
26077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26108 <row topline="true">
26109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26132 \begin_inset LatexCommand \index{C Reference card}
26139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26145 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
26153 <row topline="true">
26154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26168 \begin_inset LatexCommand \index{C FAQ}
26175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26181 \begin_inset LatexCommand \url{http://www.c-faq.com}
26189 <row topline="true">
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26204 \begin_inset Quotes sld
26208 \begin_inset Quotes srd
26214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26222 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
26230 <row topline="true">
26231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26245 \begin_inset Quotes sld
26248 Extensions for Embedded C
26249 \begin_inset Quotes srd
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26263 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
26271 <row topline="true">
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26284 Latest datasheet of target CPU
26287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26296 <row topline="true" bottomline="true">
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26309 Revision history of datasheet
26312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26330 Application notes specifically for SDCC
26333 SDCC makes no claims about the completeness of this list and about up-to-datenes
26334 s or correctness of the application notes
26335 \begin_inset LatexCommand \index{Application notes}
26345 \begin_inset Tabular
26346 <lyxtabular version="3" rows="7" columns="3">
26348 <column alignment="block" valignment="top" leftline="true" width="17col%">
26349 <column alignment="block" valignment="top" leftline="true" width="27col%">
26350 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
26351 <row topline="true" bottomline="true">
26352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26363 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26386 <row topline="true">
26387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26404 Using the SDCC Compiler for the DS80C400
26405 \begin_inset LatexCommand \index{DS80C400}
26412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26420 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
26428 <row topline="true">
26429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26439 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
26446 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
26447 \begin_inset LatexCommand \index{DS89C4x0}
26451 Family of Microcontrollers
26454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26462 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
26470 <row topline="true">
26471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26478 Silicon Laboratories / Cygnal
26481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26488 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
26489 \begin_inset LatexCommand \index{IDE}
26496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26504 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
26512 <row topline="true">
26513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26520 Ramtron / Goal Semiconductor
26523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26530 Interfacing SDCC to Syn and Textpad
26533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26541 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
26549 <row topline="true">
26550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26557 Ramtron / Goal Semiconductor
26560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26567 Installing and Configuring SDCC and Crimson Editor
26570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26578 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
26586 <row topline="true" bottomline="true">
26587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26604 MSC12xx Programming with SDCC
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26615 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
26633 Some questions answered, some pointers given - it might be time to in turn
26641 can you solve your project with the selected microcontroller? Would you
26642 find out early or rather late that your target is too small/slow/whatever?
26643 Can you switch to a slightly better device if it doesn't fit?
26646 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
26647 and/or another programming language be more adequate? Would an operating
26648 system on the target device help?
26651 if you solved the problem, will the marketing department be happy?
26654 if the marketing department is happy, will customers be happy?
26657 if you're the project manager, marketing department and maybe even the customer
26658 in one person, have you tried to see the project from the outside?
26661 is the project done if you think it is done? Or is just that other interface/pro
26662 tocol/feature/configuration/option missing? How about website, manual(s),
26663 internationali(z|s)ation, packaging, labels, 2nd source for components,
26664 electromagnetic compatability/interference, documentation for production,
26665 production test software, update mechanism, patent issues?
26668 is your project adequately positioned in that magic triangle: fame, fortune,
26672 Maybe not all answers to these questions are known and some answers may
26677 , nevertheless knowing these questions may help you to avoid burnout
26683 burnout is bad for electronic devices, programmers and motorcycle tyres
26687 Chances are you didn't want to hear some of them...
26691 \begin_inset LatexCommand \index{Support}
26698 SDCC has grown to be a large project.
26699 The compiler alone (without the preprocessor, assembler and linker) is
26700 well over 150,000 lines of code (blank stripped).
26701 The open source nature of this project is a key to its continued growth
26703 You gain the benefit and support of many active software developers and
26705 Is SDCC perfect? No, that's why we need your help.
26706 The developers take pride in fixing reported bugs.
26707 You can help by reporting the bugs and helping other SDCC users.
26708 There are lots of ways to contribute, and we encourage you to take part
26709 in making SDCC a great software package.
26713 The SDCC project is hosted on the SDCC sourceforge site at
26714 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
26719 You'll find the complete set of mailing lists
26720 \begin_inset LatexCommand \index{Mailing list(s)}
26724 , forums, bug reporting system, patch submission
26725 \begin_inset LatexCommand \index{Patch submission}
26730 \begin_inset LatexCommand \index{download}
26734 area and Subversion code repository
26735 \begin_inset LatexCommand \index{Subversion code repository}
26743 \begin_inset LatexCommand \index{Bug reporting}
26748 \begin_inset LatexCommand \index{Reporting bugs}
26755 The recommended way of reporting bugs is using the infrastructure of the
26757 You can follow the status of bug reports there and have an overview about
26761 Bug reports are automatically forwarded to the developer mailing list and
26762 will be fixed ASAP.
26763 When reporting a bug, it is very useful to include a small test program
26764 (the smaller the better) which reproduces the problem.
26765 If you can isolate the problem by looking at the generated assembly code,
26766 this can be very helpful.
26767 Compiling your program with the -
26778 \begin_inset LatexCommand \index{-\/-dumpall}
26782 option can sometimes be useful in locating optimization problems.
26783 When reporting a bug please make sure you:
26786 Attach the code you are compiling with SDCC.
26790 Specify the exact command you use to run SDCC, or attach your Makefile.
26794 Specify the SDCC version (type "
26800 "), your platform, and operating system.
26804 Provide an exact copy of any error message or incorrect output.
26808 Put something meaningful in the subject of your message.
26811 Please attempt to include these 5 important parts, as applicable, in all
26812 requests for support or when reporting any problems or bugs with SDCC.
26813 Though this will make your message lengthy, it will greatly improve your
26814 chance that SDCC users and developers will be able to help you.
26815 Some SDCC developers are frustrated by bug reports without code provided
26816 that they can use to reproduce and ultimately fix the problem, so please
26817 be sure to provide sample code if you are reporting a bug!
26820 Please have a short check that you are using a recent version of SDCC and
26821 the bug is not yet known.
26822 This is the link for reporting bugs:
26823 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
26828 With SDCC on average having more than 200 downloads
26829 \begin_inset LatexCommand \index{download}
26833 on sourceforge per day
26839 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
26840 between 2002 and 2005.
26841 This does not include other methods of distribution.
26844 there must be some users.
26845 So it's not exactly easy to find a new bug.
26846 If you find one we need it:
26848 reporting bugs is good
26853 Requesting Features
26854 \begin_inset LatexCommand \label{sub:Requesting-Features}
26859 \begin_inset LatexCommand \index{Feature request}
26864 \begin_inset LatexCommand \index{Requesting features}
26871 Like bug reports feature requests are forwarded to the developer mailing
26873 This is the link for requesting features:
26874 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
26884 Like bug reports contributed patches are forwarded to the developer mailing
26886 This is the link for submitting patches
26887 \begin_inset LatexCommand \index{Patch submission}
26892 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
26899 You need to specify some parameters to the
26903 command for the patches to be useful.
26904 If you modified more than one file a patch created f.e.
26909 \begin_inset Quotes sld
26912 diff -Naur unmodified_directory modified_directory >my_changes.patch
26913 \begin_inset Quotes srd
26919 will be fine, otherwise
26923 \begin_inset Quotes sld
26926 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
26927 \begin_inset Quotes srd
26940 These links should take you directly to the
26941 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
26951 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
26952 automated messages (mid 2003)
26956 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
26961 \begin_inset LatexCommand \index{Mailing list(s)}
26965 and forums are archived and searchable so if you are lucky someone already
26966 had a similar problem.
26967 While mails to the lists themselves are delivered promptly their web front
26968 end on sourceforge sometimes shows a severe time lag (up to several weeks),
26969 if you're seriously using SDCC please consider subscribing to the lists.
26975 You can follow the status of the Subversion version
26976 \begin_inset LatexCommand \index{version}
26980 of SDCC by watching the Changelog
26981 \begin_inset LatexCommand \index{Changelog}
26985 in the Subversion repository
26988 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26995 Subversion Source Code Repository
27004 or the filenames of the snapshot versions of SDCC include date and its
27006 \begin_inset LatexCommand \index{Subversion code repository}
27011 Subversion allows to download the source of recent or previous versions
27013 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
27017 (by number or by date).
27018 An on-line source code browser and detailled instructions are also available
27020 SDCC versions starting from 1999 up to now are available (currently the
27021 versions prior to the conversion from cvs
27022 \begin_inset LatexCommand \index{cvs|see{Subversion}}
27026 to Subversion (April 2006) are either by accessible by Subversion or by
27031 \begin_inset LatexCommand \index{Release policy}
27038 Historically there often were long delays between official releases and
27039 the sourceforge download area tends to get not updated at all.
27040 Excuses in the past might have referred to problems with live range analysis,
27041 but as this was fixed a while ago, the current problem is that another
27042 excuse has to be found.
27043 Kidding aside, we have to get better there! On the other hand there are
27044 daily snapshots available at
27045 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
27049 , and you can always build the very last version (hopefully with many bugs
27050 fixed, and features added) from the source code available at
27051 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
27057 \begin_inset LatexCommand \index{wiki}
27062 \begin_inset LatexCommand \index{Release wiki}
27067 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
27071 also holds some information about past and future releases.
27075 \begin_inset LatexCommand \index{Examples}
27082 You'll find some small examples in the directory
27084 sdcc/device/examples/.
27087 More examples and libraries are available at
27089 The SDCC Open Knowledge Resource
27090 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
27097 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
27104 I did insert a reference to Paul's web site here although it seems rather
27105 dedicated to a specific 8032 board (I think it's okay because it f.e.
27106 shows LCD/Harddisc interface and has a free 8051 monitor.
27107 Independent 8032 board vendors face hard competition of heavily subsidized
27108 development boards anyway).
27111 Maybe we should include some links to real world applications.
27112 Preferably pointer to pointers (one for each architecture) so this stays
27117 \begin_inset LatexCommand \label{sec:Quality-control}
27122 \begin_inset LatexCommand \index{Quality control}
27129 The compiler is passed through nightly compile and build checks.
27135 \begin_inset LatexCommand \index{Regression test}
27139 check that SDCC itself compiles flawlessly on several host platforms (i386,
27140 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
27141 the quality of the code generated by SDCC by running the code for several
27142 target platforms through simulators.
27143 The regression test suite comprises more than 100 files which expand to
27144 more than 500 test cases which include more than 4500 tests.
27145 The results of these tests are published daily on SDCC's snapshot page
27146 (click on the red or green symbols on the right side of
27147 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
27154 There is a separate document
27157 \begin_inset LatexCommand \index{Test suite}
27164 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
27168 about the regression test suite.
27171 You'll find the test code in the directory
27173 sdcc/support/regression
27176 You can run these tests manually by running
27180 in this directory (or f.e.
27185 \begin_inset Quotes sld
27189 \begin_inset Quotes srd
27195 if you don't want to run the complete tests).
27196 The test code might also be interesting if you want to look for examples
27197 \begin_inset LatexCommand \index{Examples}
27201 checking corner cases of SDCC or if you plan to submit patches
27202 \begin_inset LatexCommand \index{Patch submission}
27209 The 14bit pic port uses a different set of regression tests
27210 \begin_inset LatexCommand \index{Regression test (PIC14)}
27214 , you'll find them in the directory
27216 sdcc/src/regression
27221 Use of SDCC in Education
27234 the phrase "use in education" might evoke the association "
27238 fit for use in education".
27239 This connotation is not intended but nevertheless risked as the licensing
27240 of SDCC makes it difficult to offer educational discounts
27244 If your rationales are to:
27247 give students a chance to understand the
27251 steps of code generation
27254 have a curriculum that can be extended for years.
27255 Then you could use an fpga board as target and your curriculum will seamlessly
27256 extend from logic synthesis (
27257 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
27262 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
27266 ), over assembly programming, to C to FPGA compilers (
27267 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
27274 be able to insert excursions about skills like using a revision control
27275 system, submitting/applying patches, using a type-setting (as opposed to
27276 word-processing) engine LyX/LaTeX, using
27277 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
27282 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
27286 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
27287 Source Software, CPU simulation, compiler regression tests
27288 \begin_inset LatexCommand \index{Regression test}
27295 And if there should be a shortage of ideas then you can always point students
27296 to the ever-growing feature request list
27297 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
27304 not tie students to a specific host platform and instead allow them to use
27309 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
27311 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
27318 not encourage students to use illegal copies of educational software
27321 be immune to licensing/availability/price changes of the chosen tool chain
27324 be able to change to a new target platform without having to adopt a new
27328 have complete control over and insight into the tool chain
27331 make your students aware about the pros and cons of open source software
27335 give back to the public as you are probably at least partially publically
27339 give students a chance to publically prove their skills and to possibly
27340 see a world wide impact
27343 then SDCC is probably among the first choices.
27344 Well, probably SDCC might be the only choice.
27347 SDCC Technical Data
27351 \begin_inset LatexCommand \index{Optimizations}
27358 SDCC performs a host of standard optimizations in addition to some MCU specific
27363 Sub-expression Elimination
27364 \begin_inset LatexCommand \index{Subexpression elimination}
27371 The compiler does local and
27397 will be translated to
27409 Some subexpressions are not as obvious as the above example, e.g.:
27419 In this case the address arithmetic a->b[i] will be computed only once;
27420 the equivalent code in C would be.
27432 The compiler will try to keep these temporary variables in registers.
27435 Dead-Code Elimination
27436 \begin_inset LatexCommand \index{Dead-code elimination}
27457 i = 1; \SpecialChar ~
27466 global = 1;\SpecialChar ~
27479 global = 3;\SpecialChar ~
27504 \begin_inset LatexCommand \index{Copy propagation}
27560 Note: the dead stores created by this copy propagation will be eliminated
27561 by dead-code elimination.
27565 \begin_inset LatexCommand \index{Loop optimization}
27570 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
27577 Two types of loop optimizations are done by SDCC
27585 of loop induction variables.
27586 In addition to the strength reduction the optimizer marks the induction
27587 variables and the register allocator tries to keep the induction variables
27588 in registers for the duration of the loop.
27589 Because of this preference of the register allocator
27590 \begin_inset LatexCommand \index{Register allocation}
27594 , loop induction optimization causes an increase in register pressure, which
27595 may cause unwanted spilling of other temporary variables into the stack
27596 \begin_inset LatexCommand \index{stack}
27601 The compiler will generate a warning message when it is forced to allocate
27602 extra space either on the stack or data space.
27603 If this extra space allocation is undesirable then induction optimization
27604 can be eliminated either for the entire source file (with -
27614 -noinduction option) or for a given function only using #pragma\SpecialChar ~
27616 \begin_inset LatexCommand \index{\#pragma noinduction}
27629 for (i = 0 ; i < 100 ; i ++)
27645 for (i = 0; i < 100; i++)
27654 As mentioned previously some loop invariants are not as apparent, all static
27655 address computations are also moved out of the loop.
27660 \begin_inset LatexCommand \index{Strength reduction}
27664 , this optimization substitutes an expression by a cheaper expression:
27669 for (i=0;i < 100; i++)
27687 for (i=0;i< 100;i++) {
27693 ar[itemp1] = itemp2;
27710 The more expensive multiplication
27711 \begin_inset LatexCommand \index{Multiplication}
27715 is changed to a less expensive addition.
27719 \begin_inset LatexCommand \index{Loop reversing}
27726 This optimization is done to reduce the overhead of checking loop boundaries
27727 for every iteration.
27728 Some simple loops can be reversed and implemented using a
27729 \begin_inset Quotes eld
27732 decrement and jump if not zero
27733 \begin_inset Quotes erd
27737 SDCC checks for the following criterion to determine if a loop is reversible
27738 (note: more sophisticated compilers use data-dependency analysis to make
27739 this determination, SDCC uses a more simple minded analysis).
27742 The 'for' loop is of the form
27748 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
27758 The <for body> does not contain
27759 \begin_inset Quotes eld
27763 \begin_inset Quotes erd
27767 \begin_inset Quotes erd
27773 All goto's are contained within the loop.
27776 No function calls within the loop.
27779 The loop control variable <sym> is not assigned any value within the loop
27782 The loop control variable does NOT participate in any arithmetic operation
27786 There are NO switch statements in the loop.
27789 Algebraic Simplifications
27792 SDCC does numerous algebraic simplifications, the following is a small sub-set
27793 of these optimizations.
27798 i = j + 0;\SpecialChar ~
27802 /* changed to: */\SpecialChar ~
27808 i /= 2;\SpecialChar ~
27815 /* changed to: */\SpecialChar ~
27821 i = j - j;\SpecialChar ~
27825 /* changed to: */\SpecialChar ~
27831 i = j / 1;\SpecialChar ~
27835 /* changed to: */\SpecialChar ~
27842 Note the subexpressions
27843 \begin_inset LatexCommand \index{Subexpression}
27847 given above are generally introduced by macro expansions or as a result
27848 of copy/constant propagation.
27851 'switch' Statements
27852 \begin_inset LatexCommand \label{sub:'switch'-Statements}
27857 \begin_inset LatexCommand \index{switch statement}
27864 SDCC can optimize switch statements to jump tables
27865 \begin_inset LatexCommand \index{jump tables}
27870 It makes the decision based on an estimate of the generated code size.
27871 SDCC is quite liberal in the requirements for jump table generation:
27874 The labels need not be in order, and the starting number need not be one
27875 or zero, the case labels are in numerical sequence or not too many case
27876 labels are missing.
27882 switch(i) {\SpecialChar ~
27913 case 4: ...\SpecialChar ~
27945 case 5: ...\SpecialChar ~
27977 case 3: ...\SpecialChar ~
28008 case 6: ...\SpecialChar ~
28040 case 7: ...\SpecialChar ~
28072 case 8: ...\SpecialChar ~
28104 case 9: ...\SpecialChar ~
28136 case 10: ...\SpecialChar ~
28167 case 11: ...\SpecialChar ~
28234 Both the above switch statements will be implemented using a jump-table.
28235 The example to the right side is slightly more efficient as the check for
28236 the lower boundary of the jump-table is not needed.
28240 The number of case labels is not larger than supported by the target architectur
28244 If the case labels are not in numerical sequence ('gaps' between cases)
28245 SDCC checks whether a jump table with additionally inserted dummy cases
28246 is still attractive.
28250 If the starting number is not zero and a check for the lower boundary of
28251 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
28256 Switch statements which have large gaps in the numeric sequence or those
28257 that have too many case labels can be split into more than one switch statement
28258 for efficient code generation, e.g.:
28338 If the above switch statement is broken down into two switch statements
28428 then both the switch statements will be implemented using jump-tables whereas
28429 the unmodified switch statement will not be.
28432 There might be reasons which SDCC cannot know about to either favour or
28433 not favour jump tables.
28434 If the target system has to be as quick for the last switch case as for
28435 the first (pro jump table), or if the switch argument is known to be zero
28436 in the majority of the cases (contra jump table).
28439 The pragma nojtbound
28440 \begin_inset LatexCommand \index{\#pragma nojtbound}
28444 can be used to turn off checking the
28457 It has no effect if a default label is supplied.
28458 Use of this pragma is dangerous: if the switch
28459 \begin_inset LatexCommand \index{switch statement}
28463 argument is not matched by a case statement the processor will happily
28467 Bit-shifting Operations
28468 \begin_inset LatexCommand \index{Bit shifting}
28475 Bit shifting is one of the most frequently used operation in embedded programmin
28477 SDCC tries to implement bit-shift operations in the most efficient way
28493 generates the following code:
28510 In general SDCC will never setup a loop if the shift count is known.
28553 \begin_inset LatexCommand \index{Bit rotation}
28560 A special case of the bit-shift operation is bit rotation
28561 \begin_inset LatexCommand \index{rotating bits}
28565 , SDCC recognizes the following expression to be a left bit-rotation:
28575 char i;\SpecialChar ~
28586 /* unsigned is needed for rotation */
28591 i = ((i << 1) | (i >> 7));
28600 will generate the following code:
28619 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
28620 ns of this case will also be recognized as bit-rotation, i.e.:
28625 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
28628 Nibble and Byte Swapping
28631 Other special cases of the bit-shift operations are nibble or byte swapping
28632 \begin_inset LatexCommand \index{swapping nibbles/bytes}
28636 , SDCC recognizes the following expressions:
28659 i = ((i << 4) | (i >> 4));
28665 j = ((j << 8) | (j >> 8));
28668 and generates a swap instruction for the nibble swapping
28669 \begin_inset LatexCommand \index{Nibble swapping}
28673 or move instructions for the byte swapping
28674 \begin_inset LatexCommand \index{Byte swapping}
28680 \begin_inset Quotes sld
28684 \begin_inset Quotes srd
28687 example can be used to convert from little to big-endian or vice versa.
28688 If you want to change the endianness of a
28692 integer you have to cast to
28699 Note that SDCC stores numbers in little-endian
28705 Usually 8-bit processors don't care much about endianness.
28706 This is not the case for the standard 8051 which only has an instruction
28712 \begin_inset LatexCommand \index{DPTR}
28720 so little-endian is the more efficient byte order.
28724 \begin_inset LatexCommand \index{little-endian}
28729 \begin_inset LatexCommand \index{Endianness}
28734 lowest order first).
28738 \begin_inset LatexCommand \index{Highest Order Bit}
28743 \begin_inset LatexCommand \index{Any Order Bit}
28750 It is frequently required to obtain the highest order bit of an integral
28751 type (long, int, short or char types).
28752 Also obtaining any other order bit is not uncommon.
28753 SDCC recognizes the following expressions to yield the highest order bit
28754 and generates optimized code for it, e.g.:
28767 unsigned char hob1, aob1;
28771 bit hob2, hob3, aob2, aob3;
28780 hob1 = (gint >> 15) & 1;
28784 hob2 = (gint >> 15) & 1;
28788 hob3 = gint & 0x8000;
28792 aob1 = (gint >> 9) & 1;
28796 aob2 = (gint >> 8) & 1;
28800 aob3 = gint & 0x0800;
28810 will generate the following code:
28843 000A E5*01\SpecialChar ~
28870 000C 23\SpecialChar ~
28901 000D 54 01\SpecialChar ~
28928 000F F5*02\SpecialChar ~
28983 0011 E5*01\SpecialChar ~
29010 0013 33\SpecialChar ~
29040 0014 92*00\SpecialChar ~
29095 0016 E5*01\SpecialChar ~
29122 0018 33\SpecialChar ~
29152 0019 92*01\SpecialChar ~
29207 001B E5*01\SpecialChar ~
29234 001D 03\SpecialChar ~
29265 001E 54 01\SpecialChar ~
29292 0020 F5*03\SpecialChar ~
29347 0022 E5*01\SpecialChar ~
29374 0024 13\SpecialChar ~
29404 0025 92*02\SpecialChar ~
29459 0027 E5*01\SpecialChar ~
29486 0029 A2 E3\SpecialChar ~
29513 002B 92*03\SpecialChar ~
29541 Other variations of these cases however will
29546 They are standard C expressions, so I heartily recommend these be the only
29547 way to get the highest order bit, (it is portable).
29548 Of course it will be recognized even if it is embedded in other expressions,
29554 xyz = gint + ((gint >> 15) & 1);
29557 will still be recognized.
29561 \begin_inset LatexCommand \index{Higher Order Byte}
29565 / Higher Order Word
29566 \begin_inset LatexCommand \index{Higher Order Word}
29573 It is also frequently required to obtain a higher order byte or word of
29574 a larger integral type (long, int or short types).
29575 SDCC recognizes the following expressions to yield the higher order byte
29576 or word and generates optimized code for it, e.g.:
29583 unsigned long int glong;
29591 unsigned char hob1, hob2;
29595 unsigned int how1, how2;
29604 hob1 = (gint >> 8) & 0xFF;
29608 hob2 = glong >> 24;
29612 how1 = (glong >> 16) & 0xFFFF;
29626 will generate the following code:
29659 0037 85*01*06\SpecialChar ~
29681 _foo_hob1_1_1,(_gint + 1)
29711 003A 85*05*07\SpecialChar ~
29733 _foo_hob2_1_1,(_glong + 3)
29763 003D 85*04*08\SpecialChar ~
29785 _foo_how1_1_1,(_glong + 2)
29787 0040 85*05*09\SpecialChar ~
29809 (_foo_how1_1_1 + 1),(_glong + 3)
29811 0043 85*03*0A\SpecialChar ~
29833 _foo_how2_1_1,(_glong + 1)
29835 0046 85*04*0B\SpecialChar ~
29857 (_foo_how2_1_1 + 1),(_glong + 2)
29860 Again, variations of these cases may
29865 They are standard C expressions, so I heartily recommend these be the only
29866 way to get the higher order byte/word, (it is portable).
29867 Of course it will be recognized even if it is embedded in other expressions,
29873 xyz = gint + ((gint >> 8) & 0xFF);
29876 will still be recognized.
29880 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
29885 \begin_inset LatexCommand \index{Peephole optimizer}
29892 The compiler uses a rule based, pattern matching and re-writing mechanism
29893 for peep-hole optimization.
29898 a peep-hole optimizer by Christopher W.
29899 Fraser (cwfraser\SpecialChar ~
29902 A default set of rules are compiled into the compiler, additional rules
29903 may be added with the
29916 \begin_inset LatexCommand \index{-\/-peep-file}
29923 The rule language is best illustrated with examples.
29947 The above rule will change the following assembly
29948 \begin_inset LatexCommand \index{Assembler routines}
29970 Note: All occurrences of a
29974 (pattern variable) must denote the same string.
29975 With the above rule, the assembly sequence:
29985 will remain unmodified.
29989 Other special case optimizations may be added by the user (via
30005 some variants of the 8051 MCU
30006 \begin_inset LatexCommand \index{MCS51 variants}
30019 The following two rules will change all
30038 replace { lcall %1 } by { acall %1 }
30040 replace { ljmp %1 } by { ajmp %1 }
30045 inline-assembler code
30047 is also passed through the peep hole optimizer, thus the peephole optimizer
30048 can also be used as an assembly level macro expander.
30049 The rules themselves are MCU dependent whereas the rule language infra-structur
30050 e is MCU independent.
30051 Peephole optimization rules for other MCU can be easily programmed using
30056 The syntax for a rule is as follows:
30061 rule := replace [ restart ] '{' <assembly sequence> '
30099 <assembly sequence> '
30117 '}' [if <functionName> ] '
30122 <assembly sequence> := assembly instruction (each instruction including
30123 labels must be on a separate line).
30127 The optimizer will apply to the rules one by one from the top in the sequence
30128 of their appearance, it will terminate when all rules are exhausted.
30129 If the 'restart' option is specified, then the optimizer will start matching
30130 the rules again from the top, this option for a rule is expensive (performance)
30131 , it is intended to be used in situations where a transformation will trigger
30132 the same rule again.
30133 An example of this (not a good one, it has side effects) is the following
30156 Note that the replace pattern cannot be a blank, but can be a comment line.
30157 Without the 'restart' option only the innermost 'pop' 'push' pair would
30158 be eliminated, i.e.:
30188 the restart option the rule will be applied again to the resulting code
30189 and then all the pop-push pairs will be eliminated to yield:
30199 A conditional function can be attached to a rule.
30200 Attaching rules are somewhat more involved, let me illustrate this with
30227 The optimizer does a look-up of a function name table defined in function
30232 in the source file SDCCpeeph.c, with the name
30237 If it finds a corresponding entry the function is called.
30238 Note there can be no parameters specified for these functions, in this
30243 is crucial, since the function
30247 expects to find the label in that particular variable (the hash table containin
30248 g the variable bindings is passed as a parameter).
30249 If you want to code more such functions, take a close look at the function
30250 labelInRange and the calling mechanism in source file SDCCpeeph.c.
30251 Currently implemented are
30253 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
30254 24bitMode, portIsDS390, 24bitModeAndPortDS390
30263 I know this whole thing is a little kludgey, but maybe some day we will
30264 have some better means.
30265 If you are looking at this file, you will see the default rules that are
30266 compiled into the compiler, you can add your own rules in the default set
30267 there if you get tired of specifying the -
30281 \begin_inset LatexCommand \index{ANSI-compliance}
30286 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
30293 The latest publically available version of the standard
30295 ISO/IEC 9899 - Programming languages - C
30297 should be available at:
30298 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30307 Deviations from the compliance:
30310 functions are not reentrant
30311 \begin_inset LatexCommand \index{reentrant}
30315 unless explicitly declared as such or the
30328 \begin_inset LatexCommand \index{-\/-stack-auto}
30334 command line option is specified.
30338 \begin_inset LatexCommand \index{struct}
30343 \begin_inset LatexCommand \index{union}
30347 cannot be assigned values directly, cannot be passed as function parameters
30348 or assigned to each other and cannot be a return value
30349 \begin_inset LatexCommand \index{return value}
30353 from a function, e.g.:
30379 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
30398 s parms) /* invalid in SDCC although allowed in ANSI */
30419 return rets; /* is invalid in SDCC although allowed in ANSI */
30425 initialization of structure arrays must be fully braced.
30431 struct s { char x } a[] = {1, 2};\SpecialChar ~
30436 /* invalid in SDCC */
30438 struct s { char x } a[] = {{1}, {2}}; /* OK */
30443 \begin_inset LatexCommand \index{long long (not supported)}
30448 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
30456 \begin_inset LatexCommand \index{double (not supported)}
30460 ' precision floating point
30461 \begin_inset LatexCommand \index{Floating point support}
30469 \begin_inset LatexCommand \index{K\&R style}
30473 function declarations are NOT allowed.
30479 foo(i,j) /* this old style of function declarations */
30481 int i,j; /* are valid in ANSI but not valid in SDCC */
30496 Most enhancements in C99 are not supported, f.e.:
30504 \begin_inset LatexCommand \index{inline (not supported)}
30510 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
30516 can be used as a work around */
30524 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
30528 Certain words that are valid identifiers in the standard may be reserved
30529 words in SDCC unless the
30542 \begin_inset LatexCommand \index{-\/-std-c89}
30557 \begin_inset LatexCommand \index{-\/-std-c99}
30563 command line options are used.
30564 These may include (depending on the selected processor): 'at', 'banked',
30565 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
30566 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
30567 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
30569 Compliant equivalents of these keywords are always available in a form
30570 that begin with two underscores
30571 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
30576 '__data' instead of 'data'.
30579 Cyclomatic Complexity
30580 \begin_inset LatexCommand \index{Cyclomatic complexity}
30587 Cyclomatic complexity of a function is defined as the number of independent
30588 paths the program can take during execution of the function.
30589 This is an important number since it defines the number test cases you
30590 have to generate to validate the function.
30591 The accepted industry standard for complexity number is 10, if the cyclomatic
30592 complexity reported by SDCC exceeds 10 you should think about simplification
30593 of the function logic.
30594 Note that the complexity level is not related to the number of lines of
30595 code in a function.
30596 Large functions can have low complexity, and small functions can have large
30602 SDCC uses the following formula to compute the complexity:
30607 complexity = (number of edges in control flow graph) - (number of nodes
30608 in control flow graph) + 2;
30612 Having said that the industry standard is 10, you should be aware that in
30613 some cases it be may unavoidable to have a complexity level of less than
30615 For example if you have switch statement with more than 10 case labels,
30616 each case label adds one to the complexity level.
30617 The complexity level is by no means an absolute measure of the algorithmic
30618 complexity of the function, it does however provide a good starting point
30619 for which functions you might look at for further optimization.
30622 Retargetting for other Processors
30625 The issues for retargetting the compiler are far too numerous to be covered
30627 What follows is a brief description of each of the seven phases of the
30628 compiler and its MCU dependency.
30631 Parsing the source and building the annotated parse tree.
30632 This phase is largely MCU independent (except for the language extensions).
30633 Syntax & semantic checks are also done in this phase, along with some initial
30634 optimizations like back patching labels and the pattern matching optimizations
30635 like bit-rotation etc.
30638 The second phase involves generating an intermediate code which can be easy
30639 manipulated during the later phases.
30640 This phase is entirely MCU independent.
30641 The intermediate code generation assumes the target machine has unlimited
30642 number of registers, and designates them with the name iTemp.
30643 The compiler can be made to dump a human readable form of the code generated
30657 This phase does the bulk of the standard optimizations and is also MCU independe
30659 This phase can be broken down into several sub-phases:
30663 Break down intermediate code (iCode) into basic blocks.
30665 Do control flow & data flow analysis on the basic blocks.
30667 Do local common subexpression elimination, then global subexpression elimination
30669 Dead code elimination
30673 If loop optimizations caused any changes then do 'global subexpression eliminati
30674 on' and 'dead code elimination' again.
30677 This phase determines the live-ranges; by live range I mean those iTemp
30678 variables defined by the compiler that still survive after all the optimization
30680 Live range analysis
30681 \begin_inset LatexCommand \index{Live range analysis}
30685 is essential for register allocation, since these computation determines
30686 which of these iTemps will be assigned to registers, and for how long.
30689 Phase five is register allocation.
30690 There are two parts to this process.
30694 The first part I call 'register packing' (for lack of a better term).
30695 In this case several MCU specific expression folding is done to reduce
30700 The second part is more MCU independent and deals with allocating registers
30701 to the remaining live ranges.
30702 A lot of MCU specific code does creep into this phase because of the limited
30703 number of index registers available in the 8051.
30706 The Code generation phase is (unhappily), entirely MCU dependent and very
30707 little (if any at all) of this code can be reused for other MCU.
30708 However the scheme for allocating a homogenized assembler operand for each
30709 iCode operand may be reused.
30712 As mentioned in the optimization section the peep-hole optimizer is rule
30713 based system, which can reprogrammed for other MCUs.
30716 More information is available in a wiki
30717 \begin_inset LatexCommand \index{wiki}
30722 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
30726 ) and in the thread
30727 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
30735 \begin_inset LatexCommand \index{Compiler internals}
30742 The anatomy of the compiler
30743 \begin_inset LatexCommand \label{sub:The-anatomy-of}
30752 This is an excerpt from an article published in Circuit Cellar Magazine
30758 It's a little outdated (the compiler is much more efficient now and user/develo
30759 per friendly), but pretty well exposes the guts of it all.
30765 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
30766 It is fairly easy to retarget for other 8-bit MCU.
30767 Here we take a look at some of the internals of the compiler.
30772 \begin_inset LatexCommand \index{Parsing}
30779 Parsing the input source file and creating an AST (Annotated Syntax Tree
30780 \begin_inset LatexCommand \index{Annotated syntax tree}
30785 This phase also involves propagating types (annotating each node of the
30786 parse tree with type information) and semantic analysis.
30787 There are some MCU specific parsing rules.
30788 For example the storage classes, the extended storage classes are MCU specific
30789 while there may be a xdata storage class for 8051 there is no such storage
30790 class for z80 or Atmel AVR.
30791 SDCC allows MCU specific storage class extensions, i.e.
30792 xdata will be treated as a storage class specifier when parsing 8051 C
30793 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
30798 \begin_inset LatexCommand \index{iCode}
30805 Intermediate code generation.
30806 In this phase the AST is broken down into three-operand form (iCode).
30807 These three operand forms are represented as doubly linked lists.
30808 ICode is the term given to the intermediate form generated by the compiler.
30809 ICode example section shows some examples of iCode generated for some simple
30810 C source functions.
30814 \begin_inset LatexCommand \index{Optimizations}
30821 Bulk of the target independent optimizations is performed in this phase.
30822 The optimizations include constant propagation, common sub-expression eliminati
30823 on, loop invariant code movement, strength reduction of loop induction variables
30824 and dead-code elimination.
30827 Live range analysis
30828 \begin_inset LatexCommand \index{Live range analysis}
30835 During intermediate code generation phase, the compiler assumes the target
30836 machine has infinite number of registers and generates a lot of temporary
30838 The live range computation determines the lifetime of each of these compiler-ge
30839 nerated temporaries.
30840 A picture speaks a thousand words.
30841 ICode example sections show the live range annotations for each of the
30843 It is important to note here, each iCode is assigned a number in the order
30844 of its execution in the function.
30845 The live ranges are computed in terms of these numbers.
30846 The from number is the number of the iCode which first defines the operand
30847 and the to number signifies the iCode which uses this operand last.
30850 Register Allocation
30851 \begin_inset LatexCommand \index{Register allocation}
30858 The register allocation determines the type and number of registers needed
30860 In most MCUs only a few registers can be used for indirect addressing.
30861 In case of 8051 for example the registers R0 & R1 can be used to indirectly
30862 address the internal ram and DPTR to indirectly address the external ram.
30863 The compiler will try to allocate the appropriate register to pointer variables
30865 ICode example section shows the operands annotated with the registers assigned
30867 The compiler will try to keep operands in registers as much as possible;
30868 there are several schemes the compiler uses to do achieve this.
30869 When the compiler runs out of registers the compiler will check to see
30870 if there are any live operands which is not used or defined in the current
30871 basic block being processed, if there are any found then it will push that
30872 operand and use the registers in this block, the operand will then be popped
30873 at the end of the basic block.
30877 There are other MCU specific considerations in this phase.
30878 Some MCUs have an accumulator; very short-lived operands could be assigned
30879 to the accumulator instead of a general-purpose register.
30885 Figure II gives a table of iCode
30886 \begin_inset LatexCommand \index{iCode}
30890 operations supported by the compiler.
30891 The code generation involves translating these operations into corresponding
30892 assembly code for the processor.
30893 This sounds overly simple but that is the essence of code generation.
30894 Some of the iCode operations are generated on a MCU specific manner for
30895 example, the z80 port does not use registers to pass parameters so the
30896 SEND and RECV iCode operations will not be generated, and it also does
30897 not support JUMPTABLES.
30906 \begin_inset Tabular
30907 <lyxtabular version="3" rows="39" columns="4">
30908 <features islongtable="true" headBottomDL="true">
30909 <column alignment="block" valignment="top" leftline="true" width="13col%">
30910 <column alignment="left" valignment="top" leftline="true" width="13col%">
30911 <column alignment="block" valignment="top" leftline="true" width="22col%">
30912 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
30913 <row topline="true" bottomline="true" endhead="true">
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30924 \begin_inset LatexCommand \index{iCode}
30931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30962 <row topline="true">
30963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30980 IC_LEFT() IC_RESULT()
30983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31000 IC_RESULT = ! IC_LEFT;
31004 <row topline="true">
31005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31022 IC_LEFT() IC_RESULT()
31025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31032 Bitwise complement of
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31042 IC_RESULT = ~IC_LEFT;
31046 <row topline="true">
31047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31064 IC_LEFT() IC_RESULT()
31067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31074 Rotate right with carry
31077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31084 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
31088 <row topline="true">
31089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31106 IC_LEFT() IC_RESULT()
31109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31116 Rotate left with carry
31119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31126 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
31130 <row topline="true">
31131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31148 IC_LEFT() IC_RESULT()
31151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31158 Get the highest order bit of IC_LEFT
31161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31168 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
31172 <row topline="true">
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31190 IC_LEFT() IC_RESULT()
31193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31210 IC_RESULT = - IC_LEFT;
31214 <row topline="true">
31215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31242 Push the operand into stack
31245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31256 <row topline="true">
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31284 Pop the operand from the stack
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31298 <row topline="true">
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31316 IC_LEFT() IC_RESULT()
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31326 Call the function represented by IC_LEFT
31329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31336 IC_RESULT = IC_LEFT();
31340 <row topline="true">
31341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31358 IC_LEFT() IC_RESULT()
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31368 Call via function pointer
31371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31378 IC_RESULT = (*IC_LEFT)();
31382 <row topline="true">
31383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31410 Return the value in operand IC_LEFT
31413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31424 <row topline="true">
31425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31466 <row topline="true">
31467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31508 <row topline="true">
31509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31526 IC_LEFT() IC_RIGHT() IC_RESULT()
31529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31546 IC_RESULT = IC_LEFT + IC_RIGHT
31550 <row topline="true">
31551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31568 IC_LEFT() IC_RIGHT() IC_RESULT()
31571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31588 IC_RESULT = IC_LEFT - IC_RIGHT
31592 <row topline="true">
31593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31610 IC_LEFT() IC_RIGHT() IC_RESULT()
31613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31630 IC_RESULT = IC_LEFT * IC_RIGHT;
31634 <row topline="true">
31635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31652 IC_LEFT() IC_RIGHT() IC_RESULT()
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31672 IC_RESULT = IC_LEFT / IC_RIGHT;
31676 <row topline="true">
31677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31694 IC_LEFT() IC_RIGHT() IC_RESULT()
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31714 IC_RESULT = IC_LEFT % IC_RIGHT;
31718 <row topline="true">
31719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31736 IC_LEFT() IC_RIGHT() IC_RESULT()
31739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31756 IC_RESULT = IC_LEFT < IC_RIGHT;
31760 <row topline="true">
31761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31778 IC_LEFT() IC_RIGHT() IC_RESULT()
31781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31798 IC_RESULT = IC_LEFT > IC_RIGHT;
31802 <row topline="true">
31803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31820 IC_LEFT() IC_RIGHT() IC_RESULT()
31823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31840 IC_RESULT = IC_LEFT == IC_RIGHT;
31844 <row topline="true">
31845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31862 IC_LEFT() IC_RIGHT() IC_RESULT()
31865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31872 Logical and operation
31875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31882 IC_RESULT = IC_LEFT && IC_RIGHT;
31886 <row topline="true">
31887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31904 IC_LEFT() IC_RIGHT() IC_RESULT()
31907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31914 Logical or operation
31917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31924 IC_RESULT = IC_LEFT || IC_RIGHT;
31928 <row topline="true">
31929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31946 IC_LEFT() IC_RIGHT() IC_RESULT()
31949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31966 IC_RESULT = IC_LEFT ^ IC_RIGHT;
31970 <row topline="true">
31971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31988 IC_LEFT() IC_RIGHT() IC_RESULT()
31991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32008 IC_RESULT = IC_LEFT | IC_RIGHT;
32012 <row topline="true">
32013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32030 IC_LEFT() IC_RIGHT() IC_RESULT()
32033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32050 IC_RESULT = IC_LEFT & IC_RIGHT;
32054 <row topline="true">
32055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32072 IC_LEFT() IC_RIGHT() IC_RESULT()
32075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32092 IC_RESULT = IC_LEFT << IC_RIGHT
32096 <row topline="true">
32097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32114 IC_LEFT() IC_RIGHT() IC_RESULT()
32117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32134 IC_RESULT = IC_LEFT >> IC_RIGHT
32138 <row topline="true">
32139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32158 IC_LEFT() IC_RESULT()
32161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32178 IC_RESULT = (*IC_LEFT);
32182 <row topline="true">
32183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32200 IC_RIGHT() IC_RESULT()
32203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32220 (*IC_RESULT) = IC_RIGHT;
32224 <row topline="true">
32225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32242 IC_RIGHT() IC_RESULT()
32245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32262 IC_RESULT = IC_RIGHT;
32266 <row topline="true">
32267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32284 IC_COND IC_TRUE IC_LABEL
32287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32295 If true label is present then jump to true label if condition is true else
32296 jump to false label if condition is false
32299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32306 if (IC_COND) goto IC_TRUE;
32312 If (!IC_COND) goto IC_FALSE;
32316 <row topline="true">
32317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32334 IC_LEFT() IC_RESULT()
32337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32354 IC_RESULT = &IC_LEFT();
32358 <row topline="true">
32359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32376 IC_JTCOND IC_JTLABELS
32379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32386 Jump to list of labels depending on the value of JTCOND
32389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32400 <row topline="true">
32401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32418 IC_RIGHT() IC_LEFT() IC_RESULT()
32421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32438 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
32442 <row topline="true">
32443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32470 This is used for passing parameters in registers;
32472 move IC_LEFT to the next available parameter register.
32475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32486 <row topline="true">
32487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32514 This is used for receiving parameters passed in registers;
32516 Move the values in the next parameter register to IC_RESULT
32519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32530 <row topline="true" bottomline="true">
32531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32539 (some more have been added)
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32582 In the original article Figure II was announced to be downloadable on
32587 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
32591 \begin_inset LatexCommand \index{iCode}
32598 This section shows some details of iCode.
32599 The example C code does not do anything useful; it is used as an example
32600 to illustrate the intermediate code generated by the compiler.
32612 /* This function does nothing useful.
32619 for the purpose of explaining iCode */
32622 short function (data int *x)
32630 short i=10; \SpecialChar ~
32632 /* dead initialization eliminated */
32637 short sum=10; /* dead initialization eliminated */
32650 while (*x) *x++ = *p++;
32664 /* compiler detects i,j to be induction variables */
32668 for (i = 0, j = 10 ; i < 10 ; i++, j
32694 mul += i * 3; \SpecialChar ~
32696 /* this multiplication remains */
32702 gint += j * 3;\SpecialChar ~
32704 /* this multiplication changed to addition */
32718 In addition to the operands each iCode contains information about the filename
32719 and line it corresponds to in the source file.
32720 The first field in the listing should be interpreted as follows:
32725 Filename(linenumber: iCode Execution sequence number : ICode hash table
32726 key : loop depth of the iCode).
32731 Then follows the human readable form of the ICode operation.
32732 Each operand of this triplet form can be of three basic types a) compiler
32733 generated temporary b) user defined variable c) a constant value.
32734 Note that local variables and parameters are replaced by compiler generated
32737 \begin_inset LatexCommand \index{Live range analysis}
32741 are computed only for temporaries (i.e.
32742 live ranges are not computed for global variables).
32744 \begin_inset LatexCommand \index{Register allocation}
32748 are allocated for temporaries only.
32749 Operands are formatted in the following manner:
32754 Operand Name [lr live-from : live-to ] { type information } [ registers
32760 As mentioned earlier the live ranges are computed in terms of the execution
32761 sequence number of the iCodes, for example
32763 the iTemp0 is live from (i.e.
32764 first defined in iCode with execution sequence number 3, and is last used
32765 in the iCode with sequence number 5).
32766 For induction variables such as iTemp21 the live range computation extends
32767 the lifetime from the start to the end of the loop.
32769 The register allocator used the live range information to allocate registers,
32770 the same registers may be used for different temporaries if their live
32771 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
32772 iTemp17 since their live ranges do not overlap.
32773 In addition the allocator also takes into consideration the type and usage
32774 of a temporary, for example itemp6 is a pointer to near space and is used
32775 as to fetch data from (i.e.
32776 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
32777 Some short lived temporaries are allocated to special registers which have
32778 meaning to the code generator e.g.
32779 iTemp13 is allocated to a pseudo register CC which tells the back end that
32780 the temporary is used only for a conditional jump the code generation makes
32781 use of this information to optimize a compare and jump ICode.
32783 There are several loop optimizations
32784 \begin_inset LatexCommand \index{Loop optimization}
32788 performed by the compiler.
32789 It can detect induction variables iTemp21(i) and iTemp23(j).
32790 Also note the compiler does selective strength reduction
32791 \begin_inset LatexCommand \index{Strength reduction}
32796 the multiplication of an induction variable in line 18 (gint = j * 3) is
32797 changed to addition, a new temporary iTemp17 is allocated and assigned
32798 a initial value, a constant 3 is then added for each iteration of the loop.
32799 The compiler does not change the multiplication
32800 \begin_inset LatexCommand \index{Multiplication}
32804 in line 17 however since the processor does support an 8 * 8 bit multiplication.
32806 Note the dead code elimination
32807 \begin_inset LatexCommand \index{Dead-code elimination}
32811 optimization eliminated the dead assignments in line 7 & 8 to I and sum
32819 Sample.c (5:1:0:0) _entry($9) :
32824 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
32829 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
32834 Sample.c(11:4:53:0) preHeaderLbl0($11) :
32839 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
32845 Sample.c(11:6:5:1) _whilecontinue_0($1) :
32850 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
32856 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
32861 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
32867 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
32873 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
32879 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
32885 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
32886 * int}[r0] + 0x2 {short}
32891 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
32896 Sample.c(11:17:21:0)_whilebreak_0($3) :
32901 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
32906 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
32911 Sample.c(15:20:54:0)preHeaderLbl1($13) :
32916 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
32921 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
32926 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
32931 Sample.c(15:24:26:1)_forcond_0($4) :
32936 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
32942 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
32947 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
32948 + ITemp21 [lr21:38]{short}[r4]
32953 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
32959 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
32960 + iTemp15 [lr29:30]{short}[r1]
32965 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
32971 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
32977 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
32983 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
32989 Sample.c(19:38:47:1) goto _forcond_0($4)
32994 Sample.c(19:39:48:0)_forbreak_0($7) :
32999 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
33000 + ITemp11 [lr19:40]{short}[r3]
33005 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
33010 Sample.c(20:42:51:0)_return($8) :
33015 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
33021 Finally the code generated for this function:
33062 ; ----------------------------------------------
33067 ; function function
33072 ; ----------------------------------------------
33082 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
33094 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
33106 ;_whilecontinue_0($1) :
33116 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
33121 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
33180 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
33199 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
33246 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
33286 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
33312 ; iTemp6 [lr5:16]{_near * int}[r0] =
33317 ; iTemp6 [lr5:16]{_near * int}[r0] +
33334 ; goto _whilecontinue_0($1)
33346 ; _whilebreak_0($3) :
33356 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
33368 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
33380 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
33392 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
33411 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
33440 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
33445 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
33490 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
33495 ; iTemp21 [lr21:38]{short}[r4]
33521 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
33554 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
33559 ; iTemp15 [lr29:30]{short}[r1]
33578 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
33625 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
33672 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
33684 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
33698 cjne r5,#0xff,00104$
33710 ; goto _forcond_0($4)
33722 ; _forbreak_0($7) :
33732 ; ret iTemp24 [lr40:41]{short}
33775 A few words about basic block successors, predecessors and dominators
33778 Successors are basic blocks
33779 \begin_inset LatexCommand \index{Basic blocks}
33783 that might execute after this basic block.
33785 Predecessors are basic blocks that might execute before reaching this basic
33788 Dominators are basic blocks that WILL execute before reaching this basic
33822 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
33825 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
33828 c) domVect of [BB4] = BB1 ...
33829 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
33837 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
33847 Thanks to all the other volunteer developers who have helped with coding,
33848 testing, web-page creation, distribution sets, etc.
33849 You know who you are :-)
33857 Also thanks to Sourceforge
33858 \begin_inset LatexCommand \url{http://www.sf.net}
33862 which has hosted the project since 1999 and donates significant download
33863 bandwidth and probably more than
33871 CPU cycles per day.
33879 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
33880 minutes for (configure+make+regression test), and there is (i386, amd64,
33881 alpha, ppc64, (mingw32), sparc, macosx).
33888 This document was initially written by Sandeep Dutta
33891 All product names mentioned herein may be trademarks
33892 \begin_inset LatexCommand \index{Trademarks}
33896 of their respective companies.
33903 To avoid confusion, the installation and building options for SDCC itself
33904 (chapter 2) are not part of the index.
33908 \begin_inset LatexCommand \printindex{}