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
56 Please note: double dashed longoptions (e.g.
57 --version) are written this way: -
71 three consecutive dashes simply result in a long resp.
75 Architecture specific stuff (like memory models, code examples) should maybe
79 into seperate sections/chapters/appendices (it is hard to document PIC or
83 a 8051 centered document) - for now simply add.
89 SDCC Compiler User Guide
109 The above strings enclosed in $ are automatically updated by Subversion
116 \begin_inset LatexCommand \tableofcontents{}
149 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
154 designed for 8 bit Microprocessors.
155 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
157 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
161 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
162 Zilog Z80 based MCUs.
163 It can be retargeted for other microprocessors, support for Microchip PIC,
164 Atmel AVR is under development.
165 The entire source code for the compiler is distributed under GPL.
167 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
172 \begin_inset LatexCommand \index{aslink}
176 , an open source retargetable assembler & linker.
177 SDCC has extensive language extensions suitable for utilizing various microcont
178 rollers and underlying hardware effectively.
183 In addition to the MCU specific optimizations SDCC also does a host of standard
187 global sub expression elimination,
190 loop optimizations (loop invariant, strength reduction of induction variables
194 constant folding & propagation,
200 dead code elimination
210 For the back-end SDCC uses a global register allocation scheme which should
211 be well suited for other 8 bit MCUs.
216 The peep hole optimizer uses a rule based substitution mechanism which is
222 Supported data-types are:
227 <lyxtabular version="3" rows="8" columns="5">
229 <column alignment="center" valignment="top" leftline="true" width="0">
230 <column alignment="center" valignment="top" leftline="true" width="0">
231 <column alignment="center" valignment="top" leftline="true" width="0">
232 <column alignment="center" valignment="top" leftline="true" width="0">
233 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
234 <row topline="true" bottomline="true">
235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
251 <cell alignment="center" valignment="top" topline="true" leftline="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" rightline="true" usebox="none">
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
293 <cell alignment="center" valignment="top" topline="true" leftline="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" rightline="true" usebox="none">
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
335 <cell alignment="center" valignment="top" topline="true" leftline="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" rightline="true" usebox="none">
361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
377 <cell alignment="center" valignment="top" topline="true" leftline="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" rightline="true" usebox="none">
403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
444 <row topline="true" bottomline="true">
445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
474 -2.147.483.648, +2.147.483.647
477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
486 <row topline="true" bottomline="true">
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
536 <row topline="true" bottomline="true">
537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
582 The compiler also allows
584 inline assembler code
586 to be embedded anywhere in a function.
587 In addition, routines developed in assembly can also be called.
591 SDCC also provides an option (-
601 -cyclomatic) to report the relative complexity of a function.
602 These functions can then be further optimized, or hand coded in assembly
608 SDCC also comes with a companion source level debugger SDCDB, the debugger
609 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
613 The latest version can be downloaded from
614 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
624 Please note: the compiler will probably always be some steps ahead of this
629 \begin_inset LatexCommand \index{Status of documentation}
639 Obviously this has pros and cons
648 All packages used in this compiler system are
656 ; source code for all the sub-packages (pre-processor, assemblers, linkers
657 etc) is distributed with the package.
658 This documentation is maintained using a freeware word processor (LyX).
660 This program is free software; you can redistribute it and/or modify it
661 under the terms of the GNU General Public License
662 \begin_inset LatexCommand \index{GNU General Public License, GPL}
666 as published by the Free Software Foundation; either version 2, or (at
667 your option) any later version.
668 This program is distributed in the hope that it will be useful, but WITHOUT
669 ANY WARRANTY; without even the implied warranty
670 \begin_inset LatexCommand \index{warranty}
674 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
675 See the GNU General Public License for more details.
676 You should have received a copy of the GNU General Public License along
677 with this program; if not, write to the Free Software Foundation, 59 Temple
678 Place - Suite 330, Boston, MA 02111-1307, USA.
679 In other words, you are welcome to use, share and improve this program.
680 You are forbidden to forbid anyone else to use, share and improve what
682 Help stamp out software-hoarding!
685 Typographic conventions
686 \begin_inset LatexCommand \index{Typographic conventions}
693 Throughout this manual, we will use the following convention.
694 Commands you have to type in are printed in
702 Code samples are printed in
707 Interesting items and new terms are printed in
713 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
717 with previous versions
718 \begin_inset LatexCommand \index{Compatibility with previous versions}
725 This version has numerous bug fixes compared with the previous version.
726 But we also introduced some incompatibilities with older versions.
727 Not just for the fun of it, but to make the compiler more stable, efficient
729 \begin_inset LatexCommand \index{ANSI-compliance}
734 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
738 for ANSI-Compliance).
744 short is now equivalent to int (16 bits), it used to be equivalent to char
745 (8 bits) which is not ANSI compliant.
748 the default directory for gcc-builds where include, library and documentation
749 files are stored is now in /usr/local/share.
752 char type parameters to vararg
753 \begin_inset LatexCommand \index{vararg, va\_arg}
757 functions are casted to int unless explicitly casted
758 \begin_inset Marginal
785 will push a as an int and as a char resp.
798 -regextend has been removed.
811 -noregparms has been removed.
824 -stack-after-data has been removed.
828 \begin_inset LatexCommand \index{bit}
833 \begin_inset LatexCommand \index{sbit}
838 \begin_inset LatexCommand \index{\_\_sbit}
842 types now consistently behave like the C99 _Bool type with respect to type
844 \begin_inset LatexCommand \index{type conversion}
849 \begin_inset LatexCommand \index{type promotion}
854 The most common incompatibility resulting from this change is related to
856 \begin_inset LatexCommand \index{Bit toggling}
871 \begin_inset LatexCommand \index{\~\/ Operator}
875 b; /* equivalent to b=1 instead of toggling b */
876 \begin_inset Marginal
891 b = !b; /* toggles b */
895 In previous versions, both forms would have toggled the bit.
900 <pending: more incompatibilities?>
906 What do you need before you start installation of SDCC? A computer, and
908 The preferred method of installation is to compile SDCC from source using
910 For Windows some pre-compiled binary distributions are available for your
912 You should have some experience with command line tools and compiler use.
918 The SDCC home page at
919 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
923 is a great place to find distribution sets.
924 You can also find links to the user mailing lists that offer help or discuss
925 SDCC with other SDCC users.
926 Web links to other SDCC related sites can also be found here.
927 This document can be found in the DOC directory of the source package as
929 A pdf version of this document is available at
930 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
935 Some of the other tools (simulator and assembler) included with SDCC contain
936 their own documentation and can be found in the source distribution.
937 If you want the latest unreleased software, the complete source package
938 is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
942 Wishes for the future
945 There are (and always will be) some things that could be done.
946 Here are some I can think of:
953 char KernelFunction3(char p) at 0x340;
961 \begin_inset LatexCommand \index{code banking (limited support)}
971 If you can think of some more, please see the section
972 \begin_inset LatexCommand \ref{sub:Requesting-Features}
976 about filing feature requests
977 \begin_inset LatexCommand \index{Requesting features}
982 \begin_inset LatexCommand \index{Feature request}
992 \begin_inset LatexCommand \index{Installation}
999 For most users it is sufficient to skip to either section
1000 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1005 \begin_inset LatexCommand \ref{sub:Windows-Install}
1010 More detailed instructions follow below.
1014 \begin_inset LatexCommand \index{Options SDCC configuration}
1021 The install paths, search paths and other options are defined when running
1023 The defaults can be overridden by:
1025 \labelwidthstring 00.00.0000
1037 -prefix see table below
1039 \labelwidthstring 00.00.0000
1051 -exec_prefix see table below
1053 \labelwidthstring 00.00.0000
1065 -bindir see table below
1067 \labelwidthstring 00.00.0000
1079 -datadir see table below
1081 \labelwidthstring 00.00.0000
1093 -datarootdir see table below
1097 \labelwidthstring 00.00.0000
1101 docdir environment variable, see table below
1103 \labelwidthstring 00.00.0000
1107 include_dir_suffix environment variable, see table below
1109 \labelwidthstring 00.00.0000
1113 lib_dir_suffix environment variable, see table below
1115 \labelwidthstring 00.00.0000
1119 sdccconf_h_dir_separator environment variable, either / or
1124 This character will only be used in sdccconf.h; don't forget it's a C-header,
1125 therefore a double-backslash is needed there.
1129 \labelwidthstring 00.00.0000
1141 -disable-mcs51-port Excludes the Intel mcs51 port
1143 \labelwidthstring 00.00.0000
1155 -disable-gbz80-port Excludes the Gameboy gbz80 port
1157 \labelwidthstring 00.00.0000
1169 -disable-z80-port Excludes the z80 port
1171 \labelwidthstring 00.00.0000
1183 -disable-avr-port Excludes the AVR port
1185 \labelwidthstring 00.00.0000
1197 -disable-ds390-port Excludes the DS390 port
1199 \labelwidthstring 00.00.0000
1211 -disable-hc08-port Excludes the HC08 port
1213 \labelwidthstring 00.00.0000
1225 -disable-pic-port Excludes the PIC port
1227 \labelwidthstring 00.00.0000
1239 -disable-xa51-port Excludes the XA51 port
1241 \labelwidthstring 00.00.0000
1253 -disable-ucsim Disables configuring and building of ucsim
1255 \labelwidthstring 00.00.0000
1267 -disable-device-lib Disables automatically building device libraries
1269 \labelwidthstring 00.00.0000
1281 -disable-packihx Disables building packihx
1285 \labelwidthstring 00.00.0000
1297 -enable-doc Build pdf, html and txt files from the lyx sources
1299 \labelwidthstring 00.00.0000
1311 -enable-libgc Use the Bohem memory allocator.
1312 Lower runtime footprint.
1315 Furthermore the environment variables CC, CFLAGS, ...
1316 the tools and their arguments can be influenced.
1317 Please see `configure -
1327 -help` and the man/info pages of `configure` for details.
1331 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1332 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1333 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1334 At the moment it's not possible to change the default settings (it was
1335 simply never required).
1339 These configure options are compiled into the binaries, and can only be
1340 changed by rerunning 'configure' and recompiling SDCC.
1341 The configure options are written in
1345 to distinguish them from run time environment variables (see section search
1351 \begin_inset Quotes sld
1355 \begin_inset Quotes srd
1358 are used by the SDCC team to build the official Win32 binaries.
1359 The SDCC team uses Mingw32 to build the official Windows binaries, because
1366 a gcc compiler and last but not least
1369 the binaries can be built by cross compiling on Sourceforge's compile farm.
1372 See the examples, how to pass the Win32 settings to 'configure'.
1373 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1374 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1385 \begin_inset Tabular
1386 <lyxtabular version="3" rows="9" columns="3">
1388 <column alignment="block" valignment="top" leftline="true" width="0in">
1389 <column alignment="block" valignment="top" leftline="true" width="0in">
1390 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1391 <row topline="true" bottomline="true">
1392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1417 <row topline="true">
1418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1447 <row topline="true">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1479 <row topline="true">
1480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1517 <row topline="true">
1518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1549 <row topline="true">
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1583 <row topline="true">
1584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1621 <row topline="true">
1622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1649 <row topline="true" bottomline="true">
1650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1686 'configure' also computes relative paths.
1687 This is needed for full relocatability of a binary package and to complete
1688 search paths (see section search paths below):
1694 \begin_inset Tabular
1695 <lyxtabular version="3" rows="4" columns="3">
1697 <column alignment="block" valignment="top" leftline="true" width="0in">
1698 <column alignment="block" valignment="top" leftline="true" width="0in">
1699 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1700 <row topline="true" bottomline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 <row topline="true" bottomline="true">
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1754 <row bottomline="true">
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1782 <row bottomline="true">
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1834 \begin_inset Quotes srd
1838 \begin_inset Quotes srd
1852 \begin_inset Quotes srd
1856 \begin_inset Quotes srd
1884 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1893 \begin_inset Quotes srd
1896 i586-mingw32msvc-gcc
1897 \begin_inset Quotes srd
1901 \begin_inset Quotes srd
1904 i586-mingw32msvc-g++
1905 \begin_inset Quotes srd
1913 \begin_inset Quotes srd
1916 i586-mingw32msvc-ranlib
1917 \begin_inset Quotes srd
1925 \begin_inset Quotes srd
1928 i586-mingw32msvc-strip
1929 \begin_inset Quotes srd
1947 \begin_inset Quotes srd
1951 \begin_inset Quotes srd
1969 \begin_inset Quotes srd
1973 \begin_inset Quotes srd
1981 \begin_inset Quotes srd
1987 \begin_inset Quotes srd
1995 \begin_inset Quotes srd
1999 \begin_inset Quotes srd
2007 \begin_inset Quotes srd
2011 \begin_inset Quotes srd
2018 sdccconf_h_dir_separator=
2019 \begin_inset Quotes srd
2031 \begin_inset Quotes srd
2062 -host=i586-mingw32msvc
2076 -build=unknown-unknown-linux-gnu
2080 \begin_inset Quotes sld
2084 \begin_inset Quotes srd
2087 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2106 \begin_inset Quotes srd
2110 \begin_inset Quotes srd
2128 \begin_inset Quotes srd
2132 \begin_inset Quotes srd
2140 \begin_inset Quotes srd
2146 \begin_inset Quotes srd
2154 \begin_inset Quotes srd
2158 \begin_inset Quotes srd
2166 \begin_inset Quotes srd
2170 \begin_inset Quotes srd
2177 sdccconf_h_dir_separator=
2178 \begin_inset Quotes srd
2190 \begin_inset Quotes srd
2198 \begin_inset Quotes srd
2202 \begin_inset Quotes srd
2210 \begin_inset Quotes srd
2214 \begin_inset Quotes srd
2220 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2231 -C' turns on caching, which gives a little bit extra speed.
2232 However if options are changed, it can be necessary to delete the config.cache
2235 \added_space_bottom medskip
2237 \begin_inset LatexCommand \label{sub:Install-paths}
2242 \begin_inset LatexCommand \index{Install paths}
2250 \begin_inset Tabular
2251 <lyxtabular version="3" rows="5" columns="4">
2253 <column alignment="left" valignment="top" leftline="true" width="0">
2254 <column alignment="left" valignment="top" leftline="true" width="0">
2255 <column alignment="left" valignment="top" leftline="true" width="0">
2256 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2257 <row topline="true" bottomline="true">
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2299 <row topline="true">
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2339 <row topline="true">
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2355 $DATADIR/ $INCLUDE_DIR_SUFFIX
2358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2363 /usr/local/share/sdcc/include
2366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2379 <row topline="true">
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2395 $DATADIR/$LIB_DIR_SUFFIX
2398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2403 /usr/local/share/sdcc/lib
2406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2419 <row topline="true" bottomline="true">
2420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2443 /usr/local/share/sdcc/doc
2446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2468 *compiler, preprocessor, assembler, and linker
2474 is auto-appended by the compiler, e.g.
2475 small, large, z80, ds390 etc
2478 The install paths can still be changed during `make install` with e.g.:
2481 make install prefix=$(HOME)/local/sdcc
2484 Of course this doesn't change the search paths compiled into the binaries.
2488 Moreover the install path can be changed by defining DESTDIR
2489 \begin_inset LatexCommand \index{DESTDIR}
2496 make install DESTDIR=$(HOME)/sdcc.rpm/
2499 Please note that DESTDIR must have a trailing slash!
2503 \begin_inset LatexCommand \label{sub:Search-Paths}
2508 \begin_inset LatexCommand \index{Search path}
2515 Some search paths or parts of them are determined by configure variables
2520 , see section above).
2521 Further search paths are determined by environment variables during runtime.
2524 The paths searched when running the compiler are as follows (the first catch
2530 Binary files (preprocessor, assembler and linker)
2536 \begin_inset Tabular
2537 <lyxtabular version="3" rows="4" columns="3">
2539 <column alignment="block" valignment="top" leftline="true" width="0in">
2540 <column alignment="block" valignment="top" leftline="true" width="0in">
2541 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2542 <row topline="true" bottomline="true">
2543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2568 <row topline="true">
2569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2598 <row topline="true">
2599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2604 Path of argv[0] (if available)
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2624 <row topline="true" bottomline="true">
2625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2666 \begin_inset Tabular
2667 <lyxtabular version="3" rows="6" columns="3">
2669 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2670 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2671 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2672 <row topline="true" bottomline="true">
2673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2698 <row topline="true">
2699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2754 <row topline="true">
2755 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2780 <row topline="true">
2781 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2795 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2818 <row topline="true">
2819 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2900 <row topline="true" bottomline="true">
2901 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2917 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2922 /usr/local/share/sdcc/
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2955 -nostdinc disables the last two search paths.
2965 With the exception of
2966 \begin_inset Quotes sld
2980 \begin_inset Quotes srd
2987 is auto-appended by the compiler (e.g.
2988 small, large, z80, ds390 etc.).
2995 \begin_inset Tabular
2996 <lyxtabular version="3" rows="6" columns="3">
2998 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2999 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3000 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3001 <row topline="true" bottomline="true">
3002 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3010 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3027 <row topline="true">
3028 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3083 <row topline="true">
3084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3123 <row topline="true">
3124 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3135 $LIB_DIR_SUFFIX/<model>
3138 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3152 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 <row topline="true">
3170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3185 $LIB_DIR_SUFFIX/<model>
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3297 <row topline="true" bottomline="true">
3298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3307 $LIB_DIR_SUFFIX/<model>
3310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3315 /usr/local/share/sdcc/
3322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3346 Don't delete any of the stray spaces in the table above without checking
3347 the HTML output (last line)!
3366 -nostdlib disables the last two search paths.
3370 \begin_inset LatexCommand \index{Building SDCC}
3377 Building SDCC on Linux
3378 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3387 Download the source package
3389 either from the SDCC Subversion repository or from the nightly snapshots
3391 , it will be named something like sdcc
3402 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3411 Bring up a command line terminal, such as xterm.
3416 Unpack the file using a command like:
3419 "tar -xvzf sdcc.src.tar.gz
3424 , this will create a sub-directory called sdcc with all of the sources.
3427 Change directory into the main SDCC directory, for example type:
3444 This configures the package for compilation on your system.
3460 All of the source packages will compile, this can take a while.
3476 This copies the binary executables, the include files, the libraries and
3477 the documentation to the install directories.
3478 Proceed with section
3479 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3486 Building SDCC on OSX 2.x
3489 Follow the instruction for Linux.
3493 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3494 )) fails to compile SDCC.
3495 Fortunately there's also gcc 2.9.x installed, which works fine.
3496 This compiler can be selected by running 'configure' with:
3499 ./configure CC=gcc2 CXX=g++2
3502 Cross compiling SDCC on Linux for Windows
3505 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3506 See section 'Configure Options'.
3509 Building SDCC using Cygwin and Mingw32
3512 For building and installing a Cygwin executable follow the instructions
3518 \begin_inset Quotes sld
3522 \begin_inset Quotes srd
3525 Win32-binary can be built, which will not need the Cygwin-DLL.
3526 For the necessary 'configure' options see section 'configure options' or
3527 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3531 In order to install Cygwin on Windows download setup.exe from
3532 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3538 \begin_inset Quotes sld
3541 default text file type
3542 \begin_inset Quotes srd
3546 \begin_inset Quotes sld
3550 \begin_inset Quotes srd
3553 and download/install at least the following packages.
3554 Some packages are selected by default, others will be automatically selected
3555 because of dependencies with the manually selected packages.
3556 Never deselect these packages!
3565 gcc ; version 3.x is fine, no need to use the old 2.9x
3568 binutils ; selected with gcc
3574 rxvt ; a nice console, which makes life much easier under windoze (see below)
3577 man ; not really needed for building SDCC, but you'll miss it sooner or
3581 less ; not really needed for building SDCC, but you'll miss it sooner or
3585 svn ; only if you use Subversion access
3588 If you want to develop something you'll need:
3591 python ; for the regression tests
3594 gdb ; the gnu debugger, together with the nice GUI
3595 \begin_inset Quotes sld
3599 \begin_inset Quotes srd
3605 openssh ; to access the CF or commit changes
3608 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3609 use autoconf-stable!
3612 rxvt is a nice console with history.
3613 Replace in your cygwin.bat the line
3632 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3635 -bg black -fg white -geometry 100x65 -e bash -
3648 Text selected with the mouse is automatically copied to the clipboard, pasting
3649 works with shift-insert.
3653 The other good tip is to make sure you have no //c/-style paths anywhere,
3654 use /cygdrive/c/ instead.
3655 Using // invokes a network lookup which is very slow.
3657 \begin_inset Quotes sld
3661 \begin_inset Quotes srd
3664 is too long, you can change it with e.g.
3670 SDCC sources use the unix line ending LF.
3671 Life is much easier, if you store the source tree on a drive which is mounted
3673 And use an editor which can handle LF-only line endings.
3674 Make sure not to commit files with windows line endings.
3675 The tabulator spacing
3676 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3680 used in the project is 8.
3681 Although a tabulator spacing of 8 is a sensible choice for programmers
3682 (it's a power of 2 and allows to display 8/16 bit signed variables without
3683 loosing columns) the plan is to move towards using only spaces in the source.
3686 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3691 Download the source package
3693 either from the SDCC Subversion repository or from the
3694 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3700 , it will be named something like sdcc
3707 SDCC is distributed with all the projects, workspaces, and files you need
3708 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3709 The workspace name is 'sdcc.dsw'.
3710 Please note that as it is now, all the executables are created in a folder
3714 Once built you need to copy the executables from sdcc
3718 bin before running SDCC.
3723 WARNING: Visual studio is very picky with line terminations; it expects
3724 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3725 When using the Subversion repository it's easiest to configure the svn
3726 client to convert automatically for you.
3727 If however you are getting a message such as "This makefile was not generated
3728 by Developer Studio etc.
3730 \begin_inset Quotes srd
3733 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3734 need to convert the Unix style line endings to DOS style line endings.
3735 To do so you can use the
3736 \begin_inset Quotes sld
3740 \begin_inset Quotes srd
3743 utility freely available on the internet.
3744 Doug Hawkins reported in the sdcc-user list that this works:
3752 SDCC> unix2dos sdcc.dsw
3758 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3762 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3763 flex.exe, and gawk.exe.
3764 One good place to get them is
3765 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3773 Download the file UnxUtils
3774 \begin_inset LatexCommand \index{UnxUtils}
3779 Now you have to install the utilities and setup MSVC so it can locate the
3781 Here there are two alternatives (choose one!):
3788 a) Extract UnxUtils.zip to your C:
3790 hard disk PRESERVING the original paths, otherwise bison won't work.
3791 (If you are using WinZip make certain that 'Use folder names' is selected)
3795 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3796 in 'Show directories for:' select 'Executable files', and in the directories
3797 window add a new path: 'C:
3807 (As a side effect, you get a bunch of Unix utilities that could be useful,
3808 such as diff and patch.)
3815 This one avoids extracting a bunch of files you may not use, but requires
3820 a) Create a directory were to put the tools needed, or use a directory already
3828 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3829 to such directory WITHOUT preserving the original paths.
3830 (If you are using WinZip make certain that 'Use folder names' is not selected)
3834 c) Rename bison.exe to '_bison.exe'.
3838 d) Create a batch file 'bison.bat' in 'C:
3842 ' and add these lines:
3862 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3866 Steps 'c' and 'd' are needed because bison requires by default that the
3867 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3868 '/usr/local/share/' I think.
3869 So it is necessary to tell bison where those files are located if they
3870 are not in such directory.
3871 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3875 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3876 in 'Show directories for:' select 'Executable files', and in the directories
3877 window add a new path: 'c:
3880 Note that you can use any other path instead of 'c:
3882 util', even the path where the Visual C++ tools are, probably: 'C:
3886 Microsoft Visual Studio
3891 So you don't have to execute step 'e' :)
3895 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3896 the executables from sdcc
3900 bin, and you can compile using SDCC.
3903 Building SDCC Using Borland
3906 From the sdcc directory, run the command "make -f Makefile.bcc".
3907 This should regenerate all the .exe files in the bin directory except for
3911 If you modify any source files and need to rebuild, be aware that the dependenci
3912 es may not be correctly calculated.
3913 The safest option is to delete all .obj files and run the build again.
3914 From a Cygwin BASH prompt, this can easily be done with the command (be
3915 sure you are in the sdcc directory):
3925 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3927 ) -print -exec rm {}
3936 or on Windows NT/2000/XP from the command prompt with the command:
3943 del /s *.obj *.lib *.rul
3946 from the sdcc directory.
3949 Windows Install Using a ZIP Package
3952 Download the binary zip package from
3953 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3957 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3958 This should unpack to a group of sub-directories.
3959 An example directory structure after unpacking the mingw32 package is:
3964 bin for the executables, c:
3972 lib for the include and libraries.
3975 Adjust your environment variable PATH to include the location of the bin
3976 directory or start sdcc using the full path.
3979 Windows Install Using the Setup Program
3980 \begin_inset LatexCommand \label{sub:Windows-Install}
3987 Download the setup program
3989 sdcc-x.y.z-setup.exe
3991 for an official release from
3994 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3998 or a setup program for one of the snapshots
4000 sdcc-yyyymmdd-xxxx-setup.exe
4003 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4008 A windows typical installer will guide you through the installation process.
4012 \begin_inset LatexCommand \index{VPATH}
4019 SDCC supports the VPATH feature provided by configure and make.
4020 It allows to separate the source and build trees.
4052 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4053 # extract source to directory sdcc
4058 mkdir sdcc.build\SpecialChar ~
4067 # put output in sdcc.build
4077 ../sdcc/configure\SpecialChar ~
4085 # configure is doing all the magic!
4097 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4098 It automagically computes the variables srcdir, top_srcdir and top_buildir
4104 the generated files will be in ~/sdcc.build, while the source files stay
4107 This is not only usefull for building different binaries, e.g.
4108 when cross compiling.
4109 It also gives you a much better overview in the source tree when all the
4110 generated files are not scattered between the source files.
4111 And the best thing is: if you want to change a file you can leave the original
4112 file untouched in the source directory.
4113 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4114 Makefile.dep` and `make`.
4119 will do the rest for you!
4122 Building the Documentation
4135 -enable-doc to the configure arguments to build the documentation together
4136 with all the other stuff.
4137 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4138 dvips and makeindex) to get the job done.
4139 Another possibility is to change to the doc directory and to type
4143 \begin_inset Quotes srd
4147 \begin_inset Quotes srd
4154 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4157 \begin_inset LatexCommand \url{http://www.lyx.org}
4161 as editor is straightforward.
4162 Prebuilt documentation in html and pdf format is available from
4163 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4170 Reading the Documentation
4171 \begin_inset LatexCommand \index{Documentation}
4178 Currently reading the document in pdf format is recommended, as for unknown
4179 reason the hyperlinks are working there whereas in the html version they
4186 If you should know why please drop us a note
4192 You'll find the pdf version
4193 \begin_inset LatexCommand \index{PDF version of this document}
4198 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4206 \begin_inset LatexCommand \index{HTML version of this document}
4211 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4217 This documentation is in some aspects different from a commercial documentation:
4221 It tries to document SDCC for several processor architectures in one document
4222 (commercially these probably would be separate documents/products).
4224 \begin_inset LatexCommand \index{Status of documentation}
4228 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4230 Z80, PIC14, PIC16 and HC08.
4233 There are many references pointing away from this documentation.
4234 Don't let this distract you.
4236 was a reference like
4237 \begin_inset LatexCommand \url{http://www.opencores.org}
4241 together with a statement
4242 \begin_inset Quotes sld
4245 some processors which are targetted by SDCC can be implemented in a
4262 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4267 \begin_inset Quotes srd
4271 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4276 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4281 \begin_inset Quotes sld
4284 have you ever heard of an open source compiler that compiles a subset of
4286 \begin_inset Quotes srd
4289 we expect you to have a quick look there and come back.
4290 If you read this you are on the right track.
4293 Some sections attribute more space to problems, restrictions and warnings
4294 than to the solution.
4297 The installation section and the section about the debugger is intimidating.
4300 There are still lots of typos and there are more different writing styles
4304 Testing the SDCC Compiler
4305 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4312 The first thing you should do after installing your SDCC compiler is to
4328 \begin_inset LatexCommand \index{version}
4335 at the prompt, and the program should run and output its version like:
4340 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4344 If it doesn't run, or gives a message about not finding sdcc program, then
4345 you need to check over your installation.
4346 Make sure that the sdcc bin directory is in your executable search path
4347 defined by the PATH environment setting (
4352 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4359 Install trouble-shooting for suggestions
4362 Make sure that the sdcc program is in the bin folder, if not perhaps something
4363 did not install correctly.
4371 is commonly installed as described in section
4372 \begin_inset Quotes sld
4375 Install and search paths
4376 \begin_inset Quotes srd
4385 Make sure the compiler works on a very simple example.
4386 Type in the following test.c program using your favorite
4412 Compile this using the following command:
4421 If all goes well, the compiler will generate a test.asm and test.rel file.
4422 Congratulations, you've just compiled your first program with SDCC.
4423 We used the -c option to tell SDCC not to link the generated code, just
4424 to keep things simple for this step.
4432 The next step is to try it with the linker.
4442 If all goes well the compiler will link with the libraries and produce
4443 a test.ihx output file.
4448 (no test.ihx, and the linker generates warnings), then the problem is most
4457 usr/local/share/sdcc/lib directory
4464 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4471 Install trouble-shooting for suggestions).
4479 The final test is to ensure
4487 header files and libraries.
4488 Edit test.c and change it to the following:
4505 strcpy(str1, "testing");
4512 Compile this by typing
4519 This should generate a test.ihx output file, and it should give no warnings
4520 such as not finding the string.h file.
4521 If it cannot find the string.h file, then the problem is that
4525 cannot find the /usr/local/share/sdcc/include directory
4532 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4539 Install trouble-shooting section for suggestions).
4557 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4561 to find exactly where SDCC is looking for the include and lib files.
4564 Install Trouble-shooting
4565 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4570 \begin_inset LatexCommand \index{Install trouble-shooting}
4577 If SDCC does not build correctly
4580 A thing to try is starting from scratch by unpacking the .tgz source package
4581 again in an empty directory.
4589 ./configure 2>&1 | tee configure.log
4603 make 2>&1 | tee make.log
4610 If anything goes wrong, you can review the log files to locate the problem.
4611 Or a relevant part of this can be attached to an email that could be helpful
4612 when requesting help from the mailing list.
4616 \begin_inset Quotes sld
4620 \begin_inset Quotes srd
4627 \begin_inset Quotes sld
4631 \begin_inset Quotes srd
4634 command is a script that analyzes your system and performs some configuration
4635 to ensure the source package compiles on your system.
4636 It will take a few minutes to run, and will compile a few tests to determine
4637 what compiler features are installed.
4641 \begin_inset Quotes sld
4645 \begin_inset Quotes srd
4651 This runs the GNU make tool, which automatically compiles all the source
4652 packages into the final installed binary executables.
4656 \begin_inset Quotes sld
4660 \begin_inset Quotes erd
4666 This will install the compiler, other executables libraries and include
4667 files into the appropriate directories.
4669 \begin_inset LatexCommand \ref{sub:Install-paths}
4675 \begin_inset LatexCommand \ref{sub:Search-Paths}
4680 about install and search paths.
4682 On most systems you will need super-user privileges to do this.
4688 SDCC is not just a compiler, but a collection of tools by various developers.
4689 These include linkers, assemblers, simulators and other components.
4690 Here is a summary of some of the components.
4691 Note that the included simulator and assembler have separate documentation
4692 which you can find in the source package in their respective directories.
4693 As SDCC grows to include support for other processors, other packages from
4694 various developers are included and may have their own sets of documentation.
4698 You might want to look at the files which are installed in <installdir>.
4699 At the time of this writing, we find the following programs for gcc-builds:
4703 In <installdir>/bin:
4706 sdcc - The compiler.
4709 sdcpp - The C preprocessor.
4712 asx8051 - The assembler for 8051 type processors.
4719 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4722 aslink -The linker for 8051 type processors.
4729 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4732 s51 - The ucSim 8051 simulator.
4735 sdcdb - The source debugger.
4738 packihx - A tool to pack (compress) Intel hex files.
4741 In <installdir>/share/sdcc/include
4747 In <installdir>/share/sdcc/lib
4750 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4754 In <installdir>/share/sdcc/doc
4760 As development for other processors proceeds, this list will expand to include
4761 executables to support processors like AVR, PIC, etc.
4767 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4768 the assembler and linkage editor.
4771 sdcpp - The C-Preprocessor
4775 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4779 is a modified version of the GNU cpp
4780 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4785 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4790 The C preprocessor is used to pull in #include sources, process #ifdef
4791 statements, #defines and so on.
4802 - The Assemblers and Linkage Editors
4805 This is retargettable assembler & linkage editor, it was developed by Alan
4807 John Hartman created the version for 8051, and I (Sandeep) have made some
4808 enhancements and bug fixes for it to work properly with SDCC.
4815 \begin_inset LatexCommand \index{s51}
4819 is a freeware, opensource simulator developed by Daniel Drotos.
4820 The simulator is built as part of the build process.
4821 For more information visit Daniel's web site at:
4822 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4827 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4831 sdcdb - Source Level Debugger
4835 \begin_inset LatexCommand \index{SDCDB (debugger)}
4839 is the companion source level debugger.
4840 More about SDCDB in section
4841 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4846 The current version of the debugger uses Daniel's Simulator S51
4847 \begin_inset LatexCommand \index{s51}
4851 , but can be easily changed to use other simulators.
4860 Single Source File Projects
4863 For single source file 8051 projects the process is very simple.
4864 Compile your programs with the following command
4867 "sdcc sourcefile.c".
4871 This will compile, assemble and link your source file.
4872 Output files are as follows:
4876 \begin_inset LatexCommand \index{<file>.asm}
4881 \begin_inset LatexCommand \index{Assembler source}
4885 file created by the compiler
4889 \begin_inset LatexCommand \index{<file>.lst}
4894 \begin_inset LatexCommand \index{Assembler listing}
4898 file created by the Assembler
4902 \begin_inset LatexCommand \index{<file>.rst}
4907 \begin_inset LatexCommand \index{Assembler listing}
4911 file updated with linkedit information, created by linkage editor
4915 \begin_inset LatexCommand \index{<file>.sym}
4920 \begin_inset LatexCommand \index{Symbol listing}
4924 for the sourcefile, created by the assembler
4928 \begin_inset LatexCommand \index{<file>.rel}
4933 \begin_inset LatexCommand \index{<file>.o}
4938 \begin_inset LatexCommand \index{Object file}
4942 created by the assembler, input to Linkage editor
4946 \begin_inset LatexCommand \index{<file>.map}
4951 \begin_inset LatexCommand \index{Memory map}
4955 for the load module, created by the Linker
4959 \begin_inset LatexCommand \index{<file>.mem}
4963 - A file with a summary of the memory usage
4967 \begin_inset LatexCommand \index{<file>.ihx}
4971 - The load module in Intel hex format
4972 \begin_inset LatexCommand \index{Intel hex format}
4976 (you can select the Motorola S19 format
4977 \begin_inset LatexCommand \index{Motorola S19 format}
4992 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4997 If you need another format you might want to use
5004 \begin_inset LatexCommand \index{objdump (tool)}
5015 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5020 Both formats are documented in the documentation of srecord
5021 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5029 \begin_inset LatexCommand \index{<file>.adb}
5033 - An intermediate file containing debug information needed to create the
5045 \begin_inset LatexCommand \index{-\/-debug}
5053 \begin_inset LatexCommand \index{<file>.cdb}
5057 - An optional file (with -
5067 -debug) containing debug information.
5068 The format is documented in cdbfileformat.pdf
5073 \begin_inset LatexCommand \index{<file> (no extension)}
5077 An optional AOMF or AOMF51
5078 \begin_inset LatexCommand \index{AOMF, AOMF51}
5083 \begin_inset LatexCommand \label{OMF file}
5087 file containing debug information (generated with option -
5114 ormat is commonly used by third party tools (debuggers
5115 \begin_inset LatexCommand \index{Debugger}
5119 , simulators, emulators)
5123 \begin_inset LatexCommand \index{<file>.dump*}
5127 - Dump file to debug the compiler it self (generated with option -
5137 -dumpall) (see section
5138 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5144 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5150 \begin_inset Quotes sld
5153 Anatomy of the compiler
5154 \begin_inset Quotes srd
5160 Postprocessing the Intel Hex
5161 \begin_inset LatexCommand \index{Intel hex format}
5168 In most cases this won't be needed but the Intel Hex file
5169 \begin_inset LatexCommand \index{<file>.ihx}
5173 which is generated by SDCC might include lines of varying length and the
5174 addresses within the file are not guaranteed to be strictly ascending.
5175 If your toolchain or a bootloader does not like this you can use the tool
5181 \begin_inset LatexCommand \index{packihx (tool)}
5185 which is part of the SDCC distribution:
5192 packihx sourcefile.ihx >sourcefile.hex
5199 The separately available
5204 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5208 package additionally allows to set undefined locations to a predefined
5209 value, to insert checksums
5210 \begin_inset LatexCommand \index{checksum}
5214 of various flavours (crc, add, xor) and to perform other manipulations
5215 (convert, split, crop, offset, ...).
5223 srec_cat\SpecialChar ~
5225 sourcefile.ihx -intel\SpecialChar ~
5227 -o sourcefile.hex -intel
5234 An example for a more complex command line
5240 the command backfills
5241 \begin_inset LatexCommand \index{backfill unused memory}
5245 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5247 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5248 will be interpreted as an
5256 (where an emergency routine could sit).
5267 srec_cat\SpecialChar ~
5268 sourcefile.ihx -intel\SpecialChar ~
5270 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5271 -little-endian-checksum-nega
5272 tive 0xfffe 0x02 0x02\SpecialChar ~
5274 -o sourcefile.hex -intel
5283 The srecord package is available at
5284 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5291 Projects with Multiple Source Files
5294 SDCC can compile only ONE file at a time.
5295 Let us for example assume that you have a project containing the following
5300 foo1.c (contains some functions)
5302 foo2.c (contains some more functions)
5304 foomain.c (contains more functions and the function main)
5312 The first two files will need to be compiled separately with the commands:
5344 Then compile the source file containing the
5349 \begin_inset LatexCommand \index{Linker}
5353 the files together with the following command:
5361 foomain.c\SpecialChar ~
5362 foo1.rel\SpecialChar ~
5367 \begin_inset LatexCommand \index{<file>.rel}
5379 can be separately compiled as well:
5390 sdcc foomain.rel foo1.rel foo2.rel
5397 The file containing the
5412 file specified in the command line, since the linkage editor processes
5413 file in the order they are presented to it.
5414 The linker is invoked from SDCC using a script file with extension .lnk
5415 \begin_inset LatexCommand \index{<file>.lnk}
5420 You can view this file to troubleshoot linking problems such as those arising
5421 from missing libraries.
5424 Projects with Additional Libraries
5425 \begin_inset LatexCommand \index{Libraries}
5432 Some reusable routines may be compiled into a library, see the documentation
5433 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5437 \begin_inset LatexCommand \index{<file>.lib}
5444 Libraries created in this manner can be included in the command line.
5445 Make sure you include the -L <library-path> option to tell the linker where
5446 to look for these files if they are not in the current directory.
5447 Here is an example, assuming you have the source file
5459 (if that is not the same as your current project):
5466 sdcc foomain.c foolib.lib -L mylib
5477 must be an absolute path name.
5481 The most efficient way to use libraries is to keep separate modules in separate
5483 The lib file now should name all the modules.rel
5484 \begin_inset LatexCommand \index{<file>.rel}
5489 For an example see the standard library file
5493 in the directory <installdir>/share/lib/small.
5496 Using sdcclib to Create and Manage Libraries
5497 \begin_inset LatexCommand \index{sdcclib}
5504 Alternatively, instead of having a .rel file for each entry on the library
5505 file as described in the preceding section, sdcclib can be used to embed
5506 all the modules belonging to such library in the library file itself.
5507 This results in a larger library file, but it greatly reduces the number
5508 of disk files accessed by the linker.
5509 Additionally, the packed library file contains an index of all include
5510 modules and symbols that significantly speeds up the linking process.
5511 To display a list of options supported by sdcclib type:
5520 \begin_inset LatexCommand \index{sdcclib}
5531 To create a new library file, start by compiling all the required modules.
5569 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5571 The next step is to add the .rel files to the library file:
5579 sdcclib libint.lib _divsint.rel
5582 \begin_inset LatexCommand \index{sdcclib}
5592 sdcclib libint.lib _divuint.rel
5598 sdcclib libint.lib _modsint.rel
5604 sdcclib libint.lib _moduint.rel
5610 sdcclib libint.lib _mulint.rel
5617 If the file already exists in the library, it will be replaced.
5618 To see what modules and symbols are included in the library, options -s
5619 and -m are available.
5627 sdcclib -s libint.lib
5630 \begin_inset LatexCommand \index{sdcclib}
5739 \added_space_bottom bigskip
5740 If the source files are compiled using -
5751 \begin_inset LatexCommand \index{-\/-debug}
5755 , the corresponding debug information file .adb will be include in the library
5757 The library files created with sdcclib are plain text files, so they can
5758 be viewed with a text editor.
5759 It is not recomended to modify a library file created with sdcclib using
5760 a text editor, as there are file indexes numbers located accross the file
5761 used by the linker to quickly locate the required module to link.
5762 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5763 it can be safely deleted, since all the information required for linking
5764 is embedded in the library file itself.
5765 Library files created using sdcclib are used as described in the preceding
5769 Command Line Options
5770 \begin_inset LatexCommand \index{Command Line Options}
5777 Processor Selection Options
5778 \begin_inset LatexCommand \index{Options processor selection}
5783 \begin_inset LatexCommand \index{Processor selection options}
5789 \labelwidthstring 00.00.0000
5794 \begin_inset LatexCommand \index{-mmcs51}
5800 Generate code for the Intel MCS51
5801 \begin_inset LatexCommand \index{MCS51}
5805 family of processors.
5806 This is the default processor target.
5808 \labelwidthstring 00.00.0000
5813 \begin_inset LatexCommand \index{-mds390}
5819 Generate code for the Dallas DS80C390
5820 \begin_inset LatexCommand \index{DS80C390}
5826 \labelwidthstring 00.00.0000
5831 \begin_inset LatexCommand \index{-mds400}
5837 Generate code for the Dallas DS80C400
5838 \begin_inset LatexCommand \index{DS80C400}
5844 \labelwidthstring 00.00.0000
5849 \begin_inset LatexCommand \index{-mhc08}
5855 Generate code for the Freescale/Motorola HC08
5856 \begin_inset LatexCommand \index{HC08}
5860 family of processors.
5862 \labelwidthstring 00.00.0000
5867 \begin_inset LatexCommand \index{-mz80}
5873 Generate code for the Zilog Z80
5874 \begin_inset LatexCommand \index{Z80}
5878 family of processors.
5880 \labelwidthstring 00.00.0000
5885 \begin_inset LatexCommand \index{-mgbz80}
5891 Generate code for the GameBoy Z80
5892 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5896 processor (Not actively maintained).
5898 \labelwidthstring 00.00.0000
5903 \begin_inset LatexCommand \index{-mavr}
5909 Generate code for the Atmel AVR
5910 \begin_inset LatexCommand \index{AVR}
5914 processor (Not maintained, not complete).
5915 AVR users should probably have a look at winavr
5916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5934 I think it is fair to direct users there for now.
5935 Open source is also about avoiding unnecessary work .
5936 But I didn't find the 'official' link.
5941 \labelwidthstring 00.00.0000
5946 \begin_inset LatexCommand \index{-mpic14}
5952 Generate code for the Microchip PIC 14
5953 \begin_inset LatexCommand \index{PIC14}
5957 -bit processors (p16f84 and variants.
5958 In development, not complete).
5967 p16f627 p16f628 p16f84 p16f873 p16f877?
5972 \labelwidthstring 00.00.0000
5977 \begin_inset LatexCommand \index{-mpic16}
5983 Generate code for the Microchip PIC 16
5984 \begin_inset LatexCommand \index{PIC16}
5988 -bit processors (p18f452 and variants.
5989 In development, not complete).
5991 \labelwidthstring 00.00.0000
5997 Generate code for the Toshiba TLCS-900H
5998 \begin_inset LatexCommand \index{TLCS-900H}
6002 processor (Not maintained, not complete).
6004 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6009 \begin_inset LatexCommand \index{-mxa51}
6015 Generate code for the Phillips XA51
6016 \begin_inset LatexCommand \index{XA51}
6020 processor (Not maintained, not complete).
6023 Preprocessor Options
6024 \begin_inset LatexCommand \index{Options preprocessor}
6029 \begin_inset LatexCommand \index{Preprocessor options}
6034 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6040 \labelwidthstring 00.00.0000
6045 \begin_inset LatexCommand \index{-I<path>}
6051 The additional location where the pre processor will look for <..h> or
6052 \begin_inset Quotes eld
6056 \begin_inset Quotes erd
6061 \labelwidthstring 00.00.0000
6066 \begin_inset LatexCommand \index{-D<macro[=value]>}
6072 Command line definition of macros.
6073 Passed to the preprocessor.
6075 \labelwidthstring 00.00.0000
6080 \begin_inset LatexCommand \index{-M}
6086 Tell the preprocessor to output a rule suitable for make describing the
6087 dependencies of each object file.
6088 For each source file, the preprocessor outputs one make-rule whose target
6089 is the object file name for that source file and whose dependencies are
6090 all the files `#include'd in it.
6091 This rule may be a single line or may be continued with `
6093 '-newline if it is long.
6094 The list of rules is printed on standard output instead of the preprocessed
6097 \begin_inset LatexCommand \index{-E}
6103 \labelwidthstring 00.00.0000
6108 \begin_inset LatexCommand \index{-C}
6114 Tell the preprocessor not to discard comments.
6115 Used with the `-E' option.
6117 \labelwidthstring 00.00.0000
6122 \begin_inset LatexCommand \index{-MM}
6133 Like `-M' but the output mentions only the user header files included with
6135 \begin_inset Quotes eld
6139 System header files included with `#include <file>' are omitted.
6141 \labelwidthstring 00.00.0000
6146 \begin_inset LatexCommand \index{-Aquestion(answer)}
6152 Assert the answer answer for question, in case it is tested with a preprocessor
6153 conditional such as `#if #question(answer)'.
6154 `-A-' disables the standard assertions that normally describe the target
6157 \labelwidthstring 00.00.0000
6162 \begin_inset LatexCommand \index{-Umacro}
6168 Undefine macro macro.
6169 `-U' options are evaluated after all `-D' options, but before any `-include'
6170 and `-imacros' options.
6172 \labelwidthstring 00.00.0000
6177 \begin_inset LatexCommand \index{-dM}
6183 Tell the preprocessor to output only a list of the macro definitions that
6184 are in effect at the end of preprocessing.
6185 Used with the `-E' option.
6187 \labelwidthstring 00.00.0000
6192 \begin_inset LatexCommand \index{-dD}
6198 Tell the preprocessor to pass all macro definitions into the output, in
6199 their proper sequence in the rest of the output.
6201 \labelwidthstring 00.00.0000
6206 \begin_inset LatexCommand \index{-dN}
6217 Like `-dD' except that the macro arguments and contents are omitted.
6218 Only `#define name' is included in the output.
6220 \labelwidthstring 00.00.0000
6224 -pedantic-parse-number
6225 \begin_inset LatexCommand \index{-pedantic-parse-number}
6236 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6237 and the macro LO_B(3) gets expanded.
6238 See also #pragma pedantic_parse_number in section
6239 \begin_inset LatexCommand \ref{sec:Pragmas}
6245 Note: this functionality is not in conformance with standard!
6247 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6252 preprocessorOption[,preprocessorOption]
6255 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6260 Pass the preprocessorOption to the preprocessor
6265 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6270 SDCC uses an adapted version of the preprocessor
6274 of the GNU Compiler Collection
6275 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6284 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6288 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6293 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6301 \begin_inset LatexCommand \index{Options linker}
6306 \begin_inset LatexCommand \index{Linker options}
6312 \labelwidthstring 00.00.0000
6332 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6337 \begin_inset LatexCommand \index{-L -\/-lib-path}
6344 <absolute path to additional libraries> This option is passed to the linkage
6345 editor's additional libraries
6346 \begin_inset LatexCommand \index{Libraries}
6351 The path name must be absolute.
6352 Additional library files may be specified in the command line.
6353 See section Compiling programs for more details.
6355 \labelwidthstring 00.00.0000
6372 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6377 <Value> The start location of the external ram
6378 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6382 , default value is 0.
6383 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6393 -xram-loc 0x8000 or -
6405 \labelwidthstring 00.00.0000
6422 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6427 <Value> The start location of the code
6428 \begin_inset LatexCommand \index{code}
6432 segment, default value 0.
6433 Note when this option is used the interrupt vector table
6434 \begin_inset LatexCommand \index{interrupt vector table}
6438 is also relocated to the given address.
6439 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6449 -code-loc 0x8000 or -
6461 \labelwidthstring 00.00.0000
6478 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6483 <Value> By default the stack
6484 \begin_inset LatexCommand \index{stack}
6488 is placed after the data segment.
6489 Using this option the stack can be placed anywhere in the internal memory
6491 The value entered can be in Hexadecimal or Decimal format, e.g.
6502 -stack-loc 0x20 or -
6513 Since the sp register is incremented before a push or call, the initial
6514 sp will be set to one byte prior the provided value.
6515 The provided value should not overlap any other memory areas such as used
6516 register banks or the data segment and with enough space for the current
6534 \begin_inset LatexCommand \index{-\/-pack-iram}
6538 option (which is now a default setting) will override this setting, so
6539 you should also specify the
6555 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6559 option if you need to manually place the stack.
6561 \labelwidthstring 00.00.0000
6578 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6583 <Value> By default the external stack
6584 \begin_inset LatexCommand \index{xstack}
6588 is placed after the pdata
6589 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6594 Using this option the xstack can be placed anywhere in the external memory
6596 The value entered can be in Hexadecimal or Decimal format, e.g.
6607 -xstack-loc 0x8000 or -
6618 The provided value should not overlap any other memory areas such as the
6619 pdata or xdata segment and with enough space for the current application.
6621 \labelwidthstring 00.00.0000
6638 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6643 <Value> The start location of the internal ram data
6644 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6649 The value entered can be in Hexadecimal or Decimal format, eg.
6671 (By default, the start location of the internal ram data segment is set
6672 as low as possible in memory, taking into account the used register banks
6673 and the bit segment at address 0x20.
6674 For example if register banks 0 and 1 are used without bit variables, the
6675 data segment will be set, if -
6685 -data-loc is not used, to location 0x10.)
6687 \labelwidthstring 00.00.0000
6704 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6709 <Value> The start location of the indirectly addressable internal ram
6710 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6714 of the 8051, default value is 0x80.
6715 The value entered can be in Hexadecimal or Decimal format, eg.
6726 -idata-loc 0x88 or -
6738 \labelwidthstring 00.00.0000
6755 <Value> The start location of the bit
6756 \begin_inset LatexCommand \index{bit}
6760 addressable internal ram of the 8051.
6766 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6769 \labelwidthstring 00.00.0000
6784 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6793 The linker output (final object code) is in Intel Hex format.
6794 \begin_inset LatexCommand \index{Intel hex format}
6798 This is the default option.
6799 The format itself is documented in the documentation of srecord
6800 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6806 \labelwidthstring 00.00.0000
6821 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6830 The linker output (final object code) is in Motorola S19 format
6831 \begin_inset LatexCommand \index{Motorola S19 format}
6836 The format itself is documented in the documentation of srecord.
6838 \labelwidthstring 00.00.0000
6853 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6858 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6867 The linker output (final object code) is in ELF format
6868 \begin_inset LatexCommand \index{ELF format}
6873 (Currently only supported for the HC08
6874 \begin_inset LatexCommand \index{HC08}
6880 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6885 linkOption[,linkOption]
6888 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6893 Pass the linkOption to the linker.
6894 If a bootloader is used an option like
6895 \begin_inset Quotes sld
6900 \begin_inset Quotes srd
6903 would be typical to set the start of the code segment.
6904 See also #pragma constseg and #pragma codeseg in section
6905 \begin_inset LatexCommand \ref{sec:Pragmas}
6910 File sdcc/as/doc/asxhtm.html has more on linker options.
6914 \begin_inset LatexCommand \index{Options MCS51}
6919 \begin_inset LatexCommand \index{MCS51 options}
6925 \labelwidthstring 00.00.0000
6940 \begin_inset LatexCommand \index{-\/-model-small}
6951 Generate code for Small Model programs, see section Memory Models for more
6953 This is the default model.
6955 \labelwidthstring 00.00.0000
6970 \begin_inset LatexCommand \index{-\/-model-medium}
6976 Generate code for Medium model programs, see section Memory Models for
6978 If this option is used all source files in the project have to be compiled
6980 It must also be used when invoking the linker.
6982 \labelwidthstring 00.00.0000
6997 \begin_inset LatexCommand \index{-\/-model-large}
7003 Generate code for Large model programs, see section Memory Models for more
7005 If this option is used all source files in the project have to be compiled
7007 It must also be used when invoking the linker.
7009 \labelwidthstring 00.00.0000
7024 \begin_inset LatexCommand \index{-\/-xstack}
7030 Uses a pseudo stack in the pdata
7031 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7035 area (usually the first 256 bytes in the external ram) for allocating variables
7036 and passing parameters.
7038 \begin_inset LatexCommand \ref{sub:External-Stack}
7043 External Stack for more details.
7045 \labelwidthstring 00.00.0000
7063 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7067 Causes the linker to check if the internal ram usage is within limits of
7070 \labelwidthstring 00.00.0000
7088 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7092 Causes the linker to check if the external ram usage is within limits of
7095 \labelwidthstring 00.00.0000
7113 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7117 Causes the linker to check if the code memory usage is within limits of
7120 \labelwidthstring 00.00.0000
7138 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7142 Causes the linker to check if there is at minimum <Value> bytes for stack.
7144 \labelwidthstring 00.00.0000
7162 \begin_inset LatexCommand \index{-\/-pack-iram}
7166 Causes the linker to use unused register banks for data variables and pack
7167 data, idata and stack together.
7168 This is the default now.
7170 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7188 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7192 Causes the linker to use old style for allocating memory areas.
7195 DS390 / DS400 Options
7196 \begin_inset LatexCommand \index{Options DS390}
7201 \begin_inset LatexCommand \index{DS390}
7207 \labelwidthstring 00.00.0000
7224 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7234 Generate 24-bit flat mode code.
7235 This is the one and only that the ds390 code generator supports right now
7236 and is default when using
7241 See section Memory Models for more details.
7243 \labelwidthstring 00.00.0000
7258 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7264 disable interrupts during ESP:SP updates.
7266 \labelwidthstring 00.00.0000
7283 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7287 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7288 This is the one and only that the ds390 code generator supports right now
7289 and is default when using
7294 In this mode, the stack is located in the lower 1K of the internal RAM,
7295 which is mapped to 0x400000.
7296 Note that the support is incomplete, since it still uses a single byte
7297 as the stack pointer.
7298 This means that only the lower 256 bytes of the potential 1K stack space
7299 will actually be used.
7300 However, this does allow you to reclaim the precious 256 bytes of low RAM
7301 for use for the DATA and IDATA segments.
7302 The compiler will not generate any code to put the processor into 10 bit
7304 It is important to ensure that the processor is in this mode before calling
7305 any re-entrant functions compiled with this option.
7306 In principle, this should work with the
7319 \begin_inset LatexCommand \index{-\/-stack-auto}
7325 option, but that has not been tested.
7326 It is incompatible with the
7339 \begin_inset LatexCommand \index{-\/-xstack}
7346 It also only makes sense if the processor is in 24 bit contiguous addressing
7359 -model-flat24 option
7363 \labelwidthstring 00.00.0000
7378 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7384 insert call to function __stack_probe at each function prologue.
7386 \labelwidthstring 00.00.0000
7401 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7407 <nnnn> LibraryID used in -mTININative.
7410 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7425 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7431 generate code for DS390 Arithmetic Accelerator.
7436 \begin_inset LatexCommand \index{Options Z80}
7441 \begin_inset LatexCommand \index{Z80}
7447 \labelwidthstring 00.00.0000
7464 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7474 Force a called function to always save BC.
7476 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7493 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7497 When linking, skip the standard crt0.o object file.
7498 You must provide your own crt0.o for your system when linking.
7502 Optimization Options
7503 \begin_inset LatexCommand \index{Options optimization}
7508 \begin_inset LatexCommand \index{Optimization options}
7514 \labelwidthstring 00.00.0000
7529 \begin_inset LatexCommand \index{-\/-nogcse}
7535 Will not do global subexpression elimination, this option may be used when
7536 the compiler creates undesirably large stack/data spaces to store compiler
7546 \begin_inset LatexCommand \index{sloc (spill location)}
7551 A warning message will be generated when this happens and the compiler
7552 will indicate the number of extra bytes it allocated.
7553 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7555 \begin_inset LatexCommand \index{\#pragma nogcse}
7559 can be used to turn off global subexpression elimination
7560 \begin_inset LatexCommand \index{Subexpression elimination}
7564 for a given function only.
7566 \labelwidthstring 00.00.0000
7581 \begin_inset LatexCommand \index{-\/-noinvariant}
7587 Will not do loop invariant optimizations, this may be turned off for reasons
7588 explained for the previous option.
7589 For more details of loop optimizations performed see Loop Invariants in
7591 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7596 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7598 \begin_inset LatexCommand \index{\#pragma noinvariant}
7602 can be used to turn off invariant optimizations for a given function only.
7604 \labelwidthstring 00.00.0000
7619 \begin_inset LatexCommand \index{-\/-noinduction}
7625 Will not do loop induction optimizations, see section strength reduction
7627 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7629 \begin_inset LatexCommand \index{\#pragma noinduction}
7633 can be used to turn off induction optimizations for a given function only.
7635 \labelwidthstring 00.00.0000
7650 \begin_inset LatexCommand \index{-\/-nojtbound}
7661 Will not generate boundary condition check when switch statements
7662 \begin_inset LatexCommand \index{switch statement}
7666 are implemented using jump-tables.
7668 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7673 Switch Statements for more details.
7674 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7676 \begin_inset LatexCommand \index{\#pragma nojtbound}
7680 can be used to turn off boundary checking for jump tables for a given function
7683 \labelwidthstring 00.00.0000
7698 \begin_inset LatexCommand \index{-\/-noloopreverse}
7707 Will not do loop reversal
7708 \begin_inset LatexCommand \index{Loop reversing}
7714 \labelwidthstring 00.00.0000
7731 \begin_inset LatexCommand \index{-\/-nolabelopt }
7735 Will not optimize labels (makes the dumpfiles more readable).
7737 \labelwidthstring 00.00.0000
7752 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7758 Will not memcpy initialized data from code space into xdata space.
7759 This saves a few bytes in code space if you don't have initialized data
7760 \begin_inset LatexCommand \index{Variable initialization}
7766 \labelwidthstring 00.00.0000
7781 \begin_inset LatexCommand \index{-\/-nooverlay}
7787 The compiler will not overlay parameters and local variables of any function,
7788 see section Parameters and local variables for more details.
7790 \labelwidthstring 00.00.0000
7805 \begin_inset LatexCommand \index{-\/-no-peep}
7811 Disable peep-hole optimization with built-in rules.
7813 \labelwidthstring 00.00.0000
7830 \begin_inset LatexCommand \index{-\/-peep-file}
7835 <filename> This option can be used to use additional rules to be used by
7836 the peep hole optimizer.
7838 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7843 Peep Hole optimizations for details on how to write these rules.
7845 \labelwidthstring 00.00.0000
7860 \begin_inset LatexCommand \index{-\/-peep-asm}
7866 Pass the inline assembler code through the peep hole optimizer.
7867 This can cause unexpected changes to inline assembler code, please go through
7868 the peephole optimizer
7869 \begin_inset LatexCommand \index{Peephole optimizer}
7873 rules defined in the source file tree '<target>/peeph.def' before using
7876 \labelwidthstring 00.00.0000
7891 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7897 The compiler will optimize code generation towards fast code, possibly
7898 at the expense of code size.
7900 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7915 \begin_inset LatexCommand \index{-\/-opt-code-size}
7921 The compiler will optimize code generation towards compact code, possibly
7922 at the expense of code speed.
7926 \begin_inset LatexCommand \index{Options other}
7932 \labelwidthstring 00.00.0000
7948 \begin_inset LatexCommand \index{-\/-compile-only}
7953 \begin_inset LatexCommand \index{-c -\/-compile-only}
7959 will compile and assemble the source, but will not call the linkage editor.
7961 \labelwidthstring 00.00.0000
7980 \begin_inset LatexCommand \index{-\/-c1mode}
7986 reads the preprocessed source from standard input and compiles it.
7987 The file name for the assembler output must be specified using the -o option.
7989 \labelwidthstring 00.00.0000
7994 \begin_inset LatexCommand \index{-E}
8000 Run only the C preprocessor.
8001 Preprocess all the C source files specified and output the results to standard
8004 \labelwidthstring 00.00.0000
8010 \begin_inset LatexCommand \index{-o <path/file>}
8016 The output path resp.
8017 file where everything will be placed.
8018 If the parameter is a path, it must have a trailing slash (or backslash
8019 for the Windows binaries) to be recognized as a path.
8022 \labelwidthstring 00.00.0000
8037 \begin_inset LatexCommand \index{-\/-stack-auto}
8048 All functions in the source file will be compiled as
8053 \begin_inset LatexCommand \index{reentrant}
8058 the parameters and local variables will be allocated on the stack
8059 \begin_inset LatexCommand \index{stack}
8065 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8069 Parameters and Local Variables for more details.
8070 If this option is used all source files in the project should be compiled
8072 It automatically implies --int-long-reent and --float-reent.
8075 \labelwidthstring 00.00.0000
8090 \begin_inset LatexCommand \index{-\/-callee-saves}
8094 function1[,function2][,function3]....
8097 The compiler by default uses a caller saves convention for register saving
8098 across function calls, however this can cause unnecessary register pushing
8099 & popping when calling small functions from larger functions.
8100 This option can be used to switch the register saving convention for the
8101 function names specified.
8102 The compiler will not save registers when calling these functions, no extra
8103 code will be generated at the entry & exit (function prologue
8106 \begin_inset LatexCommand \index{function prologue}
8115 \begin_inset LatexCommand \index{function epilogue}
8121 ) for these functions to save & restore the registers used by these functions,
8122 this can SUBSTANTIALLY reduce code & improve run time performance of the
8124 In the future the compiler (with inter procedural analysis) will be able
8125 to determine the appropriate scheme to use for each function call.
8126 DO NOT use this option for built-in functions such as _mulint..., if this
8127 option is used for a library function the appropriate library function
8128 needs to be recompiled with the same option.
8129 If the project consists of multiple source files then all the source file
8130 should be compiled with the same -
8140 -callee-saves option string.
8141 Also see #pragma\SpecialChar ~
8143 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8149 \labelwidthstring 00.00.0000
8164 \begin_inset LatexCommand \index{-\/-debug}
8173 When this option is used the compiler will generate debug information.
8174 The debug information collected in a file with .cdb extension can be used
8176 For more information see documentation for SDCDB.
8177 Another file with no extension contains debug information in AOMF or AOMF51
8178 \begin_inset LatexCommand \index{AOMF, AOMF51}
8182 format which is commonly used by third party tools.
8184 \labelwidthstring 00.00.0000
8189 \begin_inset LatexCommand \index{-S}
8200 Stop after the stage of compilation proper; do not assemble.
8201 The output is an assembler code file for the input file specified.
8203 \labelwidthstring 00.00.0000
8218 \begin_inset LatexCommand \index{-\/-int-long-reent}
8224 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8225 Note by default these libraries are compiled as non-reentrant.
8226 See section Installation for more details.
8228 \labelwidthstring 00.00.0000
8243 \begin_inset LatexCommand \index{-\/-cyclomatic}
8252 This option will cause the compiler to generate an information message for
8253 each function in the source file.
8254 The message contains some
8258 information about the function.
8259 The number of edges and nodes the compiler detected in the control flow
8260 graph of the function, and most importantly the
8262 cyclomatic complexity
8263 \begin_inset LatexCommand \index{Cyclomatic complexity}
8269 see section on Cyclomatic Complexity for more details.
8271 \labelwidthstring 00.00.0000
8286 \begin_inset LatexCommand \index{-\/-float-reent}
8292 Floating point library is compiled as reentrant
8293 \begin_inset LatexCommand \index{reentrant}
8298 See section Installation for more details.
8300 \labelwidthstring 00.00.0000
8315 \begin_inset LatexCommand \index{-\/-funsigned-char}
8321 The default signedness for every type is
8326 In some embedded environments the default signedness of
8335 To set the signess for characters to unsigned, use the option --funsigned-char.
8336 If this option is set and no signedness keyword (unsigned/signed) is given,
8337 a char will be signed.
8338 All other types are unaffected.
8340 \labelwidthstring 00.00.0000
8355 \begin_inset LatexCommand \index{-\/-main-return}
8361 This option can be used if the code generated is called by a monitor program
8362 or if the main routine includes an endless loop.
8363 This option results in slightly smaller code and saves two bytes of stack
8365 The return from the 'main'
8366 \begin_inset LatexCommand \index{main return}
8370 function will return to the function calling main.
8371 The default setting is to lock up i.e.
8378 \labelwidthstring 00.00.0000
8393 \begin_inset LatexCommand \index{-\/-nostdinc}
8399 This will prevent the compiler from passing on the default include path
8400 to the preprocessor.
8402 \labelwidthstring 00.00.0000
8417 \begin_inset LatexCommand \index{-\/-nostdlib}
8423 This will prevent the compiler from passing on the default library
8424 \begin_inset LatexCommand \index{Libraries}
8430 \labelwidthstring 00.00.0000
8445 \begin_inset LatexCommand \index{-\/-verbose}
8451 Shows the various actions the compiler is performing.
8453 \labelwidthstring 00.00.0000
8458 \begin_inset LatexCommand \index{-V}
8464 Shows the actual commands the compiler is executing.
8466 \labelwidthstring 00.00.0000
8481 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8487 Hides your ugly and inefficient c-code from the asm file, so you can always
8488 blame the compiler :)
8490 \labelwidthstring 00.00.0000
8505 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8511 Will not include peep-hole comments in the generated files.
8513 \labelwidthstring 00.00.0000
8528 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8534 Include i-codes in the asm file.
8535 Sounds like noise but is most helpful for debugging the compiler itself.
8537 \labelwidthstring 00.00.0000
8552 \begin_inset LatexCommand \index{-\/-less-pedantic}
8558 Disable some of the more pedantic warnings
8559 \begin_inset LatexCommand \index{Warnings}
8563 (jwk burps: please be more specific here, please!).
8565 \labelwidthstring 00.00.0000
8579 -disable-warning\SpecialChar ~
8581 \begin_inset LatexCommand \index{-\/-disable-warning}
8587 Disable specific warning with number <nnnn>.
8589 \labelwidthstring 00.00.0000
8604 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8610 Display the directories in the compiler's search path
8612 \labelwidthstring 00.00.0000
8627 \begin_inset LatexCommand \index{-\/-vc}
8633 Display errors and warnings using MSVC style, so you can use SDCC with
8634 the visual studio IDE
8635 \begin_inset LatexCommand \index{IDE}
8640 With SDCC both offering a GCC-like (the default) and a MSVC-like
8641 \begin_inset LatexCommand \index{MSVC output style}
8645 output style, integration into most programming editors should be straightforwa
8648 \labelwidthstring 00.00.0000
8663 \begin_inset LatexCommand \index{-\/-use-stdout}
8669 Send errors and warnings to stdout instead of stderr.
8671 \labelwidthstring 00.00.0000
8676 asmOption[,asmOption]
8679 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8684 Pass the asmOption to the assembler
8685 \begin_inset LatexCommand \index{Options assembler}
8690 \begin_inset LatexCommand \index{Assembler options}
8695 See file sdcc/as/doc/asxhtm.html for assembler options.cd
8697 \labelwidthstring 00.00.0000
8712 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8718 Generally follow the C89 standard, but allow SDCC features that conflict
8719 with the standard (default).
8721 \labelwidthstring 00.00.0000
8736 \begin_inset LatexCommand \index{-\/-std-c89}
8742 Follow the C89 standard and disable SDCC features that conflict with the
8745 \labelwidthstring 00.00.0000
8760 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8766 Generally follow the C99 standard, but allow SDCC features that conflict
8767 with the standard (incomplete support).
8769 \labelwidthstring 00.00.0000
8784 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8790 Follow the C99 standard and disable SDCC features that conflict with the
8791 standard (incomplete support).
8793 \labelwidthstring 00.00.0000
8810 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8815 <Name> The name to be used for the code
8816 \begin_inset LatexCommand \index{code}
8820 segment, default CSEG.
8821 This is useful if you need to tell the compiler to put the code in a special
8822 segment so you can later on tell the linker to put this segment in a special
8824 Can be used for instance when using bank switching to put the code in a
8827 \labelwidthstring 00.00.0000
8844 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8849 <Name> The name to be used for the const
8850 \begin_inset LatexCommand \index{code}
8854 segment, default CONST.
8855 This is useful if you need to tell the compiler to put the const data in
8856 a special segment so you can later on tell the linker to put this segment
8857 in a special place in memory.
8858 Can be used for instance when using bank switching to put the const data
8861 \labelwidthstring 00.00.0000
8875 -fdollars-in-identifiers
8876 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
8882 Permit '$' as an identifier character
8884 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8896 a SDCC compiler option but if you want
8900 warnings you can use a separate tool dedicated to syntax checking like
8902 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8907 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8912 \begin_inset LatexCommand \url{http://www.splint.org}
8917 To make your source files parseable by splint you will have to include
8923 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8927 in your source file and add brackets around extended keywords (like
8930 \begin_inset Quotes sld
8943 \begin_inset Quotes srd
8951 \begin_inset Quotes sld
8954 __interrupt\SpecialChar ~
8956 \begin_inset Quotes srd
8964 Splint has an excellent on line manual at
8965 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8969 and it's capabilities go beyond pure syntax checking.
8970 You'll need to tell splint the location of SDCC's include files so a typical
8971 command line could look like this:
8975 splint\SpecialChar ~
8977 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8982 Intermediate Dump Options
8983 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8988 \begin_inset LatexCommand \index{Options intermediate dump}
8993 \begin_inset LatexCommand \index{Intermediate dump options}
9000 The following options are provided for the purpose of retargetting and debugging
9002 They provide a means to dump the intermediate code (iCode
9003 \begin_inset LatexCommand \index{iCode}
9007 ) generated by the compiler in human readable form at various stages of
9008 the compilation process.
9009 More on iCodes see chapter
9010 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9015 \begin_inset Quotes srd
9018 The anatomy of the compiler
9019 \begin_inset Quotes srd
9024 \labelwidthstring 00.00.0000
9039 \begin_inset LatexCommand \index{-\/-dumpraw}
9045 This option will cause the compiler to dump the intermediate code into
9048 <source filename>.dumpraw
9050 just after the intermediate code has been generated for a function, i.e.
9051 before any optimizations are done.
9053 \begin_inset LatexCommand \index{Basic blocks}
9057 at this stage ordered in the depth first number, so they may not be in
9058 sequence of execution.
9060 \labelwidthstring 00.00.0000
9075 \begin_inset LatexCommand \index{-\/-dumpgcse}
9081 Will create a dump of iCode's, after global subexpression elimination
9082 \begin_inset LatexCommand \index{Global subexpression elimination}
9088 <source filename>.dumpgcse.
9090 \labelwidthstring 00.00.0000
9105 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9111 Will create a dump of iCode's, after deadcode elimination
9112 \begin_inset LatexCommand \index{Dead-code elimination}
9118 <source filename>.dumpdeadcode.
9120 \labelwidthstring 00.00.0000
9135 \begin_inset LatexCommand \index{-\/-dumploop}
9144 Will create a dump of iCode's, after loop optimizations
9145 \begin_inset LatexCommand \index{Loop optimization}
9151 <source filename>.dumploop.
9153 \labelwidthstring 00.00.0000
9168 \begin_inset LatexCommand \index{-\/-dumprange}
9177 Will create a dump of iCode's, after live range analysis
9178 \begin_inset LatexCommand \index{Live range analysis}
9184 <source filename>.dumprange.
9186 \labelwidthstring 00.00.0000
9201 \begin_inset LatexCommand \index{-\/-dumlrange}
9207 Will dump the life ranges
9208 \begin_inset LatexCommand \index{Live range analysis}
9214 \labelwidthstring 00.00.0000
9229 \begin_inset LatexCommand \index{-\/-dumpregassign}
9238 Will create a dump of iCode's, after register assignment
9239 \begin_inset LatexCommand \index{Register assignment}
9245 <source filename>.dumprassgn.
9247 \labelwidthstring 00.00.0000
9262 \begin_inset LatexCommand \index{-\/-dumplrange}
9268 Will create a dump of the live ranges of iTemp's
9270 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9285 \begin_inset LatexCommand \index{-\/-dumpall}
9296 Will cause all the above mentioned dumps to be created.
9299 Redirecting output on Windows Shells
9301 \added_space_bottom bigskip
9302 By default SDCC writes it's error messages to
9303 \begin_inset Quotes sld
9307 \begin_inset Quotes srd
9311 To force all messages to
9312 \begin_inset Quotes sld
9316 \begin_inset Quotes srd
9340 \begin_inset LatexCommand \index{-\/-use-stdout}
9345 Additionally, if you happen to have visual studio installed in your windows
9346 machine, you can use it to compile your sources using a custom build and
9362 \begin_inset LatexCommand \index{-\/-vc}
9367 Something like this should work:
9411 -model-large -c $(InputPath)
9414 Environment variables
9415 \begin_inset LatexCommand \index{Environment variables}
9422 SDCC recognizes the following environment variables:
9424 \labelwidthstring 00.00.0000
9429 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9435 SDCC installs a signal handler
9436 \begin_inset LatexCommand \index{signal handler}
9440 to be able to delete temporary files after an user break (^C) or an exception.
9441 If this environment variable is set, SDCC won't install the signal handler
9442 in order to be able to debug SDCC.
9444 \labelwidthstring 00.00.0000
9451 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9457 Path, where temporary files will be created.
9458 The order of the variables is the search order.
9459 In a standard *nix environment these variables are not set, and there's
9460 no need to set them.
9461 On Windows it's recommended to set one of them.
9463 \labelwidthstring 00.00.0000
9468 \begin_inset LatexCommand \index{SDCC\_HOME}
9475 \begin_inset LatexCommand \ref{sub:Install-paths}
9481 \begin_inset Quotes sld
9485 \begin_inset Quotes srd
9490 \labelwidthstring 00.00.0000
9495 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9502 \begin_inset LatexCommand \ref{sub:Search-Paths}
9508 \begin_inset Quotes sld
9512 \begin_inset Quotes srd
9517 \labelwidthstring 00.00.0000
9522 \begin_inset LatexCommand \index{SDCC\_LIB}
9529 \begin_inset LatexCommand \ref{sub:Search-Paths}
9535 \begin_inset Quotes sld
9539 \begin_inset Quotes srd
9544 \added_space_bottom bigskip
9545 There are some more environment variables recognized by SDCC, but these
9546 are solely used for debugging purposes.
9547 They can change or disappear very quickly, and will never be documented.
9550 Storage Class Language Extensions
9553 MCS51/DS390 Storage Class
9554 \begin_inset LatexCommand \index{Storage class}
9561 In addition to the ANSI storage classes SDCC allows the following MCS51
9562 specific storage classes:
9563 \layout Subsubsection
9566 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9571 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9576 \begin_inset LatexCommand \index{near (storage class)}
9581 \begin_inset LatexCommand \index{\_\_near (storage class)}
9592 storage class for the Small Memory model (
9600 or the more ANSI-C compliant forms
9608 can be used synonymously).
9609 Variables declared with this storage class will be allocated in the directly
9610 addressable portion of the internal RAM of a 8051, e.g.:
9615 __data unsigned char test_data;
9618 Writing 0x01 to this variable generates the assembly code:
9623 75*00 01\SpecialChar ~
9629 \layout Subsubsection
9632 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9637 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9642 \begin_inset LatexCommand \index{far (storage class)}
9647 \begin_inset LatexCommand \index{\_\_far (storage class)}
9654 Variables declared with this storage class will be placed in the external
9660 storage class for the Large Memory model, e.g.:
9665 __xdata unsigned char test_xdata;
9668 Writing 0x01 to this variable generates the assembly code:
9673 90s00r00\SpecialChar ~
9702 \layout Subsubsection
9705 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9710 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9717 Variables declared with this storage class will be allocated into the indirectly
9718 addressable portion of the internal ram of a 8051, e.g.:
9723 __idata unsigned char test_idata;
9726 Writing 0x01 to this variable generates the assembly code:
9755 Please note, the first 128 byte of idata physically access the same RAM
9757 The original 8051 had 128 byte idata memory, nowadays most devices have
9758 256 byte idata memory.
9760 \begin_inset LatexCommand \index{stack}
9764 is located in idata memory.
9765 \layout Subsubsection
9768 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9773 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9780 Paged xdata access is just as straightforward as using the other addressing
9782 It is typically located at the start of xdata and has a maximum size of
9784 The following example writes 0x01 to the pdata variable.
9785 Please note, pdata access physically accesses xdata memory.
9786 The high byte of the address is determined by port P2
9787 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9791 (or in case of some 8051 variants by a separate Special Function Register,
9793 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9802 storage class for the Medium Memory model, e.g.:
9807 __pdata unsigned char test_pdata;
9810 Writing 0x01 to this variable generates the assembly code:
9854 \begin_inset LatexCommand \index{-\/-xstack}
9858 option is used the pdata memory area is followed by the xstack memory area
9859 and the sum of their sizes is limited to 256 bytes.
9860 \layout Subsubsection
9863 \begin_inset LatexCommand \index{code}
9868 \begin_inset LatexCommand \index{\_\_code}
9875 'Variables' declared with this storage class will be placed in the code
9881 __code unsigned char test_code;
9884 Read access to this variable generates the assembly code:
9889 90s00r6F\SpecialChar ~
9892 mov dptr,#_test_code
9921 indexed arrays of characters in code memory can be accessed efficiently:
9926 __code char test_array[] = {'c','h','e','a','p'};
9929 Read access to this array using an 8-bit unsigned index generates the assembly
9946 90s00r41\SpecialChar ~
9949 mov dptr,#_test_array
9964 \layout Subsubsection
9967 \begin_inset LatexCommand \index{bit}
9972 \begin_inset LatexCommand \index{\_\_bit}
9979 This is a data-type and a storage class specifier.
9980 When a variable is declared as a bit, it is allocated into the bit addressable
9981 memory of 8051, e.g.:
9989 Writing 1 to this variable generates the assembly code:
10005 The bit addressable memory consists of 128 bits which are located from 0x20
10006 to 0x2f in data memory.
10009 Apart from this 8051 specific storage class most architectures support ANSI-C
10011 \begin_inset LatexCommand \index{bitfields}
10021 Not really meant as examples, but nevertheless showing what bitfields are
10022 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10026 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10027 signed modifier are implemented as unsigned.
10028 \layout Subsubsection
10031 \begin_inset LatexCommand \index{sfr}
10036 \begin_inset LatexCommand \index{\_\_sfr}
10041 \begin_inset LatexCommand \index{sfr16}
10046 \begin_inset LatexCommand \index{\_\_sfr16}
10051 \begin_inset LatexCommand \index{sfr32}
10056 \begin_inset LatexCommand \index{\_\_sfr32}
10061 \begin_inset LatexCommand \index{\_\_sbit}
10066 \begin_inset LatexCommand \index{sbit}
10073 Like the bit keyword,
10075 sfr / sfr16 / sfr32 / sbit
10077 signify both a data-type and storage class, they are used to describe the
10098 variables of a 8051, eg:
10104 \begin_inset LatexCommand \index{at}
10109 \begin_inset LatexCommand \index{\_\_at}
10113 (0x80) P0;\SpecialChar ~
10114 /* special function register P0 at location 0x80 */
10118 /* 16 bit special function register combination for timer 0
10122 with the high byte at location 0x8C and the low byte at location 0x8A */
10124 __sfr16 __at (0x8C8A) TMR0;
10129 \begin_inset LatexCommand \index{at}
10134 \begin_inset LatexCommand \index{\_\_at}
10138 (0xd7) CY;\SpecialChar ~
10140 \begin_inset LatexCommand \index{Flags}
10145 \begin_inset LatexCommand \index{Carry flag}
10152 Special function registers which are located on an address dividable by
10153 8 are bit-addressable, an
10157 addresses a specific bit within these sfr.
10159 16 Bit and 32 bit special function register combinations which require a
10160 certain access order are better not declared using
10169 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10170 this is not guaranteed.
10175 Please note, if you use a header file which was written for another compiler
10176 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10182 Specifically the syntax
10185 sfr P0 = 0x80;\SpecialChar ~
10192 by SDCC to an assignment of 0x80 to a variable called P0
10195 \begin_inset Marginal
10209 Nevertheless it is possible to write header files
10210 \begin_inset LatexCommand \index{Header files}
10215 \begin_inset LatexCommand \index{Include files}
10219 which can be shared among different compilers (see section
10220 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10226 \layout Subsubsection
10229 \begin_inset LatexCommand \index{Pointer}
10233 to MCS51/DS390 specific memory spaces
10236 SDCC allows (via language extensions) pointers to explicitly point to any
10237 of the memory spaces
10238 \begin_inset LatexCommand \index{Memory model}
10243 In addition to the explicit pointers, the compiler uses (by default) generic
10244 pointers which can be used to point to any of the memory spaces.
10248 Pointer declaration examples:
10253 /* pointer physically in internal ram pointing to object in external ram
10256 __xdata unsigned char * __data p;
10260 /* pointer physically in external ram pointing to object in internal ram
10263 __data unsigned char * __xdata p;
10267 /* pointer physically in code rom pointing to data in xdata space */
10269 __xdata unsigned char * __code p;
10273 /* pointer physically in code space pointing to data in code space */
10275 __code unsigned char * __code p;
10279 /* generic pointer physically located in xdata space */
10281 unsigned char * __xdata p;
10285 /* generic pointer physically located in default memory space */
10291 /* the following is a function pointer
10292 \begin_inset LatexCommand \index{function pointer}
10296 physically located in data space */
10298 char (* __data fp)(void);
10301 Well you get the idea.
10306 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10319 The highest order byte of the
10323 pointers contains the data space information.
10324 Assembler support routines are called whenever data is stored or retrieved
10330 These are useful for developing reusable library
10331 \begin_inset LatexCommand \index{Libraries}
10336 Explicitly specifying the pointer
10337 \begin_inset LatexCommand \index{pointer}
10341 type will generate the most efficient code.
10342 \layout Subsubsection
10344 Notes on MCS51 memory
10345 \begin_inset LatexCommand \index{MCS51 memory}
10352 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10353 RAM memory which is structured as follows:
10357 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10360 - Bytes 20-2F - 16 bytes to hold 128 bit
10361 \begin_inset LatexCommand \index{bit}
10367 - Bytes 30-7F - 80 bytes for general purpose use.
10372 Additionally some members of the MCS51 family may have up to 128 bytes of
10373 additional, indirectly addressable, internal RAM memory (
10378 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10383 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10388 Furthermore, some chips may have some built in external memory (
10393 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10398 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10402 ) which should not be confused with the internal, directly addressable RAM
10408 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10413 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10418 Sometimes this built in
10422 memory has to be activated before using it (you can probably find this
10423 information on the datasheet of the microcontroller your are using, see
10425 \begin_inset LatexCommand \ref{sub:Startup-Code}
10433 Normally SDCC will only use the first bank
10434 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10438 of registers (register bank 0), but it is possible to specify that other
10439 banks of registers (keyword
10446 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10451 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10457 ) should be used in interrupt
10458 \begin_inset LatexCommand \index{interrupt}
10463 \begin_inset LatexCommand \index{\_\_interrupt}
10468 By default, the compiler will place the stack after the last byte of allocated
10469 memory for variables.
10470 For example, if the first 2 banks of registers are used, and only four
10475 variables, it will position the base of the internal stack at address 20
10477 This implies that as the stack
10478 \begin_inset LatexCommand \index{stack}
10482 grows, it will use up the remaining register banks, and the 16 bytes used
10483 by the 128 bit variables, and 80 bytes for general purpose use.
10484 If any bit variables are used, the data variables will be placed in unused
10485 register banks and after the byte holding the last bit variable.
10486 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10491 variables will be placed starting from address 0x10 to 0x20 and continue
10504 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10508 to specify the start address of the
10523 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10527 to specify the size of the total internal RAM (
10541 By default the 8051 linker will place the stack after the last byte of (i)data
10554 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10558 allows you to specify the start of the stack, i.e.
10559 you could start it after any data in the general purpose area.
10560 If your microcontroller has additional indirectly addressable internal
10565 ) you can place the stack on it.
10566 You may also need to use -
10577 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10581 to set the start address of the external RAM (
10596 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10600 to specify its size.
10601 Same goes for the code memory, using -
10612 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10627 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10632 If in doubt, don't specify any options and see if the resulting memory
10633 layout is appropriate, then you can adjust it.
10635 \added_space_bottom bigskip
10636 The linker generates two files with memory allocation information.
10637 The first, with extension .map
10638 \begin_inset LatexCommand \index{<file>.map}
10642 shows all the variables and segments.
10643 The second with extension .mem
10644 \begin_inset LatexCommand \index{<file>.mem}
10648 shows the final memory layout.
10649 The linker will complain either if memory segments overlap, there is not
10650 enough memory, or there is not enough space for stack.
10651 If you get any linking warnings and/or errors related to stack or segments
10652 allocation, take a look at either the .map or .mem files to find out what
10654 The .mem file may even suggest a solution to the problem.
10657 Z80/Z180 Storage Class
10658 \begin_inset LatexCommand \index{Z80!Storage class}
10662 Language Extensions
10663 \layout Subsubsection
10666 \begin_inset LatexCommand \index{sfr}
10671 \begin_inset LatexCommand \index{\_\_sfr}
10675 (in/out to 8-bit addresses)
10679 \begin_inset LatexCommand \index{Z80}
10683 family has separate address spaces for memory and
10693 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10698 \begin_inset LatexCommand \index{Z80!I/O memory}
10703 \begin_inset LatexCommand \index{Z180!I/O memory}
10707 is accessed with special instructions, e.g.:
10712 sfr at 0x78 IoPort;\SpecialChar ~
10714 /* define a var in I/O space at 78h called IoPort */
10718 Writing 0x01 to this variable generates the assembly code:
10723 3E 01\SpecialChar ~
10731 D3 78\SpecialChar ~
10738 \layout Subsubsection
10741 \begin_inset LatexCommand \index{sfr}
10746 \begin_inset LatexCommand \index{\_\_sfr}
10750 (in/out to 16-bit addresses)
10757 is used to support 16 bit addresses in I/O memory e.g.:
10763 \begin_inset LatexCommand \index{at}
10768 \begin_inset LatexCommand \index{\_\_at}
10775 Writing 0x01 to this variable generates the assembly code:
10780 01 23 01\SpecialChar ~
10785 3E 01\SpecialChar ~
10793 ED 79\SpecialChar ~
10800 \layout Subsubsection
10803 \begin_inset LatexCommand \index{sfr}
10808 \begin_inset LatexCommand \index{\_\_sfr}
10812 (in0/out0 to 8 bit addresses on Z180
10813 \begin_inset LatexCommand \index{Z180}
10818 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10824 \added_space_bottom bigskip
10825 The compiler option -
10836 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10840 =180 (80) and a compiler #pragma\SpecialChar ~
10842 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10846 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10856 If you include the file z180.h this will be set automatically.
10860 \begin_inset LatexCommand \index{HC08!Storage class}
10864 Language Extensions
10865 \layout Subsubsection
10868 \begin_inset LatexCommand \index{data (hc08 storage class)}
10873 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10880 The data storage class declares a variable that resides in the first 256
10881 bytes of memory (the direct page).
10883 \begin_inset LatexCommand \index{HC08}
10887 is most efficient at accessing variables (especially pointers) stored here.
10888 \layout Subsubsection
10891 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10896 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10902 \added_space_bottom bigskip
10903 The xdata storage class declares a variable that can reside anywhere in
10905 This is the default if no storage class is specified.
10909 Absolute Addressing
10910 \begin_inset LatexCommand \index{Absolute addressing}
10917 Data items can be assigned an absolute address with the
10920 \begin_inset LatexCommand \index{at}
10925 \begin_inset LatexCommand \index{\_\_at}
10931 keyword, in addition to a storage class, e.g.:
10937 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10942 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10947 \begin_inset LatexCommand \index{at}
10952 \begin_inset LatexCommand \index{\_\_at}
10956 0x7ffe unsigned int chksum;
10959 or, better conforming to ISO/IEC 9899 C:
10964 __xdata __at (0x7ffe) unsigned int chksum;
10967 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10968 of the external ram.
10973 reserve any space for variables declared in this way
10974 \begin_inset Marginal
10985 (they are implemented with an equate in the assembler).
10986 Thus it is left to the programmer to make sure there are no overlaps with
10987 other variables that are declared without the absolute address.
10988 The assembler listing file (.lst
10989 \begin_inset LatexCommand \index{<file>.lst}
10993 ) and the linker output files (.rst
10994 \begin_inset LatexCommand \index{<file>.rst}
10999 \begin_inset LatexCommand \index{<file>.map}
11003 ) are good places to look for such overlaps.
11004 Variables with an absolute address are
11007 \begin_inset Marginal
11021 \begin_inset LatexCommand \index{Variable initialization}
11028 In case of memory mapped I/O devices the keyword
11032 has to be used to tell the compiler that accesses might not be removed:
11038 \begin_inset LatexCommand \index{volatile}
11043 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11048 \begin_inset LatexCommand \index{at}
11052 (0x8000) unsigned char PORTA_8255;
11055 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11060 \begin_inset LatexCommand \index{Aligned array}
11067 starts at a block (256 byte) boundary
11068 \begin_inset LatexCommand \index{block boundary}
11073 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11079 Absolute addresses can be specified for variables in all storage classes,
11086 \begin_inset LatexCommand \index{bit}
11091 \begin_inset LatexCommand \index{at}
11098 The above example will allocate the variable at offset 0x02 in the bit-addressab
11100 There is no real advantage to assigning absolute addresses to variables
11101 in this manner, unless you want strict control over all the variables allocated.
11102 One possible use would be to write hardware portable code.
11103 For example, if you have a routine that uses one or more of the microcontroller
11104 I/O pins, and such pins are different for two different hardwares, you
11105 can declare the I/O pins in your routine using:
11111 \begin_inset LatexCommand \index{volatile}
11115 __bit MOSI;\SpecialChar ~
11119 /* master out, slave in */
11121 extern volatile __bit MISO;\SpecialChar ~
11125 /* master in, slave out */
11127 extern volatile __bit MCLK;\SpecialChar ~
11135 /* Input and Output of a byte on a 3-wire serial bus.
11140 If needed adapt polarity of clock, polarity of data and bit order
11145 unsigned char spi_io(unsigned char out_byte)
11169 MOSI = out_byte & 0x80;
11199 /* _asm nop _endasm; */\SpecialChar ~
11207 /* for slow peripherals */
11258 Then, someplace in the code for the first hardware you would use
11264 \begin_inset LatexCommand \index{at}
11269 \begin_inset LatexCommand \index{\_\_at}
11273 (0x80) MOSI;\SpecialChar ~
11277 /* I/O port 0, bit 0 */
11279 __bit __at (0x81) MISO;\SpecialChar ~
11283 /* I/O port 0, bit 1 */
11285 __bit __at (0x82) MCLK;\SpecialChar ~
11289 /* I/O port 0, bit 2 */
11292 Similarly, for the second hardware you would use
11297 __bit __at (0x83) MOSI;\SpecialChar ~
11301 /* I/O port 0, bit 3 */
11303 __bit __at (0x91) MISO;\SpecialChar ~
11307 /* I/O port 1, bit 1 */
11310 \begin_inset LatexCommand \index{bit}
11314 __at (0x92) MCLK;\SpecialChar ~
11318 /* I/O port 1, bit 2 */
11320 \added_space_bottom bigskip
11321 and you can use the same hardware dependent routine without changes, as
11322 for example in a library.
11323 This is somehow similar to sbit, but only one absolute address has to be
11324 specified in the whole project.
11328 \begin_inset LatexCommand \index{Parameters}
11333 \begin_inset LatexCommand \index{function parameter}
11338 \begin_inset LatexCommand \index{local variables}
11343 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11350 Automatic (local) variables and parameters to functions can either be placed
11351 on the stack or in data-space.
11352 The default action of the compiler is to place these variables in the internal
11353 RAM (for small model) or external RAM (for large model).
11354 This in fact makes them similar to
11357 \begin_inset LatexCommand \index{static}
11363 so by default functions are non-reentrant
11364 \begin_inset LatexCommand \index{reentrant}
11373 They can be placed on the stack
11374 \begin_inset LatexCommand \index{stack}
11391 \begin_inset LatexCommand \index{-\/-stack-auto}
11399 #pragma\SpecialChar ~
11403 \begin_inset LatexCommand \index{\#pragma stackauto}
11410 \begin_inset LatexCommand \index{reentrant}
11416 keyword in the function declaration, e.g.:
11421 unsigned char foo(char i) __reentrant
11435 Since stack space on 8051 is limited, the
11453 option should be used sparingly.
11454 Note that the reentrant keyword just means that the parameters & local
11455 variables will be allocated to the stack, it
11459 mean that the function is register bank
11460 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11469 \begin_inset LatexCommand \index{local variables}
11473 can be assigned storage classes and absolute
11474 \begin_inset LatexCommand \index{Absolute addressing}
11483 unsigned char foo()
11491 __xdata unsigned char i;
11504 \begin_inset LatexCommand \index{at}
11508 (0x31) unsigned char j;
11520 In the above example the variable
11524 will be allocated in the external ram,
11528 in bit addressable space and
11547 or when a function is declared as
11551 this should only be done for static variables.
11555 \begin_inset LatexCommand \index{function parameter}
11559 however are not allowed any storage class
11560 \begin_inset LatexCommand \index{Storage class}
11564 , (storage classes for parameters will be ignored), their allocation is
11565 governed by the memory model in use, and the reentrancy options.
11568 It is however allowed to use bit parameters in reentrant functions and also
11569 non-static local bit variables are supported.
11570 Efficient use is limited to 8 semi-bitregisters in bit space.
11571 They are pushed and popped to stack
11572 \begin_inset LatexCommand \index{stack}
11576 as a single byte just like the normal registers.
11580 \begin_inset LatexCommand \label{sub:Overlaying}
11585 \begin_inset LatexCommand \index{Overlaying}
11593 \begin_inset LatexCommand \index{reentrant}
11597 functions SDCC will try to reduce internal ram space usage by overlaying
11598 parameters and local variables of a function (if possible).
11599 Parameters and local variables
11600 \begin_inset LatexCommand \index{local variables}
11604 of a function will be allocated to an overlayable segment if the function
11607 no other function calls and the function is non-reentrant and the memory
11609 \begin_inset LatexCommand \index{Memory model}
11616 If an explicit storage class
11617 \begin_inset LatexCommand \index{Storage class}
11621 is specified for a local variable, it will NOT be overlayed.
11624 Note that the compiler (not the linkage editor) makes the decision for overlayin
11626 Functions that are called from an interrupt service routine
11627 \begin_inset Marginal
11637 should be preceded by a #pragma\SpecialChar ~
11639 \begin_inset LatexCommand \index{\#pragma nooverlay}
11643 if they are not reentrant.
11646 Also note that the compiler does not do any processing of inline assembler
11647 code, so the compiler might incorrectly assign local variables and parameters
11648 of a function into the overlay segment if the inline assembler code calls
11649 other c-functions that might use the overlay.
11650 In that case the #pragma\SpecialChar ~
11651 nooverlay should be used.
11654 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11656 \begin_inset LatexCommand \index{Multiplication}
11661 \begin_inset LatexCommand \index{Division}
11665 will NOT be overlayed since these are implemented using external functions,
11674 \begin_inset LatexCommand \index{\#pragma nooverlay}
11680 void set_error(unsigned char errcd)
11696 void some_isr () __interrupt
11697 \begin_inset LatexCommand \index{interrupt}
11726 \added_space_bottom bigskip
11727 In the above example the parameter
11735 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11737 not present, this could cause unpredictable runtime behavior when called
11738 from an interrupt service routine.
11739 The #pragma\SpecialChar ~
11740 nooverlay ensures that the parameters and local variables for
11741 the function are NOT overlayed.
11744 Interrupt Service Routines
11745 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11752 General Information
11767 outines to be coded in C, with some extended keywords.
11772 void timer_isr (void) __interrupt (1) __using (1)
11786 The optional number following the
11789 \begin_inset LatexCommand \index{interrupt}
11794 \begin_inset LatexCommand \index{\_\_interrupt}
11800 keyword is the interrupt number this routine will service.
11801 When present, the compiler will insert a call to this routine in the interrupt
11803 \begin_inset LatexCommand \index{interrupt vector table}
11807 for the interrupt number specified.
11808 If you have multiple source files in your project, interrupt service routines
11809 can be present in any of them, but a prototype of the isr MUST be present
11810 or included in the file that contains the function
11815 The optional (8051 specific) keyword
11818 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11823 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11829 can be used to tell the compiler to use the specified register bank when
11830 generating code for this function.
11833 Interrupt service routines open the door for some very interesting bugs:
11834 \layout Subsubsection
11837 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11841 Common interrupt pitfall: variable not declared
11846 If an interrupt service routine changes variables which are accessed by
11847 other functions these variables have to be declared
11852 \begin_inset LatexCommand \index{volatile}
11858 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11863 \layout Subsubsection
11866 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11870 Common interrupt pitfall:
11875 If the access to these variables is not
11878 \begin_inset LatexCommand \index{atomic}
11885 the processor needs more than one instruction for the access and could
11886 be interrupted while accessing the variable) the interrupt must be disabled
11887 during the access to avoid inconsistent data.
11890 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11891 should be protected by disabling interrupts.
11892 You're not automatically on the safe side if you use 8 bit variables though.
11893 We need an example here: f.e.
11894 on the 8051 the harmless looking
11895 \begin_inset Quotes srd
11900 flags\SpecialChar ~
11905 \begin_inset Quotes sld
11914 \begin_inset Quotes srd
11919 flags\SpecialChar ~
11924 \begin_inset Quotes sld
11927 from within an interrupt routine might get lost if the interrupt occurs
11930 \begin_inset Quotes sld
11935 counter\SpecialChar ~
11940 \begin_inset Quotes srd
11943 is not atomic on the 8051 even if
11947 is located in data memory.
11949 Bugs like these are hard to reproduce and can cause a lot of trouble.
11951 \layout Subsubsection
11954 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11958 Common interrupt pitfall:
11963 The return address and the registers used in the interrupt service routine
11964 are saved on the stack
11965 \begin_inset LatexCommand \index{stack}
11969 so there must be sufficient stack space.
11970 If there isn't variables or registers (or even the return address itself)
11977 \begin_inset LatexCommand \index{stack overflow}
11981 is most likely to happen if the interrupt occurs during the
11982 \begin_inset Quotes sld
11986 \begin_inset Quotes srd
11989 subroutine when the stack is already in use for f.e.
11990 many return addresses.
11991 \layout Subsubsection
11994 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11998 Common interrupt pitfall:
12000 use of non-reentrant functions
12003 A special note here, int (16 bit) and long (32 bit) integer division
12004 \begin_inset LatexCommand \index{Division}
12009 \begin_inset LatexCommand \index{Multiplication}
12014 \begin_inset LatexCommand \index{Modulus}
12019 \begin_inset LatexCommand \index{Floating point support}
12023 operations are implemented using external support routines.
12024 If an interrupt service routine needs to do any of these operations then
12025 the support routines (as mentioned in a following section) will have to
12026 be recompiled using the
12039 \begin_inset LatexCommand \index{-\/-stack-auto}
12045 option and the source file will need to be compiled using the
12060 \begin_inset LatexCommand \index{-\/-int-long-reent}
12067 Note, the type promotion
12068 \begin_inset LatexCommand \index{type promotion}
12072 required by ANSI C can cause 16 bit routines to be used
12073 \begin_inset Marginal
12084 without the programmer being aware of it.
12088 (unsigned char)(tail-1)
12090 within the if clause in section
12091 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12097 \added_space_bottom bigskip
12098 Calling other functions from an interrupt service routine is not recommended,
12099 avoid it if possible.
12100 Note that when some function is called from an interrupt service routine
12101 it should be preceded by a #pragma\SpecialChar ~
12103 \begin_inset LatexCommand \index{\#pragma nooverlay}
12107 if it is not reentrant.
12108 Furthermore nonreentrant functions should not be called from the main program
12109 while the interrupt service routine might be active.
12110 They also must not be called from low priority interrupt service routines
12111 while a high priority interrupt service routine might be active.
12112 You could use semaphores or make the function
12116 if all parameters are passed in registers.
12119 \begin_inset LatexCommand \ref{sub:Overlaying}
12124 about Overlaying and section
12125 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12130 about Functions using private register banks.
12133 MCS51/DS390 Interrupt Service Routines
12137 \begin_inset LatexCommand \index{interrupt}
12141 numbers and the corresponding address & descriptions for the Standard 8051/8052
12143 SDCC will automatically adjust the
12144 \begin_inset LatexCommand \index{interrupt vector table}
12148 to the maximum interrupt number specified.
12154 \begin_inset Tabular
12155 <lyxtabular version="3" rows="9" columns="3">
12157 <column alignment="center" valignment="top" leftline="true" width="0in">
12158 <column alignment="left" valignment="top" leftline="true" width="0in">
12159 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12160 <row topline="true" bottomline="true">
12161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12186 <row topline="true">
12187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12212 <row topline="true">
12213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12238 <row topline="true">
12239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12264 <row topline="true">
12265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12290 <row topline="true">
12291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12316 <row topline="true">
12317 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12342 <row topline="true">
12343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12367 <row topline="true" bottomline="true">
12368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12401 If the interrupt service routine is defined without
12404 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12409 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12415 a register bank or with register bank 0 (
12419 0), the compiler will save the registers used by itself on the stack upon
12420 entry and restore them at exit, however if such an interrupt service routine
12421 calls another function then the entire register bank will be saved on the
12423 This scheme may be advantageous for small interrupt service routines which
12424 have low register usage.
12426 \added_space_bottom bigskip
12427 If the interrupt service routine is defined to be using a specific register
12432 & psw are saved and restored, if such an interrupt service routine calls
12433 another function (using another register bank) then the entire register
12434 bank of the called function will be saved on the stack
12435 \begin_inset LatexCommand \index{stack}
12440 This scheme is recommended for larger interrupt service routines.
12444 \begin_inset LatexCommand \index{HC08}
12448 Interrupt Service Routines
12450 \added_space_bottom bigskip
12451 Since the number of interrupts
12452 \begin_inset LatexCommand \index{HC08!interrupt}
12456 available is chip specific and the interrupt vector table always ends at
12457 the last byte of memory, the interrupt numbers corresponds to the interrupt
12458 vectors in reverse order of address.
12459 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12460 2 will use the interrupt vector at 0xfffa, and so on.
12461 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12462 this way; instead see section
12463 \begin_inset LatexCommand \ref{sub:Startup-Code}
12467 for details on customizing startup.
12470 Z80 Interrupt Service Routines
12474 \begin_inset LatexCommand \index{Z80}
12478 uses several different methods for determining the correct interrupt
12479 \begin_inset LatexCommand \index{Z80!interrupt}
12483 vector depending on the hardware implementation.
12484 Therefore, SDCC ignores the optional interrupt number and does not attempt
12485 to generate an interrupt vector table.
12488 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12489 instruction to return from the interrupt.
12490 To write an interrupt handler for the non-maskable interrupt, which needs
12491 a RETN instruction instead, add the
12500 void nmi_isr (void) critical interrupt
12513 \added_space_bottom bigskip
12514 However if you need to create a non-interruptable interrupt service routine
12515 you would also require the
12520 To distinguish between this and an nmi_isr you must provide an interrupt
12524 Enabling and Disabling Interrupts
12527 Critical Functions and Critical Statements
12530 A special keyword may be associated with a block or a function declaring
12536 SDCC will generate code to disable all interrupts
12537 \begin_inset LatexCommand \index{interrupt}
12541 upon entry to a critical function and restore the interrupt enable to the
12542 previous state before returning.
12543 Nesting critical functions will need one additional byte on the stack
12544 \begin_inset LatexCommand \index{stack}
12553 int foo () __critical
12554 \begin_inset LatexCommand \index{critical}
12559 \begin_inset LatexCommand \index{\_\_critical}
12584 The critical attribute maybe used with other attributes like
12594 may also be used to disable interrupts more locally:
12602 More than one statement could have been included in the block.
12605 Enabling and Disabling Interrupts directly
12609 \begin_inset LatexCommand \index{interrupt}
12613 can also be disabled and enabled directly (8051):
12618 EA = 0;\SpecialChar ~
12681 EA = 1;\SpecialChar ~
12748 On other architectures which have seperate opcodes for enabling and disabling
12749 interrupts you might want to make use of defines with inline assembly
12750 \begin_inset LatexCommand \index{Assembler routines}
12755 \begin_inset LatexCommand \index{HC08!interrupt}
12765 \begin_inset LatexCommand \index{\_asm}
12774 \begin_inset LatexCommand \index{\_endasm}
12783 #define SEI _asm\SpecialChar ~
12795 Note: it is sometimes sufficient to disable only a specific interrupt source
12797 a timer or serial interrupt by manipulating an
12800 \begin_inset LatexCommand \index{interrupt mask}
12810 Usually the time during which interrupts are disabled should be kept as
12812 This minimizes both
12817 \begin_inset LatexCommand \index{interrupt latency}
12821 (the time between the occurrence of the interrupt and the execution of
12822 the first code in the interrupt routine) and
12827 \begin_inset LatexCommand \index{interrupt jitter}
12831 (the difference between the shortest and the longest interrupt latency).
12832 These really are something different, f.e.
12833 a serial interrupt has to be served before its buffer overruns so it cares
12834 for the maximum interrupt latency, whereas it does not care about jitter.
12835 On a loudspeaker driven via a digital to analog converter which is fed
12836 by an interrupt a latency of a few milliseconds might be tolerable, whereas
12837 a much smaller jitter will be very audible.
12840 You can reenable interrupts within an interrupt routine and on some architecture
12841 s you can make use of two (or more) levels of
12843 interrupt priorities
12846 \begin_inset LatexCommand \index{interrupt priority}
12851 On some architectures which don't support interrupt priorities these can
12852 be implemented by manipulating the interrupt mask and reenabling interrupts
12853 within the interrupt routine.
12854 Check there is sufficient space on the stack
12855 \begin_inset LatexCommand \index{stack}
12859 and don't add complexity unless you have to.
12864 \begin_inset LatexCommand \index{semaphore}
12868 locking (mcs51/ds390)
12871 Some architectures (mcs51/ds390) have an atomic
12872 \begin_inset LatexCommand \index{atomic}
12885 These type of instructions are typically used in preemptive multitasking
12886 systems, where a routine f.e.
12887 claims the use of a data structure ('acquires a lock
12888 \begin_inset LatexCommand \index{lock}
12892 on it'), makes some modifications and then releases the lock when the data
12893 structure is consistent again.
12894 The instruction may also be used if interrupt and non-interrupt code have
12895 to compete for a resource.
12896 With the atomic bit test and clear instruction interrupts
12897 \begin_inset LatexCommand \index{interrupt}
12901 don't have to be disabled for the locking operation.
12905 SDCC generates this instruction if the source follows this pattern:
12911 \begin_inset LatexCommand \index{volatile}
12915 bit resource_is_free;
12919 if (resource_is_free)
12929 resource_is_free=0;
12942 resource_is_free=1;
12949 Note, mcs51 and ds390 support only an atomic
12950 \begin_inset LatexCommand \index{atomic}
12958 instruction (as opposed to atomic bit test and
12963 Functions using private register banks
12964 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12971 Some architectures have support for quickly changing register sets.
12972 SDCC supports this feature with the
12975 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12980 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12986 attribute (which tells the compiler to use a register bank
12987 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12991 other than the default bank zero).
12992 It should only be applied to
12995 \begin_inset LatexCommand \index{interrupt}
13001 functions (see footnote below).
13002 This will in most circumstances make the generated ISR code more efficient
13003 since it will not have to save registers on the stack.
13010 attribute will have no effect on the generated code for a
13014 function (but may occasionally be useful anyway
13020 possible exception: if a function is called ONLY from 'interrupt' functions
13021 using a particular bank, it can be declared with the same 'using' attribute
13022 as the calling 'interrupt' functions.
13023 For instance, if you have several ISRs using bank one, and all of them
13024 call memcpy(), it might make sense to create a specialized version of memcpy()
13025 'using 1', since this would prevent the ISR from having to save bank zero
13026 to the stack on entry and switch to bank zero before calling the function
13033 (pending: Note, nowadays the
13037 attribute has an effect on
13041 the generated code for a
13056 function using a non-zero bank will assume that it can trash that register
13057 bank, and will not save it.
13058 Since high-priority interrupts
13059 \begin_inset LatexCommand \index{interrupts}
13064 \begin_inset LatexCommand \index{interrupt priority}
13068 can interrupt low-priority ones on the 8051 and friends, this means that
13069 if a high-priority ISR
13073 a particular bank occurs while processing a low-priority ISR
13077 the same bank, terrible and bad things can happen.
13078 To prevent this, no single register bank should be
13082 by both a high priority and a low priority ISR.
13083 This is probably most easily done by having all high priority ISRs use
13084 one bank and all low priority ISRs use another.
13085 If you have an ISR which can change priority at runtime, you're on your
13086 own: I suggest using the default bank zero and taking the small performance
13089 \added_space_bottom bigskip
13090 It is most efficient if your ISR calls no other functions.
13091 If your ISR must call other functions, it is most efficient if those functions
13092 use the same bank as the ISR (see note 1 below); the next best is if the
13093 called functions use bank zero.
13094 It is very inefficient to call a function using a different, non-zero bank
13100 \begin_inset LatexCommand \label{sub:Startup-Code}
13105 \begin_inset LatexCommand \index{Startup code}
13112 MCS51/DS390 Startup Code
13115 The compiler triggers the linker to link certain initialization modules
13116 from the runtime library
13117 \begin_inset LatexCommand \index{Runtime library}
13121 called crt<something>.
13122 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
13123 GSINIT5) is not linked unless the --xstack option is used.
13124 These modules are highly entangled by the use of special segments/areas,
13125 but a common layout is shown below:
13158 ljmp __sdcc_gsinit_startup
13179 .area GSINIT0 (CODE)
13181 __sdcc_gsinit_startup::
13191 mov sp,#__start__stack - 1
13212 .area GSINIT1 (CODE)
13214 __sdcc_init_xstack::
13216 ; Need to initialize in GSINIT1 in case the user's __sdcc_external_startup
13227 mov __XPAGE,#(__start__xstack >> 8)
13237 mov _spx,#__start__xstack
13258 .area GSINIT2 (CODE)
13268 lcall __sdcc_external_startup
13288 jz __sdcc_init_data
13298 ljmp __sdcc_program_startup
13321 .area GSINIT3 (CODE)
13353 orl a,#(l_XINIT >> 8)
13373 mov r2,#((l_XINIT+255) >> 8)
13403 mov __XPAGE,#(s_XISEG >> 8)
13405 00001$:\SpecialChar ~
13468 00002$:\SpecialChar ~
13512 .area GSINIT4 (CODE)
13514 __mcs51_genRAMCLEAR::
13536 00004$:\SpecialChar ~
13549 ; _mcs51_genRAMCLEAR() end
13570 .area GSINIT4 (CODE)
13572 __mcs51_genXRAMCLEAR::
13622 mov __XPAGE,#(s_PSEG >> 8)
13634 00005$:\SpecialChar ~
13687 orl a,#(l_XSEG >> 8)
13707 mov r1,#((l_XSEG + 255) >> 8)
13729 00007$:\SpecialChar ~
13783 .area GSINIT5 (CODE)
13785 ; Need to initialize in GSINIT5 because __mcs51_genXINIT modifies __XPAGE
13787 ; and __mcs51_genRAMCLEAR modifies _spx.
13797 mov __XPAGE,#(__start__xstack >> 8)
13807 mov _spx,#__start__xstack
13814 (application modules)
13828 .area GSINIT (CODE)
13849 .area GSFINAL (CODE)
13859 ljmp __sdcc_program_startup
13861 ;--------------------------------------------------------
13865 ;--------------------------------------------------------
13887 __sdcc_program_startup:
13899 ; return from main will lock up
13912 One of these modules (crtstart.asm) contains a call to the C routine
13914 _sdcc_external_startup()
13915 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13924 at the start of the CODE area.
13925 This routine is also in the runtime library
13926 \begin_inset LatexCommand \index{Runtime library}
13930 and returns 0 by default.
13931 If this routine returns a non-zero value, the static & global variable
13932 initialization will be skipped and the function main will be invoked.
13933 Otherwise static & global variables will be initialized before the function
13937 _sdcc_external_startup()
13939 routine to your program to override the default if you need to setup hardware
13940 or perform some other critical operation prior to static & global variable
13942 \begin_inset LatexCommand \index{Variable initialization}
13947 On some mcs51 variants xdata
13948 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13952 memory has to be explicitly enabled before it can be accessed or if the
13954 \begin_inset LatexCommand \index{watchdog}
13958 needs to be disabled, this is the place to do it.
13959 The startup code clears all internal data memory, 256 bytes by default,
13960 but from 0 to n-1 if
13973 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13980 (recommended for Chipcon CC1010).
13982 \added_space_bottom bigskip
13983 See also the compiler options
14002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14021 \begin_inset LatexCommand \index{-\/-main-return}
14026 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14030 about MCS51-variants.
14035 \added_space_bottom bigskip
14037 \begin_inset LatexCommand \index{HC08}
14041 startup code follows the same scheme as the MCS51 startup code.
14046 \added_space_bottom bigskip
14048 \begin_inset LatexCommand \index{Z80}
14052 the startup code is inserted by linking with crt0.o which is generated from
14053 sdcc/device/lib/z80/crt0.s.
14054 If you need a different startup code you can use the compiler option
14075 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14079 and provide your own crt0.o.
14083 Inline Assembler Code
14084 \begin_inset LatexCommand \index{Assembler routines}
14091 A Step by Step Introduction
14092 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14099 Starting from a small snippet of c-code this example shows for the MCS51
14100 how to use inline assembly, access variables, a function parameter and
14101 an array in xdata memory.
14102 The example uses an MCS51 here but is easily adapted for other architectures.
14103 This is a buffer routine which should be optimized:
14109 unsigned char __far
14110 \begin_inset LatexCommand \index{far (storage class)}
14115 \begin_inset LatexCommand \index{\_\_far (storage class)}
14120 \begin_inset LatexCommand \index{at}
14125 \begin_inset LatexCommand \index{\_\_at}
14129 (0x7f00) buf[0x100];
14130 \begin_inset LatexCommand \index{Aligned array}
14136 unsigned char head, tail;\SpecialChar ~
14154 \begin_inset LatexCommand \index{interrupt}
14206 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14218 void to_buffer( unsigned char c )
14226 if( head != (unsigned char)(tail-1) )\SpecialChar ~
14232 \begin_inset LatexCommand \index{promotion to signed int}
14237 \begin_inset LatexCommand \index{type promotion}
14242 \begin_inset Marginal
14263 buf[ head++ ] = c;\SpecialChar ~
14279 /* access to a 256 byte aligned array */
14284 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14285 then a corresponding buffer.asm file is generated.
14286 We define a new function
14290 in file buffer.c in which we cut and paste the generated code, removing
14291 unwanted comments and some ':'.
14293 \begin_inset Quotes sld
14297 \begin_inset Quotes srd
14301 \begin_inset Quotes sld
14305 \begin_inset Quotes srd
14308 to the beginning and the end of the function body:
14314 /* With a cut and paste from the .asm file, we have something to start with.
14319 The function is not yet OK! (registers aren't saved) */
14321 void to_buffer_asm( unsigned char c )
14330 \begin_inset LatexCommand \index{\_asm}
14335 \begin_inset LatexCommand \index{\_\_asm}
14349 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14355 \begin_inset LatexCommand \index{promotion to signed int}
14360 \begin_inset LatexCommand \index{type promotion}
14412 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14413 \begin_inset LatexCommand \index{Aligned array}
14478 \begin_inset LatexCommand \index{\_endasm}
14483 \begin_inset LatexCommand \index{\_\_endasm}
14492 The new file buffer.c should compile with only one warning about the unreferenced
14493 function argument 'c'.
14494 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14495 (1) and finally have:
14501 unsigned char __far __at(0x7f00) buf[0x100];
14503 unsigned char head, tail;
14505 #define USE_ASSEMBLY (1)
14513 void to_buffer( unsigned char c )
14521 if( head != (unsigned char)(tail-1) )
14541 void to_buffer( unsigned char c )
14549 c; // to avoid warning: unreferenced function argument
14556 \begin_inset LatexCommand \index{\_asm}
14561 \begin_inset LatexCommand \index{\_\_asm}
14575 ; save used registers here.
14586 ; If we were still using r2,r3 we would have to push them here.
14589 ; if( head != (unsigned char)(tail-1) )
14632 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
14656 ; buf[ head++ ] = c;
14667 a,dpl \SpecialChar ~
14674 ; dpl holds lower byte of function argument
14685 dpl,_head \SpecialChar ~
14688 ; buf is 0x100 byte aligned so head can be used directly
14730 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
14742 ; restore used registers here
14749 \begin_inset LatexCommand \index{\_endasm}
14754 \begin_inset LatexCommand \index{\_\_endasm}
14765 The inline assembler code can contain any valid code understood by the assembler
14766 , this includes any assembler directives and comment lines.
14767 The assembler does not like some characters like ':' or ''' in comments.
14768 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
14769 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
14774 \begin_inset LatexCommand \index{Assembler documentation}
14779 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
14787 The compiler does not do any validation of the code within the
14790 \begin_inset LatexCommand \index{\_asm}
14795 \begin_inset LatexCommand \index{\_\_asm}
14803 \begin_inset LatexCommand \index{\_endasm}
14808 \begin_inset LatexCommand \index{\_\_endasm}
14817 Specifically it will not know which registers are used and thus register
14819 \begin_inset LatexCommand \index{push/pop}
14823 has to be done manually.
14827 It is recommended that each assembly instruction (including labels) be placed
14828 in a separate line (as the example shows).
14842 \begin_inset LatexCommand \index{-\/-peep-asm}
14848 command line option is used, the inline assembler code will be passed through
14849 the peephole optimizer
14850 \begin_inset LatexCommand \index{Peephole optimizer}
14855 There are only a few (if any) cases where this option makes sense, it might
14856 cause some unexpected changes in the inline assembler code.
14857 Please go through the peephole optimizer rules defined in file
14861 before using this option.
14865 \begin_inset LatexCommand \label{sub:Naked-Functions}
14870 \begin_inset LatexCommand \index{Naked functions}
14877 A special keyword may be associated with a function declaring it as
14880 \begin_inset LatexCommand \index{\_naked}
14885 \begin_inset LatexCommand \index{\_\_naked}
14896 function modifier attribute prevents the compiler from generating prologue
14897 \begin_inset LatexCommand \index{function prologue}
14902 \begin_inset LatexCommand \index{function epilogue}
14906 code for that function.
14907 This means that the user is entirely responsible for such things as saving
14908 any registers that may need to be preserved, selecting the proper register
14909 bank, generating the
14913 instruction at the end, etc.
14914 Practically, this means that the contents of the function must be written
14915 in inline assembler.
14916 This is particularly useful for interrupt functions, which can have a large
14917 (and often unnecessary) prologue/epilogue.
14918 For example, compare the code generated by these two functions:
14924 \begin_inset LatexCommand \index{volatile}
14928 data unsigned char counter;
14932 void simpleInterrupt(void) __interrupt
14933 \begin_inset LatexCommand \index{interrupt}
14938 \begin_inset LatexCommand \index{\_\_interrupt}
14956 void nakedInterrupt(void) __interrupt (2) __naked
14965 \begin_inset LatexCommand \index{\_asm}
14970 \begin_inset LatexCommand \index{\_\_asm}
14987 _counter ; does not change flags, no need to save psw
14999 ; MUST explicitly include ret or reti in _naked function.
15006 \begin_inset LatexCommand \index{\_endasm}
15011 \begin_inset LatexCommand \index{\_\_endasm}
15020 For an 8051 target, the generated simpleInterrupt looks like:
15029 example, recent versions of SDCC generate
15035 code for simpleInterrupt() and nakedInterrupt()!
15175 whereas nakedInterrupt looks like:
15190 _counter ; does not change flags, no need to save psw
15208 ; MUST explicitly include ret or reti in _naked function
15211 The related directive #pragma exclude
15212 \begin_inset LatexCommand \index{\#pragma exclude}
15216 allows a more fine grained control over pushing & popping
15217 \begin_inset LatexCommand \index{push/pop}
15224 While there is nothing preventing you from writing C code inside a
15228 function, there are many ways to shoot yourself in the foot doing this,
15229 and it is recommended that you stick to inline assembler.
15232 Use of Labels within Inline Assembler
15235 SDCC allows the use of in-line assembler with a few restrictions regarding
15237 In older versions of the compiler all labels defined within inline assembler
15246 where nnnn is a number less than 100 (which implies a limit of utmost 100
15247 inline assembler labels
15261 \begin_inset LatexCommand \index{\_asm}
15266 \begin_inset LatexCommand \index{\_\_asm}
15296 \begin_inset LatexCommand \index{\_endasm}
15301 \begin_inset LatexCommand \index{\_\_endasm}
15308 Inline assembler code cannot reference any C-Labels, however it can reference
15310 \begin_inset LatexCommand \index{Labels}
15314 defined by the inline assembler, e.g.:
15339 ; some assembler code
15359 /* some more c code */
15361 clabel:\SpecialChar ~
15363 /* inline assembler cannot reference this label */
15375 $0003: ;label (can be referenced by inline assembler only)
15382 \begin_inset LatexCommand \index{\_endasm}
15387 \begin_inset LatexCommand \index{\_\_endasm}
15397 /* some more c code */
15402 In other words inline assembly code can access labels defined in inline
15403 assembly within the scope of the function.
15404 The same goes the other way, i.e.
15405 labels defines in inline assembly can not be accessed by C statements.
15408 Interfacing with Assembler Code
15409 \begin_inset LatexCommand \index{Assembler routines}
15416 Global Registers used for Parameter Passing
15417 \begin_inset LatexCommand \index{Parameter passing}
15424 The compiler always uses the global registers
15427 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15432 \begin_inset LatexCommand \index{DPTR}
15437 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15446 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15452 to pass the first parameter to a routine.
15453 The second parameter onwards is either allocated on the stack (for reentrant
15464 -stack-auto is used) or in data / xdata memory (depending on the memory
15469 Assembler Routine (non-reentrant)
15472 In the following example
15473 \begin_inset LatexCommand \index{reentrant}
15478 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15482 the function c_func calls an assembler routine asm_func, which takes two
15484 \begin_inset LatexCommand \index{function parameter}
15493 extern int asm_func(unsigned char, unsigned char);
15497 int c_func (unsigned char i, unsigned char j)
15505 return asm_func(i,j);
15519 return c_func(10,9);
15524 The corresponding assembler function is:
15529 .globl _asm_func_PARM_2
15630 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15647 Note here that the return values
15648 \begin_inset LatexCommand \index{return value}
15652 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
15654 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
15655 b' & 'acc' for four byte values.
15658 The parameter naming convention is _<function_name>_PARM_<n>, where n is
15659 the parameter number starting from 1, and counting from the left.
15660 The first parameter is passed in
15661 \begin_inset Quotes eld
15665 \begin_inset Quotes erd
15668 for a one byte parameter,
15669 \begin_inset Quotes eld
15673 \begin_inset Quotes erd
15677 \begin_inset Quotes eld
15681 \begin_inset Quotes erd
15684 for three bytes and
15685 \begin_inset Quotes eld
15689 \begin_inset Quotes erd
15692 for a four bytes parameter.
15693 The variable name for the second parameter will be _<function_name>_PARM_2.
15697 Assemble the assembler routine with the following command:
15704 asx8051 -losg asmfunc.asm
15711 Then compile and link the assembler routine to the C source file with the
15719 sdcc cfunc.c asmfunc.rel
15722 Assembler Routine (reentrant)
15726 \begin_inset LatexCommand \index{reentrant}
15731 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
15735 the second parameter
15736 \begin_inset LatexCommand \index{function parameter}
15740 onwards will be passed on the stack, the parameters are pushed from right
15742 after the call the leftmost parameter will be on the top of the stack.
15743 Here is an example:
15748 extern int asm_func(unsigned char, unsigned char);
15752 int c_func (unsigned char i, unsigned char j) reentrant
15760 return asm_func(i,j);
15774 return c_func(10,9);
15779 The corresponding assembler routine is:
15878 \added_space_bottom bigskip
15879 The compiling and linking procedure remains the same, however note the extra
15880 entry & exit linkage required for the assembler code, _bp is the stack
15881 frame pointer and is used to compute the offset into the stack for parameters
15882 and local variables.
15886 \begin_inset LatexCommand \index{int (16 bit)}
15891 \begin_inset LatexCommand \index{long (32 bit)}
15898 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15899 multiplication and modulus operations are implemented by support routines.
15900 These support routines are all developed in ANSI-C to facilitate porting
15901 to other MCUs, although some model specific assembler optimizations are
15903 The following files contain the described routines, all of them can be
15904 found in <installdir>/share/sdcc/lib.
15910 \begin_inset Tabular
15911 <lyxtabular version="3" rows="11" columns="2">
15913 <column alignment="left" valignment="top" leftline="true" width="0">
15914 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15915 <row topline="true" bottomline="true">
15916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15937 <row topline="true">
15938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15951 16 bit multiplication
15955 <row topline="true">
15956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15969 signed 16 bit division (calls _divuint)
15973 <row topline="true">
15974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15987 unsigned 16 bit division
15991 <row topline="true">
15992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16005 signed 16 bit modulus (calls _moduint)
16009 <row topline="true">
16010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16023 unsigned 16 bit modulus
16027 <row topline="true">
16028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16041 32 bit multiplication
16045 <row topline="true">
16046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16059 signed 32 division (calls _divulong)
16063 <row topline="true">
16064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16077 unsigned 32 division
16081 <row topline="true">
16082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16095 signed 32 bit modulus (calls _modulong)
16099 <row topline="true" bottomline="true">
16100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16113 unsigned 32 bit modulus
16126 Since they are compiled as
16131 \begin_inset LatexCommand \index{reentrant}
16136 \begin_inset LatexCommand \index{interrupt}
16140 service routines should not do any of the above operations.
16141 If this is unavoidable then the above routines will need to be compiled
16155 \begin_inset LatexCommand \index{-\/-stack-auto}
16161 option, after which the source program will have to be compiled with
16174 \begin_inset LatexCommand \index{-\/-int-long-reent}
16181 Notice that you don't have to call these routines directly.
16182 The compiler will use them automatically every time an integer operation
16186 Floating Point Support
16187 \begin_inset LatexCommand \index{Floating point support}
16194 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16195 The floating point support routines are derived from gcc's floatlib.c and
16196 consist of the following routines:
16204 \begin_inset Tabular
16205 <lyxtabular version="3" rows="17" columns="2">
16207 <column alignment="left" valignment="top" leftline="true" width="0">
16208 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16209 <row topline="true" bottomline="true">
16210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16236 <row topline="true">
16237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16268 add floating point numbers
16272 <row topline="true">
16273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16304 subtract floating point numbers
16308 <row topline="true">
16309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16340 divide floating point numbers
16344 <row topline="true">
16345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16376 multiply floating point numbers
16380 <row topline="true">
16381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16412 convert floating point to unsigned char
16416 <row topline="true">
16417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16448 convert floating point to signed char
16452 <row topline="true">
16453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16484 convert floating point to unsigned int
16488 <row topline="true">
16489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16520 convert floating point to signed int
16524 <row topline="true">
16525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16564 convert floating point to unsigned long
16568 <row topline="true">
16569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16600 convert floating point to signed long
16604 <row topline="true">
16605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16636 convert unsigned char to floating point
16640 <row topline="true">
16641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16672 convert char to floating point number
16676 <row topline="true">
16677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16708 convert unsigned int to floating point
16712 <row topline="true">
16713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16744 convert int to floating point numbers
16748 <row topline="true">
16749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16780 convert unsigned long to floating point number
16784 <row topline="true" bottomline="true">
16785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16816 convert long to floating point number
16828 \added_space_bottom bigskip
16829 These support routines are developed in ANSI-C so there is room for space
16830 and speed improvement
16836 These floating point routines (
16840 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
16845 Note if all these routines are used simultaneously the data space might
16847 For serious floating point usage the large model might be needed.
16848 Also notice that you don't have to call this routines directly.
16849 The compiler will use them automatically every time a floating point operation
16854 \begin_inset LatexCommand \index{Libraries}
16863 <pending: this is messy and incomplete - a little more information is in
16864 sdcc/doc/libdoc.txt
16869 Compiler support routines (_gptrget, _mulint etc.)
16872 Stdclib functions (puts, printf, strcat etc.)
16873 \layout Subsubsection
16878 getchar(), putchar()
16882 \begin_inset LatexCommand \index{<stdio.h>}
16886 As usual on embedded systems you have to provide your own
16889 \begin_inset LatexCommand \index{getchar()}
16898 \begin_inset LatexCommand \index{putchar()}
16905 SDCC does not know whether the system connects to a serial line with or
16906 without handshake, LCD, keyboard or other device.
16920 You'll find examples for serial routines f.e.
16921 in sdcc/device/lib.
16922 For the mcs51 this minimalistic polling
16926 routine might be a start:
16931 void putchar (char c) {
16937 while (!TI)\SpecialChar ~
16940 /* assumes UART is initialized */
16973 \begin_inset LatexCommand \index{printf()}
16983 does not support float (except on ds390).
16984 To enable this recompile it with the option
16997 \begin_inset LatexCommand \index{USE\_FLOATS}
17003 on the command line.
17017 \begin_inset LatexCommand \index{-\/-model-large}
17023 for the mcs51 port, since this uses a lot of memory.
17026 If you're short on code memory you might want to use
17029 \begin_inset LatexCommand \index{printf\_small()}
17044 For the mcs51 there additionally are assembly versions
17047 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17053 (subset of printf using less than 270 bytes) and
17056 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17065 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17071 (floating-point aware version of printf_fast) which should fit the requirements
17072 of many embedded systems (printf_fast() can be customized by unsetting
17077 support long variables and field widths).
17078 Be sure to use only one of these printf options within a project.
17083 Feature matrix of different
17091 \begin_inset Tabular
17092 <lyxtabular version="3" rows="14" columns="7">
17093 <features islongtable="true">
17094 <column alignment="left" valignment="center" leftline="true" width="14col%">
17095 <column alignment="center" valignment="top" leftline="true" width="0">
17096 <column alignment="center" valignment="top" leftline="true" width="12col%">
17097 <column alignment="center" valignment="top" leftline="true" width="10col%">
17098 <column alignment="center" valignment="top" leftline="true" width="0">
17099 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17100 <column alignment="center" valignment="top" rightline="true" width="0">
17101 <row topline="true" bottomline="true" endhead="true">
17102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17119 \begin_inset LatexCommand \index{printf}
17126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17169 <row topline="true" endhead="true">
17170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17239 <row topline="true" endhead="true">
17240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17246 \begin_inset Quotes sld
17250 \begin_inset Quotes srd
17259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17308 <row topline="true" endhead="true">
17309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17341 0.45k / 0.47k (+ _ltoa)
17344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17369 <row topline="true">
17370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17505 <row topline="true">
17506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17511 long (32 bit) support
17514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17572 <row topline="true">
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17578 byte arguments on stack
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17630 <row topline="true">
17631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17637 \begin_inset LatexCommand \index{Floating point support}
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17687 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
17693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17702 <row topline="true">
17703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17708 float formats %e %g
17711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17760 <row topline="true" bottomline="true">
17761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17818 <row bottomline="true">
17819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17830 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
17834 n'); standard 8051 @ 22.1184 MHz, empty putchar()
17843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17892 <row bottomline="true">
17893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17904 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
17914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17965 printf_tiny integer speed is data dependent, worst case is 0.33 ms
17972 <row bottomline="true">
17973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17984 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
17994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18043 <row bottomline="true">
18044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18055 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18119 \layout Subsubsection
18122 \begin_inset LatexCommand \index{malloc.h}
18129 As of SDCC 2.6.2 you no longer need to call an initialization routine before
18130 using dynamic memory allocation
18131 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
18136 \begin_inset LatexCommand \index{heap (malloc)}
18140 space of 1024 bytes is provided for malloc to allocate memory from.
18141 If you need a different heap size you need to recompile _heap.c with the
18142 required size defined in HEAP_SIZE.
18143 It is recommended to make a copy of this file into your project directory
18144 and compile it there with:
18149 sdcc -c _heap.c -D HEAD_SIZE=2048
18152 And then link it with:
18157 sdcc main.rel _heap.rel
18160 Math functions (sinf, powf, sqrtf etc.)
18161 \layout Subsubsection
18166 See definitions in file <math.h>.
18173 \begin_inset LatexCommand \index{Libraries}
18177 included in SDCC should have a license at least as liberal as the GNU Lesser
18178 General Public License
18179 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
18196 license statements for the libraries are missing.
18197 sdcc/device/lib/ser_ir.c
18201 come with a GPL (as opposed to LGPL) License - this will not be liberal
18202 enough for many embedded programmers.
18208 If you have ported some library or want to share experience about some code
18210 falls into any of these categories Busses (I
18211 \begin_inset Formula $^{\textrm{2}}$
18214 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
18215 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
18216 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
18217 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
18222 would certainly like to hear about it.
18224 \added_space_bottom bigskip
18225 Programmers coding for embedded systems are not especially famous for being
18226 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
18227 e these references are very valuable.
18228 Let's help to create a climate where information is shared.
18234 MCS51 Memory Models
18235 \begin_inset LatexCommand \index{Memory model}
18240 \begin_inset LatexCommand \index{MCS51 memory model}
18245 \layout Subsubsection
18247 Small, Medium and Large
18250 SDCC allows three memory models for MCS51 code,
18259 Modules compiled with different memory models should
18263 be combined together or the results would be unpredictable.
18264 The library routines supplied with the compiler are compiled as small,
18266 The compiled library modules are contained in separate directories as small,
18267 medium and large so that you can link to the appropriate set.
18270 When the medium or large model is used all variables declared without a
18271 storage class will be allocated into the external ram, this includes all
18272 parameters and local variables (for non-reentrant
18273 \begin_inset LatexCommand \index{reentrant}
18278 When the small model is used variables without storage class are allocated
18279 in the internal ram.
18282 Judicious usage of the processor specific storage classes
18283 \begin_inset LatexCommand \index{Storage class}
18287 and the 'reentrant' function type will yield much more efficient code,
18288 than using the large model.
18289 Several optimizations are disabled when the program is compiled using the
18290 large model, it is therefore recommended that the small model be used unless
18291 absolutely required.
18292 \layout Subsubsection
18295 \begin_inset LatexCommand \label{sub:External-Stack}
18300 \begin_inset LatexCommand \index{stack}
18305 \begin_inset LatexCommand \index{External stack (mcs51)}
18312 The external stack (-
18323 \begin_inset LatexCommand \index{-\/-xstack}
18327 ) is located in pdata
18328 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18332 memory (usually at the start of the external ram segment) and uses all
18333 unused space in pdata (max.
18345 -xstack option is used to compile the program, the parameters and local
18347 \begin_inset LatexCommand \index{local variables}
18351 of all reentrant functions are allocated in this area.
18352 This option is provided for programs with large stack space requirements.
18353 When used with the -
18364 \begin_inset LatexCommand \index{-\/-stack-auto}
18368 option, all parameters and local variables are allocated on the external
18369 stack (note: support libraries will need to be recompiled with the same
18371 There is a predefined target in the library makefile).
18374 The compiler outputs the higher order address byte of the external ram segment
18376 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18381 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18385 ), therefore when using the External Stack option, this port
18389 be used by the application program.
18393 \begin_inset LatexCommand \index{Memory model}
18398 \begin_inset LatexCommand \index{DS390 memory model}
18405 The only model supported is Flat 24
18406 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18411 This generates code for the 24 bit contiguous addressing mode of the Dallas
18413 In this mode, up to four meg of external RAM or code space can be directly
18415 See the data sheets at www.dalsemi.com for further information on this part.
18419 Note that the compiler does not generate any code to place the processor
18420 into 24 bitmode (although
18424 in the ds390 libraries will do that for you).
18430 \begin_inset LatexCommand \index{Tinibios (DS390)}
18434 , the boot loader or similar code must ensure that the processor is in 24
18435 bit contiguous addressing mode before calling the SDCC startup code.
18453 option, variables will by default be placed into the XDATA segment.
18458 Segments may be placed anywhere in the 4 meg address space using the usual
18470 Note that if any segments are located above 64K, the -r flag must be passed
18471 to the linker to generate the proper segment relocations, and the Intel
18472 HEX output format must be used.
18473 The -r flag can be passed to the linker by using the option
18477 on the SDCC command line.
18478 However, currently the linker can not handle code segments > 64k.
18482 \begin_inset LatexCommand \label{sec:Pragmas}
18487 \begin_inset LatexCommand \index{Pragmas}
18494 SDCC supports the following #pragma directives:
18502 \begin_inset LatexCommand \index{\#pragma save}
18506 - this will save most current options to the save/restore stack.
18507 See #pragma\SpecialChar ~
18516 \begin_inset LatexCommand \index{\#pragma restore}
18520 - will restore saved options from the last save.
18521 saves & restores can be nested.
18522 SDCC uses a save/restore stack: save pushes current options to the stack,
18523 restore pulls current options from the stack.
18524 See #pragma\SpecialChar ~
18535 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18540 \begin_inset LatexCommand \index{function prologue}
18544 function1[,function2[,function3...]] - The compiler by default uses a caller
18545 saves convention for register saving across function calls, however this
18546 can cause unnecessary register pushing & popping
18547 \begin_inset LatexCommand \index{push/pop}
18551 when calling small functions from larger functions.
18552 This option can be used to switch off the register saving convention for
18553 the function names specified.
18554 The compiler will not save registers when calling these functions, extra
18555 code need to be manually inserted at the entry & exit for these functions
18556 to save & restore the registers used by these functions, this can SUBSTANTIALLY
18557 reduce code & improve run time performance of the generated code.
18558 In the future the compiler (with inter procedural analysis) may be able
18559 to determine the appropriate scheme to use for each function call.
18570 -callee-saves command line option is used, the function names specified
18571 in #pragma\SpecialChar ~
18573 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18577 is appended to the list of functions specified in the command line.
18585 \begin_inset LatexCommand \index{\#pragma exclude}
18589 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
18590 of pairs of push/pop
18591 \begin_inset LatexCommand \index{push/pop}
18600 \begin_inset LatexCommand \index{interrupt}
18613 The directive should be placed immediately before the ISR function definition
18614 and it affects ALL ISR functions following it.
18615 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
18616 exclude\SpecialChar ~
18618 \begin_inset LatexCommand \index{\#pragma exclude}
18623 See also the related keyword _naked
18624 \begin_inset LatexCommand \index{\_naked}
18629 \begin_inset LatexCommand \index{\_\_naked}
18641 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
18645 - the compiler will not warn you anymore for obvious mistakes, you'r on
18654 \begin_inset LatexCommand \index{\#pragma disable\_warning}
18658 - the compiler will not warn you anymore about warning number <nnnn>.
18666 \begin_inset LatexCommand \index{\#pragma nogcse}
18670 - will stop global common subexpression elimination.
18678 \begin_inset LatexCommand \index{\#pragma noinduction}
18682 - will stop loop induction optimizations.
18690 \begin_inset LatexCommand \index{\#pragma noinvariant}
18694 - will not do loop invariant optimizations.
18695 For more details see Loop Invariants in section
18696 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
18708 \begin_inset LatexCommand \index{\#pragma noiv}
18712 - Do not generate interrupt
18713 \begin_inset LatexCommand \index{interrupt}
18718 \begin_inset LatexCommand \index{interrupt vector table}
18722 entries for all ISR functions defined after the pragma.
18723 This is useful in cases where the interrupt vector table must be defined
18724 manually, or when there is a secondary, manually defined interrupt vector
18726 for the autovector feature of the Cypress EZ-USB FX2).
18727 More elegantly this can be achieved by obmitting the optional interrupt
18728 number after the interrupt keyword, see section
18729 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
18742 \begin_inset LatexCommand \index{\#pragma nojtbound}
18746 - will not generate code for boundary value checking, when switch statements
18747 are turned into jump-tables (dangerous).
18748 For more details see section
18749 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
18761 \begin_inset LatexCommand \index{\#pragma noloopreverse}
18765 - Will not do loop reversal optimization
18773 \begin_inset LatexCommand \index{\#pragma nooverlay}
18777 - the compiler will not overlay the parameters and local variables of a
18786 \begin_inset LatexCommand \index{\#pragma stackauto}
18801 \begin_inset LatexCommand \index{-\/-stack-auto}
18806 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
18810 Parameters and Local Variables.
18818 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
18822 - The compiler will optimize code generation towards fast code, possibly
18823 at the expense of code size.
18824 Currently this has little effect.
18832 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
18836 - The compiler will optimize code generation towards compact code, possibly
18837 at the expense of code speed.
18838 Currently this has little effect.
18846 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
18850 - The compiler will attempt to generate code that is both compact and fast,
18851 as long as meeting one goal is not a detriment to the other (this is the
18861 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
18865 - Generally follow the C89 standard, but allow SDCC features that conflict
18866 with the standard (default).
18874 \begin_inset LatexCommand \index{\#pragma std\_c89}
18878 - Follow the C89 standard and disable SDCC features that conflict with the
18887 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
18891 - Generally follow the C99 standard, but allow SDCC features that conflict
18892 with the standard (incomplete support).
18900 \begin_inset LatexCommand \index{\#pragma std\_c99}
18904 - Follow the C99 standard and disable SDCC features that conflict with the
18905 standard (incomplete support).
18913 \begin_inset LatexCommand \index{\#pragma codeseg}
18917 - Use this name (max.
18918 8 characters) for the code segment.
18937 \begin_inset LatexCommand \index{\#pragma constseg}
18941 - Use this name (max.
18942 8 characters) for the const segment.
18956 The preprocessor SDCPP
18957 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
18961 supports the following #pragma directives:
18966 pedantic_parse_number
18969 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18973 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
18974 parsed properly and the macro LO_B(3) gets expanded.
18976 Below is an example on how to use this pragma.
18979 Note: this functionality is not in conformance with standard!
18984 #pragma pedantic_parse_number +
18985 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18993 #define LO_B(x) ((x) & 0xff)
18997 unsigned char foo(void)
19004 unsigned char c=0xfe-LO_B(3);
19023 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19027 (+ | -) - switch _asm _endasm block preprocessing on / off.
19029 You use this prama to define multilines of assembly code.
19030 This will prevent the preprocessor from changing the formating required
19032 Below is an example on how to use this pragma.
19037 #pragma preproc_asm -
19038 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19044 #define MYDELAY _asm
19049 nop ;my assembly comment...
19063 #pragma preproc_asm +
19098 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19102 (+ | -) - Allow "naked" hash in macro definition, for example:
19106 #define DIR_LO(x) #(x & 0xff)
19111 Below is an example on how to use this pragma.
19116 #pragma preproc_asm +
19118 #pragma sdcc_hash +
19119 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19134 mov R6_B3, #(x & 0xff)
19141 mov R7_B3, #((x >> 8) & 0xff)
19165 The pragma's are intended to be used to turn-on or off certain optimizations
19166 which might cause the compiler to generate extra stack / data space to
19167 store compiler generated temporary variables.
19168 This usually happens in large functions.
19169 Pragma directives should be used as shown in the following example, they
19170 are used to control options & optimizations for a given function; pragmas
19171 should be placed before and/or after a function, placing pragma's inside
19172 a function body could have unpredictable results.
19178 \begin_inset LatexCommand \index{\#pragma save}
19189 /* save the current settings */
19192 \begin_inset LatexCommand \index{\#pragma nogcse}
19201 /* turnoff global subexpression elimination */
19203 #pragma noinduction
19204 \begin_inset LatexCommand \index{\#pragma noinduction}
19208 /* turn off induction optimizations */
19231 \begin_inset LatexCommand \index{\#pragma restore}
19235 /* turn the optimizations back on */
19238 The compiler will generate a warning message when extra space is allocated.
19239 It is strongly recommended that the save and restore pragma's be used when
19240 changing options for a function.
19249 Defines Created by the Compiler
19252 The compiler creates the following #defines
19253 \begin_inset LatexCommand \index{\#defines}
19258 \begin_inset LatexCommand \index{Defines created by the compiler}
19268 \begin_inset Tabular
19269 <lyxtabular version="3" rows="11" columns="2">
19271 <column alignment="left" valignment="top" leftline="true" width="3in">
19272 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
19273 <row topline="true" bottomline="true">
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19295 <row topline="true">
19296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19302 \begin_inset LatexCommand \index{SDCC}
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19315 Since version 2.5.6 the version number as an int (ex.
19320 <row topline="true">
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19327 \begin_inset LatexCommand \index{SDCC\_mcs51}
19332 \begin_inset LatexCommand \index{SDCC\_ds390}
19337 \begin_inset LatexCommand \index{SDCC\_z80}
19344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19349 depending on the model used (e.g.: -mds390)
19353 <row topline="true">
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_inset LatexCommand \index{\_\_mcs51}
19365 \begin_inset LatexCommand \index{\_\_ds390}
19370 \begin_inset LatexCommand \index{\_\_hc08}
19375 \begin_inset LatexCommand \index{\_\_z80}
19382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19387 depending on the model used (e.g.
19392 <row topline="true">
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19399 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19429 <row topline="true">
19430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19436 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19466 <row topline="true">
19467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19473 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19503 <row topline="true">
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19510 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
19517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19540 <row topline="true">
19541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19547 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
19554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19577 <row topline="true">
19578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19584 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
19591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19604 <row topline="true" bottomline="true">
19605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19611 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
19618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19638 Notes on supported Processors
19642 \begin_inset LatexCommand \label{sub:MCS51-variants}
19647 \begin_inset LatexCommand \index{MCS51 variants}
19654 MCS51 processors are available from many vendors and come in many different
19656 While they might differ considerably in respect to Special Function Registers
19657 the core MCS51 is usually not modified or is kept compatible.
19661 pdata access by SFR
19664 With the upcome of devices with internal xdata and flash memory devices
19666 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19670 as dedicated I/O port is becoming more popular.
19671 Switching the high byte for pdata
19672 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19676 access which was formerly done by port P2 is then achieved by a Special
19678 \begin_inset LatexCommand \index{sfr}
19683 In well-established MCS51 tradition the address of this
19687 is where the chip designers decided to put it.
19688 Needless to say that they didn't agree on a common name either.
19689 So that the startup code can correctly initialize xdata variables, you
19690 should define an sfr with the name _XPAGE
19693 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
19699 at the appropriate location if the default, port P2, is not used for this.
19705 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
19711 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
19718 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
19724 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
19730 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
19734 For more exotic implementations further customizations may be needed.
19736 \begin_inset LatexCommand \ref{sub:Startup-Code}
19740 for other possibilities.
19743 Other Features available by SFR
19745 \added_space_bottom bigskip
19746 Some MCS51 variants offer features like Double DPTR
19747 \begin_inset LatexCommand \index{DPTR}
19751 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19752 These are currently not used for the MCS51 port.
19753 If you absolutely need them you can fall back to inline assembly or submit
19759 \added_space_bottom bigskip
19761 \begin_inset LatexCommand \index{DS80C400}
19766 \begin_inset LatexCommand \index{DS400}
19770 microcontroller has a rich set of peripherals.
19771 In its built-in ROM library it includes functions to access some of the
19772 features, among them is a TCP stack with IP4 and IP6 support.
19773 Library headers (currently in beta status) and other files are provided
19777 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
19785 The Z80 and gbz80 port
19788 SDCC can target both the Zilog Z80
19789 \begin_inset LatexCommand \index{Z80}
19793 and the Nintendo Gameboy's Z80-like gbz80
19794 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19799 The Z80 port is passed through the same
19802 \begin_inset LatexCommand \index{Regression test}
19809 \begin_inset LatexCommand \ref{sec:Quality-control}
19813 ) as the MCS51 and DS390 ports, so floating point support, support for long
19814 variables and bitfield support is fine.
19815 See mailing lists and forums about interrupt routines.
19817 \added_space_bottom bigskip
19818 As always, the code is the authoritative reference - see z80/ralloc.c and
19821 \begin_inset LatexCommand \index{Z80!stack}
19825 frame is similar to that generated by the IAR Z80 compiler.
19826 IX is used as the base pointer, HL and IY are used as a temporary registers,
19827 and BC and DE are available for holding variables.
19829 \begin_inset LatexCommand \index{Z80!return value}
19833 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
19835 The gbz80 port use the same set of registers for the return values, but
19836 in a different order of significance: E (one byte), DE (two bytes), or
19843 The port to the Freescale/Motorola HC08
19844 \begin_inset LatexCommand \index{HC08}
19848 family has been added in October 2003, and is still undergoing some basic
19850 The code generator is complete, but the register allocation is still quite
19852 Some of the SDCC's standard C library functions have embedded non-HC08
19853 inline assembly and so are not yet usable.
19855 \added_space_bottom bigskip \pagebreak_bottom
19856 The HC08 port passes the regression test suite (see section
19857 \begin_inset LatexCommand \ref{sec:Quality-control}
19868 \begin_inset LatexCommand \index{PIC14}
19872 port still requires a major effort from the development community.
19873 However it can work for simple code.
19874 It passes its (smaller set of) regression tests
19875 \begin_inset LatexCommand \index{Regression test (PIC14)}
19881 sdcc/src/regression
19886 C code and 14bit PIC code page
19887 \begin_inset LatexCommand \index{code page (pic14)}
19892 \begin_inset LatexCommand \index{RAM bank (pic14)}
19899 The linker organizes allocation for the code page and RAM banks.
19900 It does not have intimate knowledge of the code flow.
19901 It will put all the code section of a single asm file into a single code
19903 In order to make use of multiple code pages, separate asm files must be
19905 The compiler treats all functions of a single C file as being in the same
19906 code page unless it is non static.
19910 To get the best follow these guide lines:
19913 Make local functions static, as non static functions require code page selection
19917 For devices that have multiple code pages it is more efficient to use the
19918 same number of files as pages, i.e.
19919 for the 16F877 use 4 separate files and i.e.
19920 for the 16F874 use 2 separate files.
19921 This way the linker can put the code for each file into different code
19922 pages and there's less page selection overhead.
19925 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19926 instruction set), use 'unsigned char' whereever possible instead of 'int'.
19929 Creating a device include file
19932 For generating a device include file
19933 \begin_inset LatexCommand \index{PIC14!Header files}
19937 use the support perl script inc2h.pl kept in directory support/script.
19943 For the interrupt function, use the keyword '__interrupt'
19944 \begin_inset LatexCommand \index{PIC14!interrupt}
19948 with level number of 0 (PIC14 only has 1 interrupt so this number is only
19949 there to avoid a syntax error - it ought to be fixed).
19955 void Intr(void) __interrupt 0
19961 T0IF = 0; /* Clear timer interrupt */
19966 Linking and assembling
19969 For assembling you can use either GPUTILS'
19970 \begin_inset LatexCommand \index{gputils (pic tools)}
19974 gpasm.exe or MPLAB's mpasmwin.exe.
19975 GPUTILS is available from
19976 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19981 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19982 If you use MPLAB and an interrupt function then the linker script file
19983 vectors section will need to be enlarged to link with mplink.
20006 sdcc -S -V -mpic14 -p16F877 $<
20020 $(PRJ).hex: $(OBJS)
20030 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
20052 sdcc -S -V -mpic14 -p16F877 $<
20062 mpasmwin /q /o $*.asm
20066 $(PRJ).hex: $(OBJS)
20076 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
20079 Please note that indentations within a
20083 have to be done with a tabulator character.
20086 Command-line options
20089 Besides the switches common to all SDCC backends, the PIC14 port accepts
20090 the following options (for an updated list see sdcc -
20102 \labelwidthstring 00.00.0000
20115 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
20119 emit debug info in assembly output
20121 \labelwidthstring 00.00.0000
20134 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
20138 disable (slightly faulty) optimization on pCode
20140 \labelwidthstring 00.00.0000
20153 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
20157 sets the lowest address of the argument passing stack (defaults to a suitably
20158 large shared databank to reduce BANKSEL overhead)
20160 \labelwidthstring 00.00.0000
20173 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
20177 sets the size if the argument passing stack (default: 16, minimum: 4)
20181 \layout Subsubsection
20183 error: missing definition for symbol
20184 \begin_inset Quotes sld
20188 \begin_inset Quotes srd
20194 The PIC14 port uses library routines to provide more complex operations
20195 like multiplication, division/modulus and (generic) pointer dereferencing.
20196 In order to add these routines to your project, you must link with PIC14's
20202 For single source file projects this is done automatically, more complex
20207 to the linker's arguments.
20208 Make sure you also add an include path for the library (using the -I switch
20210 \layout Subsubsection
20212 Processor mismatch in file
20213 \begin_inset Quotes sld
20217 \begin_inset Quotes srd
20223 This warning can usually be ignored due to the very good compatibility amongst
20225 \begin_inset LatexCommand \index{PIC14}
20232 You might also consider recompiling the library for your specific device
20233 by changing the ARCH=p16f877 (default target) entry in
20235 device/lib/pic/Makefile.in
20239 device/lib/pic/Makefile
20241 to reflect your device.
20242 This might even improve performance for smaller devices as unneccesary
20243 BANKSELs migth be removed.
20247 \layout Subsubsection
20252 Currently, data can only be initialized if it resides in the source file
20258 Data in other source files will silently
20266 \begin_inset Marginal
20281 \begin_inset LatexCommand \index{PIC16}
20289 \begin_inset LatexCommand \index{PIC16}
20293 port is the portion of SDCC that is responsible to produce code for the
20295 \begin_inset LatexCommand \index{Microchip}
20299 (TM) microcontrollers with 16 bit core.
20300 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20301 Currently supported devices are:
20305 \begin_inset Tabular
20306 <lyxtabular version="3" rows="4" columns="6">
20308 <column alignment="center" valignment="top" leftline="true" width="0">
20309 <column alignment="center" valignment="top" leftline="true" width="0">
20310 <column alignment="center" valignment="top" leftline="true" width="0">
20311 <column alignment="center" valignment="top" leftline="true" width="0">
20312 <column alignment="center" valignment="top" leftline="true" width="0">
20313 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20314 <row topline="true">
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20364 <row topline="true">
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20414 <row topline="true">
20415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20464 <row topline="true" bottomline="true">
20465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20521 PIC16 port supports the standard command line arguments as supposed, with
20522 the exception of certain cases that will be mentioned in the following
20525 \labelwidthstring 00.00.0000
20538 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
20554 \labelwidthstring 00.00.0000
20567 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
20571 All function arguments are passed on stack by default.
20574 There is no need to specify this in the command line.
20576 \labelwidthstring 00.00.0000
20588 -fommit-frame-pointer
20589 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
20593 Frame pointer will be omitted when the function uses no local variables.
20596 Port Specific Options
20597 \begin_inset LatexCommand \index{Options PIC16}
20604 The port specific options appear after the global options in the sdcc --help
20606 \layout Subsubsection
20611 General options enable certain port features and optimizations.
20613 \labelwidthstring 00.00.0000
20625 -pstack-model=[model] Used in conjuction with the command above.
20626 Defines the stack model to be used, valid stack models are :
20629 \labelwidthstring 00.00.0000
20635 Selects small stack model.
20636 8 bit stack and frame pointers.
20637 Supports 256 bytes stack size.
20639 \labelwidthstring 00.00.0000
20645 Selects large stack model.
20646 16 bit stack and frame pointers.
20647 Supports 65536 bytes stack size.
20650 \labelwidthstring 00.00.0000
20662 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
20663 unitialized data variables with [kword].
20664 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
20666 \labelwidthstring 00.00.0000
20678 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
20679 Useful for bootloaders.
20681 \labelwidthstring 00.00.0000
20693 -asm= sets the full path and name of an external assembler to call.
20695 \labelwidthstring 00.00.0000
20707 -link= sets the full path and name of an external linker to call.
20709 \labelwidthstring 00.00.0000
20722 \begin_inset LatexCommand \index{PIC16!MPLAB}
20726 compatibility option.
20727 Currently only suppresses special gpasm directives.
20728 \layout Subsubsection
20730 Optimization Options
20732 \labelwidthstring 00.00.0000
20744 -optimize-goto Try to use (conditional) BRA instead of GOTO
20746 \labelwidthstring 00.00.0000
20758 -optimize-cmp Try to optimize some compares.
20760 \labelwidthstring 00.00.0000
20772 -optimize-df Analyze the dataflow of the generated code and improve it.
20774 \labelwidthstring 00.00.0000
20786 -obanksel=nn Set optimization level for inserting BANKSELs.
20791 \labelwidthstring 00.00.0000
20795 \labelwidthstring 00.00.0000
20797 1 checks previous used register and if it is the same then does not emit
20798 BANKSEL, accounts only for labels.
20800 \labelwidthstring 00.00.0000
20802 2 tries to check the location of (even different) symbols and removes BANKSELs
20803 if they are in the same bank.
20808 Important: There might be problems if the linker script has data sections
20809 across bank borders!
20811 \layout Subsubsection
20815 \labelwidthstring 00.00.0000
20827 -nodefaultlibs do not link default libraries when linking
20829 \labelwidthstring 00.00.0000
20841 -no-crt Don't link the default run-time modules
20843 \labelwidthstring 00.00.0000
20855 -use-crt= Use a custom run-time module instead of the defaults.
20856 \layout Subsubsection
20861 Debugging options enable extra debugging information in the output files.
20863 \labelwidthstring 00.00.0000
20875 -debug-xtra Similar to -
20886 \begin_inset LatexCommand \index{-\/-debug}
20890 , but dumps more information.
20892 \labelwidthstring 00.00.0000
20904 -debug-ralloc Force register allocator to dump <source>.d file with debugging
20906 <source> is the name of the file compiled.
20908 \labelwidthstring 00.00.0000
20920 -pcode-verbose Enable pcode debugging information in translation.
20922 \labelwidthstring 00.00.0000
20934 -denable-peeps Force the usage of peepholes.
20937 \labelwidthstring 00.00.0000
20949 -gstack Trace push/pops for stack pointer overflow
20951 \labelwidthstring 00.00.0000
20963 -call-tree dump call tree in .calltree file
20966 Enviromental Variables
20969 There is a number of enviromental variables that can be used when running
20970 SDCC to enable certain optimizations or force a specific program behaviour.
20971 these variables are primarily for debugging purposes so they can be enabled/dis
20975 Currently there is only two such variables available:
20977 \labelwidthstring 00.00.0000
20979 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
20980 bitfields is optimized by directly loading FSR0 with the address of the
20981 bitfield structure.
20982 Normally SDCC will cast the bitfield structure to a bitfield pointer and
20984 This step saves data ram and code space for functions that perform heavy
20987 80 bytes of code space are saved when compiling malloc.c with this option).
20990 \labelwidthstring 00.00.0000
20992 NO_REG_OPT do not perform pCode registers optimization.
20993 This should be used for debugging purposes.
20994 In some where bugs in the pcode optimizer are found, users can benefit
20995 from temporarily disabling the optimizer until the bug is fixed.
20998 Preprocessor Macros
21002 \begin_inset LatexCommand \index{PIC16}
21006 port defines the following preprocessor macros while translating a source.
21010 \begin_inset Tabular
21011 <lyxtabular version="3" rows="6" columns="2">
21013 <column alignment="center" valignment="top" leftline="true" width="0">
21014 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21015 <row topline="true" bottomline="true">
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21033 <row topline="true">
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21047 Port identification
21051 <row topline="true">
21052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21075 Port identification (same as above)
21079 <row topline="true">
21080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21093 MCU Identification.
21098 is the microcontrol identification number, i.e.
21103 <row topline="true">
21104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21127 MCU Identification (same as above)
21131 <row topline="true" bottomline="true">
21132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21145 nnn = SMALL or LARGE respectively according to the stack model used
21156 In addition the following macros are defined when calling assembler:
21160 \begin_inset Tabular
21161 <lyxtabular version="3" rows="4" columns="2">
21163 <column alignment="center" valignment="top" leftline="true" width="0">
21164 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21165 <row topline="true" bottomline="true">
21166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21183 <row topline="true">
21184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21197 MCU Identification.
21202 is the microcontrol identification number, i.e.
21207 <row topline="true">
21208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21221 nnn = SMALL or LARGE respectively according to the memory model used for
21226 <row topline="true" bottomline="true">
21227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21240 nnn = SMALL or LARGE respectively according to the stack model used
21255 \begin_inset LatexCommand \index{PIC16}
21259 port uses the following directories for searching header files and libraries.
21263 \begin_inset Tabular
21264 <lyxtabular version="3" rows="3" columns="4">
21266 <column alignment="center" valignment="top" leftline="true" width="0">
21267 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21268 <column alignment="center" valignment="top" width="0">
21269 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21270 <row topline="true" bottomline="true">
21271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21304 <row topline="true">
21305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21310 PREFIX/sdcc/include/pic16
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21318 PIC16 specific headers
21321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21338 <row topline="true" bottomline="true">
21339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21344 PREFIX/sdcc/lib/pic16
21347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21352 PIC16 specific libraries
21355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21380 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
21388 \begin_inset LatexCommand \index{PIC16}
21392 port currently supports the following pragmas:
21394 \labelwidthstring 00.00.0000
21397 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
21402 \begin_inset LatexCommand \index{PIC16!stack}
21406 forces the code generator to initialize the stack & frame pointers at a
21408 This is an adhoc solution for cases where no STACK directive is available
21409 in the linker script or gplink is not instructed to create a stack section.
21411 The stack pragma should be used only once in a project.
21412 Multiple pragmas may result in indeterminate behaviour of the program.
21418 The old format (ie.
21419 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
21420 cross page boundaries (or even exceed the available data RAM) and crash
21422 Make sure that stack does not cross page boundaries when using the SMALL
21428 The format is as follows:
21431 #pragma stack bottom_address [stack_size]
21438 is the lower bound of the stack section.
21439 The stack pointer initially will point at address (bottom_address+stack_size-1).
21447 /* initializes stack of 100 bytes at RAM address 0x200 */
21450 #pragma stack 0x200 100
21453 If the stack_size field is omitted then a stack is created with the default
21455 This size might be enough for most programs, but its not enough for operations
21456 with deep function nesting or excessive stack usage.
21458 \labelwidthstring 00.00.0000
21461 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
21465 place a function symbol at static FLASH address
21473 /* place function test_func at 0x4000 */
21476 #pragma code test_func 0x4000
21480 \labelwidthstring 00.00.0000
21482 library instructs the linker to use a library module.
21487 #pragma library module_name
21494 can be any library or object file (including its path).
21495 Note that there are four reserved keywords which have special meaning.
21500 \begin_inset Tabular
21501 <lyxtabular version="3" rows="6" columns="3">
21503 <column alignment="center" valignment="top" leftline="true" width="0">
21504 <column alignment="block" valignment="top" leftline="true" width="20page%">
21505 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
21506 <row topline="true" bottomline="true">
21507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21532 <row topline="true">
21533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21548 ignore all library pragmas
21551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21562 <row topline="true">
21563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21594 <row topline="true">
21595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21610 link the Math libarary
21613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21626 <row topline="true">
21627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21642 link the I/O library
21645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21658 <row topline="true" bottomline="true">
21659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21674 link the debug library
21677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21696 * is the device number, i.e.
21697 452 for PIC18F452 MCU.
21700 This feature allows for linking with specific libraries withoug having to
21701 explicit name them in the command line.
21706 keyword will reject all modules specified by the library pragma.
21708 \labelwidthstring 00.00.0000
21710 udata pragma udata instructs the compiler to emit code so that linker will
21711 place a variable at a specific memory bank
21719 /* places variable foo at bank2 */
21722 #pragma udata bank2 foo
21728 In order for this pragma to work extra SECTION directives should be added
21729 in the .lkr script.
21730 In the following example a sample .lkr file is shown:
21735 // Sample linker script for the PIC18F452 processor
21741 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
21744 CODEPAGE NAME=page START=0x2A END=0x7FFF
21747 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
21750 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
21753 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
21756 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
21759 ACCESSBANK NAME=accessram START=0x0 END=0x7F
21764 DATABANK NAME=gpr0 START=0x80 END=0xFF
21767 DATABANK NAME=gpr1 START=0x100 END=0x1FF
21770 DATABANK NAME=gpr2 START=0x200 END=0x2FF
21773 DATABANK NAME=gpr3 START=0x300 END=0x3FF
21776 DATABANK NAME=gpr4 START=0x400 END=0x4FF
21779 DATABANK NAME=gpr5 START=0x500 END=0x5FF
21782 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
21787 SECTION NAME=CONFIG ROM=config
21792 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
21795 SECTION NAME=bank1 RAM=gpr1 # should be added to link
21798 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
21801 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
21804 SECTION NAME=bank4 RAM=gpr4
21807 SECTION NAME=bank5 RAM=gpr5
21810 The linker will recognise the section name set in the pragma statement and
21811 will position the variable at the memory bank set with the RAM field at
21812 the SECTION line in the linker script file.
21816 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
21823 There is one main header file
21824 \begin_inset LatexCommand \index{PIC16!Header files}
21828 that can be included to the source files using the pic16
21829 \begin_inset LatexCommand \index{PIC16}
21839 This header file contains the definitions for the processor special registers,
21840 so it is necessary if the source accesses them.
21841 It can be included by adding the following line in the beginning of the
21845 #include <pic18fregs.h>
21848 The specific microcontroller is selected within the pic18fregs.h automatically,
21849 so the same source can be used with a variety of devices.
21856 \begin_inset LatexCommand \index{PIC16!Libraries}
21861 \begin_inset LatexCommand \index{PIC16}
21865 port depends on are the microcontroller device libraries which contain
21866 the symbol definitions for the microcontroller special function registers.
21867 These libraries have the format pic18fxxxx.lib, where
21871 is the microcontroller identification number.
21872 The specific library is selected automatically by the compiler at link
21873 stage according to the selected device.
21876 Libraries are created with gplib which is part of the gputils package
21877 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21882 \layout Subsubsection*
21884 Building the libraries
21887 Before using SDCC/pic16 there are some libraries that need to be compiled.
21888 This process is not done automatically by SDCC since not all users use
21889 SDCC for pic16 projects.
21890 So each user should compile the libraries separately.
21893 The steps to compile the pic16 libraries under Linux are:
21896 cd device/lib/pic16
21911 su -c 'make install' # install the libraries, you need the root password
21914 If you need to install the headers too, do:
21920 su -c 'make install' # install the headers, you need the root password
21923 There exist a special target to build the I/O libraries.
21924 This target is not automatically build because it will build the I/O library
21930 This way building will take quite a lot of time.
21931 Users are advised to edit the
21933 device/lib/pic16/pics.build
21935 file and then execute:
21944 The following memory models are supported by the PIC16 port:
21953 Memory model affects the default size of pointers within the source.
21954 The sizes are shown in the next table:
21958 \begin_inset Tabular
21959 <lyxtabular version="3" rows="3" columns="3">
21961 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21962 <column alignment="center" valignment="top" leftline="true" width="0">
21963 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21964 <row topline="true" bottomline="true">
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21970 Pointer sizes according to memory model
21973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21990 <row topline="true" bottomline="true">
21991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21999 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22016 <row topline="true" bottomline="true">
22017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22025 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
22033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22049 It is advisable that all sources within a project are compiled with the
22051 If one wants to override the default memory model, this can be done by
22052 declaring a pointer as
22061 Far selects large memory model's pointers, while near selects small memory
22065 The standard device libraries (see
22066 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
22070 ) contain no reference to pointers, so they can be used with both memory
22078 \begin_inset LatexCommand \index{PIC16!stack}
22082 implementation for the PIC16 port uses two indirect registers, FSR1 and
22085 \labelwidthstring 00.00.0000
22087 FSR1 is assigned as stack pointer
22089 \labelwidthstring 00.00.0000
22091 FSR2 is assigned as frame pointer
22094 The following stack models are supported by the PIC16 port
22115 model means that only the FSRxL byte is used to access stack and frame,
22122 uses both FSRxL and FSRxH registers.
22123 The following table shows the stack/frame pointers sizes according to stack
22124 model and the maximum space they can address:
22128 \begin_inset Tabular
22129 <lyxtabular version="3" rows="3" columns="3">
22131 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22132 <column alignment="center" valignment="top" leftline="true" width="0">
22133 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22134 <row topline="true" bottomline="true">
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22140 Stack & Frame pointer sizes according to stack model
22143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22160 <row topline="true">
22161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22186 <row topline="true" bottomline="true">
22187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22223 stack model is currently not working properly throughout the code generator.
22224 So its use is not advised.
22225 Also there are some other points that need special care:
22230 Do not create stack sections with size more than one physical bank (that
22234 Stack sections should no cross physical bank limits (i.e.
22235 #pragma stack 0x50 0x100)
22238 These limitations are caused by the fact that only FSRxL is modified when
22239 using SMALL stack model, so no more than 256 bytes of stack can be used.
22240 This problem will disappear after LARGE model is fully implemented.
22246 In addition to the standard SDCC function keywords, PIC16
22247 \begin_inset LatexCommand \index{PIC16}
22251 port makes available two more:
22253 \labelwidthstring 00.00.0000
22256 \begin_inset LatexCommand \index{PIC16!wparam}
22260 Use the WREG to pass one byte of the first function argument.
22261 This improves speed but you may not use this for functions with arguments
22262 that are called via function pointers, otherwise the first byte of the
22263 first parameter will get lost.
22267 void func_wparam(int a) wparam
22273 /* WREG hold the lower part of a */
22276 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22285 \labelwidthstring 00.00.0000
22288 \begin_inset LatexCommand \index{PIC16!shadowregs}
22292 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22293 hardware shadow registers which hold the values of WREG, STATUS and BSR
22295 This can be done by adding the keyword
22303 keyword in the function's header.
22306 void isr_shadow(void) shadowregs interrupt 1
22322 instructs the code generator not to store/restore WREG, STATUS, BSR when
22323 entering/exiting the ISR.
22326 Function return values
22329 Return values from functions are placed to the appropriate registers following
22330 a modified Microchip policy optimized for SDCC.
22331 The following table shows these registers:
22335 \begin_inset Tabular
22336 <lyxtabular version="3" rows="6" columns="2">
22338 <column alignment="center" valignment="top" leftline="true" width="0">
22339 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22340 <row topline="true" bottomline="true">
22341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22354 destination register
22358 <row topline="true">
22359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22376 <row topline="true">
22377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22394 <row topline="true">
22395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22412 <row topline="true">
22413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22426 FSR0L:PRODH:PRODL:WREG
22430 <row topline="true" bottomline="true">
22431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22444 on stack, FSR0 points to the beginning
22459 \begin_inset LatexCommand \index{PIC16!interrupt}
22463 service routine (ISR) is declared using the
22470 void isr(void) interrupt
22488 is the interrupt number, which for PIC18F devices can be:
22492 \begin_inset Tabular
22493 <lyxtabular version="3" rows="4" columns="3">
22495 <column alignment="center" valignment="top" leftline="true" width="0">
22496 <column alignment="center" valignment="top" leftline="true" width="0">
22497 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22498 <row topline="true" bottomline="true">
22499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22522 Interrupt Vector Address
22526 <row topline="true">
22527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22552 <row topline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22584 HIGH priority interrupts
22587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22596 <row topline="true" bottomline="true">
22597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22610 LOW priority interrupts
22613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22629 When generating assembly code for ISR the code generator places a
22635 Interrupt Vector Address
22637 which points at the genetated ISR.
22638 This single GOTO instruction is part of an automatically generated
22640 interrupt entry point
22643 The actuall ISR code is placed as normally would in the code space.
22644 Upon interrupt request, the GOTO instruction is executed which jumps to
22646 When declaring interrupt functions as _naked this GOTO instruction is
22651 The whole interrupt functions is therefore placed at the Interrupt Vector
22652 Address of the specific interrupt.
22653 This is not a problem for the LOW priority interrupts, but it is a problem
22654 for the RESET and the HIGH priority interrupts because code may be written
22655 at the next interrupt´s vector address and cause undeterminate program
22656 behaviour if that interrupt is raised.
22662 This is not a problem when
22665 this is a HIGH interrupt ISR and LOW interrupts are
22672 when the ISR is small enough not to reach the next interrupt´s vector address.
22682 is possible to be omitted.
22683 This way a function is generated similar to an ISR, but it is not assigned
22687 When entering an interrupt, currently the PIC16
22688 \begin_inset LatexCommand \index{PIC16}
22692 port automatically saves the following registers:
22704 PROD (PRODL and PRODH)
22707 FSR0 (FSR0L and FSR0H)
22710 These registers are restored upon return from the interrupt routine.
22716 NOTE that when the _naked attribute is specified for an interrupt routine,
22717 then NO registers are stored or restored.
22726 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
22727 There are 3 types of generic pointers currently implemented data, code
22728 and eeprom pointers.
22729 They are differentiated by the value of the 7th and 6th bits of the upper
22734 \begin_inset Tabular
22735 <lyxtabular version="3" rows="5" columns="5">
22737 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22738 <column alignment="center" valignment="top" width="0">
22739 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22740 <column alignment="center" valignment="top" width="0">
22741 <column alignment="left" valignment="top" rightline="true" width="0">
22742 <row topline="true" bottomline="true">
22743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22772 rest of the pointer
22775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22784 <row topline="true" bottomline="true">
22785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22818 uuuuuu uuuuxxxx xxxxxxxx
22821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22826 a 12-bit data pointer in data RAM memory
22830 <row bottomline="true">
22831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22864 uxxxxx xxxxxxxx xxxxxxxx
22867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22872 a 21-bit code pointer in FLASH memory
22876 <row bottomline="true">
22877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22910 uuuuuu uuuuuuxx xxxxxxxx
22913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22918 a 10-bit eeprom pointer in EEPROM memory
22922 <row bottomline="true">
22923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22956 xxxxxx xxxxxxxx xxxxxxxx
22959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22964 unimplemented pointer type
22975 Generic pointer are read and written with a set of library functions which
22976 read/write 1, 2, 3, 4 bytes.
22980 \layout Subsubsection
22982 Standard I/O Streams
22989 the type FILE is defined as:
22992 typedef char * FILE;
22995 This type is the stream type implemented I/O in the PIC18F devices.
22996 Also the standard input and output streams are declared in stdio.h:
22999 extern FILE * stdin;
23002 extern FILE * stdout;
23005 The FILE type is actually a generic pointer which defines one more type
23006 of generic pointers, the
23011 This new type has the format:
23015 \begin_inset Tabular
23016 <lyxtabular version="3" rows="2" columns="7">
23018 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23019 <column alignment="center" valignment="top" width="0">
23020 <column alignment="center" valignment="top" leftline="true" width="0">
23021 <column alignment="center" valignment="top" leftline="true" width="0">
23022 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23023 <column alignment="center" valignment="top" width="0">
23024 <column alignment="left" valignment="top" rightline="true" width="0">
23025 <row topline="true" bottomline="true">
23026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23071 rest of the pointer
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23083 <row topline="true" bottomline="true">
23084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23141 upper byte high nubble is 0x2n, the rest are zeroes
23152 Currently implemented there are 3 types of streams defined:
23156 \begin_inset Tabular
23157 <lyxtabular version="3" rows="4" columns="4">
23159 <column alignment="center" valignment="top" leftline="true" width="0">
23160 <column alignment="center" valignment="top" leftline="true" width="0">
23161 <column alignment="center" valignment="top" leftline="true" width="0">
23162 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23163 <row topline="true" bottomline="true">
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23197 <row topline="true">
23198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23229 Writes/Reads characters via the USART peripheral
23233 <row topline="true">
23234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23265 Writes/Reads characters via the MSSP peripheral
23269 <row topline="true" bottomline="true">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23301 Writes/Reads characters via used defined functions
23312 The stream identifiers are declared as macros in the stdio.h header.
23315 In the libc library there exist the functions that are used to write to
23316 each of the above streams.
23319 \labelwidthstring 00.00.0000
23331 _stream_usart_putchar writes a character at the USART stream
23333 \labelwidthstring 00.00.0000
23345 _stream_mssp_putchar writes a character at the MSSP stream
23347 \labelwidthstring 00.00.0000
23349 putchar dummy function.
23350 This writes a character to a user specified manner.
23353 In order to increase performance
23357 is declared in stdio.h as having its parameter in WREG (it has the wparam
23359 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
23360 in a user-friendly way.
23365 is the name of the variable that holds the character to print.
23366 An example follows:
23369 #include <pic18fregs.h>
23381 PORTA = c; /* dump character c to PORTA */
23394 stdout = STREAM_USER; /* this is not necessary, since stdout points
23397 * by default to STREAM_USER */
23400 printf (¨This is a printf test
23408 \layout Subsubsection
23413 PIC16 contains an implementation of the printf-family of functions.
23414 There exist the following functions:
23417 extern unsigned int sprintf(char *buf, char *fmt, ...);
23420 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
23425 extern unsigned int printf(char *fmt, ...);
23428 extern unsigned int vprintf(char *fmt, va_lista ap);
23433 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
23436 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
23439 For sprintf and vsprintf
23443 should normally be a data pointer where the resulting string will be placed.
23444 No range checking is done so the user should allocate the necessery buffer.
23445 For fprintf and vfprintf
23449 should be a stream pointer (i.e.
23450 stdout, STREAM_MSSP, etc...).
23451 \layout Subsubsection
23456 The PIC18F family of microcontrollers supports a number of interrupt sources.
23457 A list of these interrupts is shown in the following table:
23461 \begin_inset Tabular
23462 <lyxtabular version="3" rows="11" columns="4">
23464 <column alignment="left" valignment="top" leftline="true" width="0">
23465 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23466 <column alignment="left" valignment="top" leftline="true" width="0">
23467 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23468 <row topline="true" bottomline="true">
23469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23502 <row topline="true">
23503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23511 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23516 PORTB change interrupt
23519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23532 EEPROM/FLASH write complete interrupt
23536 <row topline="true">
23537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23550 INT0 external interrupt
23553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23566 Bus collision interrupt
23570 <row topline="true">
23571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23584 INT1 external interrupt
23587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23600 Low voltage detect interrupt
23604 <row topline="true">
23605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23618 INT2 external interrupt
23621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23634 Parallel slave port interrupt
23638 <row topline="true">
23639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23652 CCP1 module interrupt
23655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23668 AD convertion complete interrupt
23672 <row topline="true">
23673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23686 CCP2 module interrupt
23689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23702 USART receive interrupt
23706 <row topline="true">
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23720 TMR0 overflow interrupt
23723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23736 USART transmit interrupt
23740 <row topline="true">
23741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23754 TMR1 overflow interrupt
23757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23770 SSP receive/transmit interrupt
23774 <row topline="true">
23775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23788 TMR2 matches PR2 interrupt
23791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23806 <row topline="true" bottomline="true">
23807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23820 TMR3 overflow interrupt
23823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23845 The prototypes for these names are defined in the header file
23852 In order to simplify signal handling, a number of macros is provided:
23854 \labelwidthstring 00.00.0000
23856 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
23857 high priority interrupts.
23862 is the function name to use.
23864 \labelwidthstring 00.00.0000
23866 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
23867 low priority interrupt.
23872 is the function name to use.
23874 \labelwidthstring 00.00.0000
23876 DEF_HANDLER(sig,handler) define a handler for signal
23880 \labelwidthstring 00.00.0000
23882 END_DEF end the declaration of the dispatch table.
23885 Additionally there are two more macros to simplify the declaration of the
23888 \labelwidthstring 00.00.0000
23892 SIGHANDLER(handler)
23894 this declares the function prototype for the
23900 \labelwidthstring 00.00.0000
23902 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
23905 An example of using the macros above is shown below:
23908 #include <pic18fregs.h>
23911 #include <signal.h>
23915 DEF_INTHIGH(high_int)
23918 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
23921 DEF_HANDLER(SIG_BCOL, _bcol_handler)
23928 SIGHANDLER(_tmr0_handler)
23934 /* action to be taken when timer 0 overflows */
23941 SIGHANDLERNAKED(_bcol_handler)
23950 /* action to be taken when bus collision occurs */
23966 Special care should be taken when using the above scheme:
23969 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
23972 when declaring SIGHANDLERNAKED handler never forget to use
23976 for proper returning.
23982 Here you can find some general tips for compiling programs with SDCC/pic16.
23983 \layout Subsubsection
23989 \begin_inset LatexCommand \index{PIC16!stack}
23993 size (that is 64 bytes) probably is enough for many programs.
23994 One must take care that when there are many levels of function nesting,
23995 or there is excessive usage of stack, its size should be extended.
23996 An example of such a case is the printf/sprintf family of functions.
23997 If you encounter problems like not being able to print integers, then you
23998 need to set the stack size around the maximum (256 for small stack model).
23999 The following diagram shows what happens when calling printf to print an
24003 printf () --> ltoa () --> ultoa () --> divschar ()
24006 It is should be understood that stack is easily consumed when calling complicate
24008 Using command line arguments like -
24018 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
24020 Other ways to reduce stack usage may exist.
24026 The PIC16 Port currently does not pass SDCC's regression test
24027 \begin_inset LatexCommand \index{Regression test (PIC16)}
24032 \begin_inset LatexCommand \ref{sec:Quality-control}
24036 ) and thus the nightly regression tests for the PIC16 target are currently
24037 disabled for all hosts except for
24042 This means you can see the result of the PIC16 regression tests f.e.
24043 by checking the log files in
24044 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
24048 (pick the most up to date file there, scroll down, lend a hand).
24054 There are several approaches to debugging your code.
24055 This chapter is meant to show your options and to give detail on some of
24060 When writing your code:
24063 write your code with debugging in mind (avoid duplicating code, put conceptually
24064 similar variables into structs, use structured code, have strategic points
24065 within your code where all variables are consistent, ...)
24068 run a syntax-checking tool like splint
24069 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24074 \begin_inset LatexCommand \index{lint (syntax checking tool)}
24089 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24096 for the high level code use a C-compiler (like f.e.
24097 GCC) to compile run and debug the code on your host.
24109 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24113 ) on howto handle syntax extensions like __xdata, __at(), ...
24117 use another C-compiler to compile code for your target.
24118 Always an option but not recommended:) And not very likely to help you.
24119 If you seriously consider walking this path you should at least occasionally
24120 check portability of your code.
24121 Most commercial compiler vendors will offer an evaluation version so you
24122 can test compile your code or snippets of your code.
24125 Debugging on a simulator:
24128 there is a separate section about SDCDB (section
24129 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
24136 or (8051 specific) use a freeware/commercial simulator which interfaces
24138 \begin_inset LatexCommand \index{AOMF, AOMF51}
24143 \begin_inset LatexCommand \ref{OMF file}
24147 ) optionally generated by SDCC.
24150 Debugging On-target:
24153 use a MCU port pin to serially output debug data to the RS232 port of your
24155 You'll probably want some level shifting device typically involving a MAX232
24157 If the hardware serial port of the MCU is not available search for 'Software
24158 UART' in your favourite search machine.
24161 use an on-target monitor.
24162 In this context a monitor is a small program which usually accepts commands
24163 via a serial line and allows to set program counter, to single step through
24164 a program and read/write memory locations.
24165 For the 8051 good examples of monitors are paulmon and cmon51 (see section
24167 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
24174 toggle MCU port pins at strategic points within your code and use an oscilloscop
24178 digital oscilloscope
24181 \begin_inset LatexCommand \index{Oscilloscope}
24185 with deep trace memory is really helpful especially if you have to debug
24186 a realtime application.
24187 If you need to monitor more pins than your oscilloscope provides you can
24188 sometimes get away with a small R-2R network.
24189 On a single channel oscilloscope you could f.e.
24190 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24192 \begin_inset Formula $\Omega$
24195 resistor and the other one by a 5\SpecialChar ~
24197 \begin_inset Formula $\Omega$
24200 resistor to the oscilloscope probe (check output drive capability of the
24201 pins you want to monitor).
24202 If you need to monitor many more pins a
24222 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24227 Usually very expensive.
24228 And very nice to have too.
24229 And usually locks you (for years...) to the devices the ICE can emulate.
24233 use a remote debugger.
24234 In most 8-bit systems the symbol information is not available on the target,
24235 and a complete debugger is too bulky for the target system.
24236 Therefore usually a debugger on the host system connects to an on-target
24237 debugging stub which accepts only primitive commands.
24240 Terms to enter into your favourite search engine could be 'remote debugging',
24241 'gdb stub' or 'inferior debugger'.
24245 use an on target hardware debugger.
24246 Some of the more modern MCUs include hardware support for setting break
24247 points and monitoring/changing variables by using dedicated hardware pins.
24248 This facility doesn't require additional code to run on the target and
24253 doesn't affect runtime behaviour until a breakpoint is hit.
24254 For the mcs51 most hardware debuggers use the AOMF
24255 \begin_inset LatexCommand \index{AOMF, AOMF51}
24260 \begin_inset LatexCommand \ref{OMF file}
24271 if you are not familiar with any of the following terms you're likely to
24272 run into problems rather sooner than later:
24289 As an embedded programmer you
24293 to know them so why not look them up
24297 you have problems?)
24300 tell someone else about your problem (actually this is a surprisingly effective
24301 means to hunt down the bug even if the listener is not familiar with your
24303 As 'failure to communicate' is probably one of the job-induced deformations
24304 of an embedded programmer this is highly encouraged.
24307 Debugging with SDCDB
24308 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24313 \begin_inset LatexCommand \index{SDCDB (debugger)}
24320 SDCC is distributed with a source level debugger
24321 \begin_inset LatexCommand \index{Debugger}
24326 The debugger uses a command line interface, the command repertoire of the
24327 debugger has been kept as close to gdb
24328 \begin_inset LatexCommand \index{gdb}
24332 (the GNU debugger) as possible.
24333 The configuration and build process is part of the standard compiler installati
24334 on, which also builds and installs the debugger in the target directory
24335 specified during configuration.
24336 The debugger allows you debug BOTH at the C source and at the ASM source
24340 Compiling for Debugging
24354 \begin_inset LatexCommand \index{-\/-debug}
24358 option must be specified for all files for which debug information is to
24360 The compiler generates a .adb file for each of these files.
24361 The linker creates the .cdb
24362 \begin_inset LatexCommand \index{<file>.cdb}
24367 \begin_inset LatexCommand \index{<file>.adb}
24371 files and the address information.
24372 This .cdb is used by the debugger.
24375 How the Debugger Works
24388 -debug option is specified the compiler generates extra symbol information
24389 some of which are put into the assembler source and some are put into the
24391 Then the linker creates the .cdb file from the individual .adb files with
24392 the address information for the symbols.
24393 The debugger reads the symbolic information generated by the compiler &
24394 the address information generated by the linker.
24395 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
24396 execution is controlled by the debugger.
24397 When a command is issued for the debugger, it translates it into appropriate
24398 commands for the simulator.
24399 (Currently SDCDM only connects to the simulator but
24404 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
24408 is an effort to connect directly to the hardware.)
24411 Starting the Debugger SDCDB
24414 The debugger can be started using the following command line.
24415 (Assume the file you are debugging has the file name foo).
24429 The debugger will look for the following files.
24432 foo.c - the source file.
24435 foo.cdb - the debugger symbol information file.
24438 foo.ihx - the Intel hex format
24439 \begin_inset LatexCommand \index{Intel hex format}
24446 SDCDB Command Line Options
24459 -directory=<source file directory> this option can used to specify the directory
24461 The debugger will look into the directory list specified for source, cdb
24463 The items in the directory list must be separated by ':', e.g.
24464 if the source files can be in the directories /home/src1 and /home/src2,
24475 -directory option should be -
24485 -directory=/home/src1:/home/src2.
24486 Note there can be no spaces in the option.
24490 -cd <directory> - change to the <directory>.
24493 -fullname - used by GUI front ends.
24496 -cpu <cpu-type> - this argument is passed to the simulator please see the
24497 simulator docs for details.
24500 -X <Clock frequency > this options is passed to the simulator please see
24501 the simulator docs for details.
24504 -s <serial port file> passed to simulator see the simulator docs for details.
24507 -S <serial in,out> passed to simulator see the simulator docs for details.
24510 -k <port number> passed to simulator see the simulator docs for details.
24513 SDCDB Debugger Commands
24516 As mentioned earlier the command interface for the debugger has been deliberatel
24517 y kept as close the GNU debugger gdb, as possible.
24518 This will help the integration with existing graphical user interfaces
24519 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
24520 If you use a graphical user interface for the debugger you can skip this
24522 \layout Subsubsection*
24524 break [line | file:line | function | file:function]
24527 Set breakpoint at specified line or function:
24536 sdcdb>break foo.c:100
24538 sdcdb>break funcfoo
24540 sdcdb>break foo.c:funcfoo
24541 \layout Subsubsection*
24543 clear [line | file:line | function | file:function ]
24546 Clear breakpoint at specified line or function:
24555 sdcdb>clear foo.c:100
24557 sdcdb>clear funcfoo
24559 sdcdb>clear foo.c:funcfoo
24560 \layout Subsubsection*
24565 Continue program being debugged, after breakpoint.
24566 \layout Subsubsection*
24571 Execute till the end of the current function.
24572 \layout Subsubsection*
24577 Delete breakpoint number 'n'.
24578 If used without any option clear ALL user defined break points.
24579 \layout Subsubsection*
24581 info [break | stack | frame | registers ]
24584 info break - list all breakpoints
24587 info stack - show the function call stack.
24590 info frame - show information about the current execution frame.
24593 info registers - show content of all registers.
24594 \layout Subsubsection*
24599 Step program until it reaches a different source line.
24600 Note: pressing <return> repeats the last command.
24601 \layout Subsubsection*
24606 Step program, proceeding through subroutine calls.
24607 \layout Subsubsection*
24612 Start debugged program.
24613 \layout Subsubsection*
24618 Print type information of the variable.
24619 \layout Subsubsection*
24624 print value of variable.
24625 \layout Subsubsection*
24630 load the given file name.
24631 Note this is an alternate method of loading file for debugging.
24632 \layout Subsubsection*
24637 print information about current frame.
24638 \layout Subsubsection*
24643 Toggle between C source & assembly source.
24644 \layout Subsubsection*
24646 ! simulator command
24649 Send the string following '!' to the simulator, the simulator response is
24651 Note the debugger does not interpret the command being sent to the simulator,
24652 so if a command like 'go' is sent the debugger can loose its execution
24653 context and may display incorrect values.
24654 \layout Subsubsection*
24661 My name is Bobby Brown"
24664 Interfacing SDCDB with DDD
24673 The screenshot was converted from png to eps with:
24674 \begin_inset Quotes sld
24677 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
24678 \begin_inset Quotes srd
24681 which produces a pretty compact eps file which is free from compression
24685 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
24686 as this broke the build system on Sourceforge (pdf-file was broken.
24687 pdflatex does not accept eps files).
24708 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
24714 shows a screenshot of a debugging session with DDD
24715 \begin_inset LatexCommand \index{DDD (debugger)}
24719 (Unix only) on a simulated 8032.
24720 The debugging session might not run as smoothly as the screenshot suggests.
24721 The debugger allows setting of breakpoints, displaying and changing variables,
24722 single stepping through C and assembler code.
24725 The source was compiled with
24748 -debug ddd_example.c
24761 and DDD was invoked with
24768 ddd -debugger "sdcdb -cpu 8032 ddd_example"
24777 Check that the double quotes or an apostroph within the command line survive
24778 the LyX tool chain.
24779 Previously the apostrophs got slanted in the PDF output so a cut and paste
24786 Interfacing SDCDB with XEmacs
24787 \begin_inset LatexCommand \index{XEmacs}
24792 \begin_inset LatexCommand \index{Emacs}
24799 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
24800 sdcdb.el and sdcdbsrc.el.
24801 These two files can be found in the $(prefix)/bin directory after the installat
24803 These files need to be loaded into XEmacs for the interface to work.
24804 This can be done at XEmacs startup time by inserting the following into
24805 your '.xemacs' file (which can be found in your HOME directory):
24811 (load-file sdcdbsrc.el)
24817 .xemacs is a lisp file so the () around the command is REQUIRED.
24818 The files can also be loaded dynamically while XEmacs is running, set the
24819 environment variable 'EMACSLOADPATH' to the installation bin directory
24820 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
24821 To start the interface enter the following command:
24835 You will prompted to enter the file name to be debugged.
24840 The command line options that are passed to the simulator directly are bound
24841 to default values in the file sdcdbsrc.el.
24842 The variables are listed below, these values maybe changed as required.
24845 sdcdbsrc-cpu-type '51
24848 sdcdbsrc-frequency '11059200
24851 sdcdbsrc-serial nil
24854 The following is a list of key mapping for the debugger interface.
24865 ;;key\SpecialChar ~
24879 binding\SpecialChar ~
24903 ;;---\SpecialChar ~
24917 -------\SpecialChar ~
24959 sdcdb-next-from-src\SpecialChar ~
24987 sdcdb-back-from-src\SpecialChar ~
25015 sdcdb-cont-from-src\SpecialChar ~
25025 SDCDB continue command
25043 sdcdb-step-from-src\SpecialChar ~
25071 sdcdb-whatis-c-sexp\SpecialChar ~
25081 SDCDB ptypecommand for data at
25148 sdcdbsrc-delete\SpecialChar ~
25162 SDCDB Delete all breakpoints if no arg
25211 given or delete arg (C-u arg x)
25229 sdcdbsrc-frame\SpecialChar ~
25244 SDCDB Display current frame if no arg,
25293 given or display frame arg
25360 sdcdbsrc-goto-sdcdb\SpecialChar ~
25370 Goto the SDCDB output buffer
25388 sdcdb-print-c-sexp\SpecialChar ~
25399 SDCDB print command for data at
25466 sdcdbsrc-goto-sdcdb\SpecialChar ~
25476 Goto the SDCDB output buffer
25494 sdcdbsrc-mode\SpecialChar ~
25510 Toggles Sdcdbsrc mode (turns it off)
25525 sdcdb-finish-from-src\SpecialChar ~
25533 SDCDB finish command
25548 sdcdb-break\SpecialChar ~
25566 Set break for line with point
25581 sdcdbsrc-mode\SpecialChar ~
25597 Toggle Sdcdbsrc mode
25612 sdcdbsrc-srcmode\SpecialChar ~
25635 Here are a few guidelines that will help the compiler generate more efficient
25636 code, some of the tips are specific to this compiler others are generally
25637 good programming practice.
25640 Use the smallest data type to represent your data-value.
25641 If it is known in advance that the value is going to be less than 256 then
25642 use an 'unsigned char' instead of a 'short' or 'int'.
25643 Please note, that ANSI C requires both signed and unsigned chars to be
25644 promoted to 'signed int'
25645 \begin_inset LatexCommand \index{promotion to signed int}
25650 \begin_inset Marginal
25661 before doing any operation.
25663 \begin_inset LatexCommand \index{type promotion}
25668 \begin_inset LatexCommand \label{type promotion}
25672 can be omitted, if the result is the same.
25673 The effect of the promotion rules together with the sign-extension is often
25680 unsigned char uc = 0xfe;
25682 if (uc * uc < 0) /* this is true! */
25701 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
25711 (unsigned char) -12 / (signed char) -3 = ...
25714 No, the result is not 4:
25719 (int) (unsigned char) -12 / (int) (signed char) -3 =
25721 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
25723 (int) 0x00f4 / (int) 0xfffd =
25725 (int) 0x00f4 / (int) 0xfffd =
25727 (int) 244 / (int) -3 =
25729 (int) -81 = (int) 0xffaf;
25732 Don't complain, that gcc gives you a different result.
25733 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
25734 Therefore the results are different.
25737 \begin_inset Quotes sld
25741 \begin_inset Quotes srd
25749 If well-defined overflow characteristics are important and negative values
25750 are not, or if you want to steer clear of sign-extension problems when
25751 manipulating bits or bytes, use one of the corresponding unsigned types.
25752 (Beware when mixing signed and unsigned values in expressions, though.)
25754 Although character types (especially unsigned char) can be used as "tiny"
25755 integers, doing so is sometimes more trouble than it's worth, due to unpredicta
25756 ble sign extension and increased code size.
25760 Use unsigned when it is known in advance that the value is not going to
25762 This helps especially if you are doing division or multiplication, bit-shifting
25763 or are using an array index.
25766 NEVER jump into a LOOP.
25769 Declare the variables to be local
25770 \begin_inset LatexCommand \index{local variables}
25774 whenever possible, especially loop control variables (induction).
25777 Have a look at the assembly listing to get a
25778 \begin_inset Quotes sld
25782 \begin_inset Quotes srd
25785 for the code generation.
25788 Porting code from or to other compilers
25789 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
25796 check whether endianness of the compilers differs and adapt where needed.
25799 check the device specific header files
25800 \begin_inset LatexCommand \index{Header files}
25805 \begin_inset LatexCommand \index{Include files}
25809 for compiler specific syntax.
25810 Eventually include the file <compiler.h
25811 \begin_inset LatexCommand \index{compiler.h (include file)}
25816 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
25820 to allow using common header files.
25823 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
25830 check whether the startup code contains the correct initialization (watchdog,
25834 check whether the sizes of short, int, long match.
25837 check if some 16 or 32 bit hardware registers require a specific addressing
25838 order (least significant or most significant byte first) and adapt if needed
25847 relate to time and not to lower/upper memory location here, so this is
25852 the same as endianness).
25855 check whether the keyword
25859 is used where needed.
25860 The compilers might differ in their optimization characteristics (as different
25861 versions of the same compiler might also use more clever optimizations
25862 this is good idea anyway).
25864 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
25871 check that the compilers are not told to supress warnings.
25874 check and convert compiler specific extensions (interrupts, memory areas,
25878 check for differences in type promotion.
25879 Especially check for math operations on
25888 For the sake of C99 compatibility SDCC will probably promote these to
25892 more often than other compilers.
25893 Eventually insert explicit casts to
25902 Also check that the ~\SpecialChar ~
25904 \begin_inset LatexCommand \index{\~\/ Operator}
25911 \begin_inset LatexCommand \index{bit}
25917 variables, use the !\SpecialChar ~
25920 \begin_inset LatexCommand \ref{type promotion}
25925 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25932 check the assembly code generated for interrupt routines (f.e.
25933 for calls to possibly non-reentrant library functions).
25936 check whether timing loops result in proper timing (or preferably consider
25937 a rewrite of the code with timer based delays instead).
25940 check for differences in printf parameters (some compilers push (va_arg
25941 \begin_inset LatexCommand \index{vararg, va\_arg}
25945 ) char variables as
25949 others push them as
25955 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25962 check the resulting memory map
25963 \begin_inset LatexCommand \index{Memory map}
25968 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
25969 ly idata, pdata, xdata).
25970 Eventually check if unexpected library functions are included.
25974 \begin_inset LatexCommand \index{Tools}
25978 included in the distribution
25982 \begin_inset Tabular
25983 <lyxtabular version="3" rows="12" columns="3">
25985 <column alignment="left" valignment="top" leftline="true" width="0pt">
25986 <column alignment="left" valignment="top" leftline="true" width="0pt">
25987 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25988 <row topline="true" bottomline="true">
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26020 <row topline="true">
26021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26027 \begin_inset LatexCommand \index{uCsim}
26034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26039 Simulator for various architectures
26042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26051 <row topline="true">
26052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26066 \begin_inset LatexCommand \index{Header files}
26071 \begin_inset LatexCommand \index{Include files}
26078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26083 sdcc/support/scripts
26087 <row topline="true">
26088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26101 header file conversion
26104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26109 sdcc/support/scripts
26113 <row topline="true">
26114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26148 <row topline="true">
26149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26183 <row topline="true">
26184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26218 <row topline="true">
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26253 <row topline="true">
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26288 <row topline="true">
26289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26323 <row topline="true">
26324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26358 <row topline="true" bottomline="true">
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26373 \begin_inset LatexCommand \index{packihx (tool)}
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26408 \begin_inset LatexCommand \index{Documentation}
26412 included in the distribution
26416 \begin_inset Tabular
26417 <lyxtabular version="3" rows="10" columns="2">
26419 <column alignment="block" valignment="top" leftline="true" width="40col%">
26420 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
26421 <row topline="true" bottomline="true" endhead="true">
26422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26439 Filename / Where to get
26443 <row topline="true">
26444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26449 SDCC Compiler User Guide
26452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26457 You're reading it right now
26469 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
26477 <row topline="true">
26478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26503 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26511 <row topline="true">
26512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26518 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
26523 \begin_inset LatexCommand \index{Assembler documentation}
26530 \begin_inset LatexCommand \index{aslink}
26535 \begin_inset LatexCommand \index{Linker documentation}
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26547 sdcc/as/doc/asxhtm.html
26559 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
26567 <row topline="true">
26568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26573 SDCC regression test
26574 \begin_inset LatexCommand \index{Regression test}
26581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26586 sdcc/doc/test_suite_spec.pdf
26598 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26606 <row topline="true">
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26632 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
26640 <row topline="true">
26641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26646 Notes on debugging with SDCDB
26647 \begin_inset LatexCommand \index{SDCDB (debugger)}
26654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26659 sdcc/debugger/README
26671 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
26679 <row topline="true">
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26686 \begin_inset LatexCommand \index{uCsim}
26690 Software simulator for microcontrollers
26693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26727 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
26735 <row topline="true">
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26741 Temporary notes on the pic16
26742 \begin_inset LatexCommand \index{PIC16}
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26754 sdcc/src/pic16/NOTES
26766 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
26774 <row topline="true" bottomline="true">
26775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26780 SDCC internal documentation (debugging file format)
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26817 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
26834 Related open source tools
26835 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
26840 \begin_inset LatexCommand \index{Related tools}
26848 \begin_inset Tabular
26849 <lyxtabular version="3" rows="14" columns="3">
26851 <column alignment="left" valignment="top" leftline="true" width="0pt">
26852 <column alignment="block" valignment="top" leftline="true" width="30line%">
26853 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26854 <row topline="true" bottomline="true">
26855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26886 <row topline="true">
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26893 \begin_inset LatexCommand \index{gpsim (pic simulator)}
26900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26914 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
26922 <row topline="true">
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26929 \begin_inset LatexCommand \index{gputils (pic tools)}
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26950 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26958 <row topline="true">
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
26989 <row topline="true">
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27003 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
27007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27013 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
27021 <row topline="true">
27022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27028 \begin_inset LatexCommand \index{indent (source formatting tool)}
27035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27040 Formats C source - Master of the white spaces
27043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27049 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
27057 <row topline="true">
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27064 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27076 Object file conversion, checksumming, ...
27079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27085 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
27093 <row topline="true">
27094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27100 \begin_inset LatexCommand \index{objdump (tool)}
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27112 Object file conversion, ...
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27120 Part of binutils (should be there anyway)
27124 <row topline="true">
27125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27138 8051 monitor (hex up-/download, single step, disassemble)
27141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27147 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
27155 <row topline="true">
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27162 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27174 Source code documentation system
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27183 \begin_inset LatexCommand \url{http://www.doxygen.org}
27191 <row topline="true">
27192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27205 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27214 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27222 <row topline="true">
27223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27236 8051 monitor (hex up-/download, single step, disassemble)
27239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27245 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27253 <row topline="true">
27254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27260 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27272 Statically checks c sources (see
27273 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27286 \begin_inset LatexCommand \url{http://www.splint.org}
27294 <row topline="true" bottomline="true">
27295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27301 \begin_inset LatexCommand \index{DDD (debugger)}
27308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27313 Debugger, serves nicely as GUI to SDCDB
27314 \begin_inset LatexCommand \index{SDCDB (debugger)}
27321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27327 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
27344 Related documentation / recommended reading
27348 \begin_inset Tabular
27349 <lyxtabular version="3" rows="7" columns="3">
27351 <column alignment="left" valignment="top" leftline="true" width="0pt">
27352 <column alignment="left" valignment="top" leftline="true" width="0">
27353 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27354 <row topline="true" bottomline="true">
27355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27386 <row topline="true">
27387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27410 \begin_inset LatexCommand \index{C Reference card}
27417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27423 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
27431 <row topline="true">
27432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27446 \begin_inset LatexCommand \index{C FAQ}
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27459 \begin_inset LatexCommand \url{http://www.c-faq.com}
27467 <row topline="true">
27468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27482 \begin_inset Quotes sld
27486 \begin_inset Quotes srd
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27500 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27508 <row topline="true">
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27523 \begin_inset Quotes sld
27526 Extensions for Embedded C
27527 \begin_inset Quotes srd
27533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27541 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
27549 <row topline="true">
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27562 Latest datasheet of target CPU
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27574 <row topline="true" bottomline="true">
27575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27587 Revision history of datasheet
27590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27608 Application notes specifically for SDCC
27611 SDCC makes no claims about the completeness of this list and about up-to-datenes
27612 s or correctness of the application notes
27613 \begin_inset LatexCommand \index{Application notes}
27623 \begin_inset Tabular
27624 <lyxtabular version="3" rows="7" columns="3">
27626 <column alignment="block" valignment="top" leftline="true" width="17col%">
27627 <column alignment="block" valignment="top" leftline="true" width="27col%">
27628 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
27629 <row topline="true" bottomline="true">
27630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27641 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27664 <row topline="true">
27665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27682 Using the SDCC Compiler for the DS80C400
27683 \begin_inset LatexCommand \index{DS80C400}
27690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27698 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
27706 <row topline="true">
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27717 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
27724 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
27725 \begin_inset LatexCommand \index{DS89C4x0}
27729 Family of Microcontrollers
27732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27740 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
27748 <row topline="true">
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27756 Silicon Laboratories / Cygnal
27759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27766 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
27767 \begin_inset LatexCommand \index{IDE}
27774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27782 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
27790 <row topline="true">
27791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27798 Ramtron / Goal Semiconductor
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27808 Interfacing SDCC to Syn and Textpad
27811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27819 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27827 <row topline="true">
27828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27835 Ramtron / Goal Semiconductor
27838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27845 Installing and Configuring SDCC and Crimson Editor
27848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27856 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27864 <row topline="true" bottomline="true">
27865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27882 MSC12xx Programming with SDCC
27885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27893 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
27911 Some questions answered, some pointers given - it might be time to in turn
27919 can you solve your project with the selected microcontroller? Would you
27920 find out early or rather late that your target is too small/slow/whatever?
27921 Can you switch to a slightly better device if it doesn't fit?
27924 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
27925 and/or another programming language be more adequate? Would an operating
27926 system on the target device help?
27929 if you solved the problem, will the marketing department be happy?
27932 if the marketing department is happy, will customers be happy?
27935 if you're the project manager, marketing department and maybe even the customer
27936 in one person, have you tried to see the project from the outside?
27939 is the project done if you think it is done? Or is just that other interface/pro
27940 tocol/feature/configuration/option missing? How about website, manual(s),
27941 internationali(z|s)ation, packaging, labels, 2nd source for components,
27942 electromagnetic compatability/interference, documentation for production,
27943 production test software, update mechanism, patent issues?
27946 is your project adequately positioned in that magic triangle: fame, fortune,
27950 Maybe not all answers to these questions are known and some answers may
27955 , nevertheless knowing these questions may help you to avoid burnout
27961 burnout is bad for electronic devices, programmers and motorcycle tyres
27965 Chances are you didn't want to hear some of them...
27969 \begin_inset LatexCommand \index{Support}
27976 SDCC has grown to be a large project.
27977 The compiler alone (without the preprocessor, assembler and linker) is
27978 well over 150,000 lines of code (blank stripped).
27979 The open source nature of this project is a key to its continued growth
27981 You gain the benefit and support of many active software developers and
27983 Is SDCC perfect? No, that's why we need your help.
27984 The developers take pride in fixing reported bugs.
27985 You can help by reporting the bugs and helping other SDCC users.
27986 There are lots of ways to contribute, and we encourage you to take part
27987 in making SDCC a great software package.
27991 The SDCC project is hosted on the SDCC sourceforge site at
27992 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
27997 You'll find the complete set of mailing lists
27998 \begin_inset LatexCommand \index{Mailing list(s)}
28002 , forums, bug reporting system, patch submission
28003 \begin_inset LatexCommand \index{Patch submission}
28008 \begin_inset LatexCommand \index{download}
28012 area and Subversion code repository
28013 \begin_inset LatexCommand \index{Subversion code repository}
28021 \begin_inset LatexCommand \index{Bug reporting}
28026 \begin_inset LatexCommand \index{Reporting bugs}
28033 The recommended way of reporting bugs is using the infrastructure of the
28035 You can follow the status of bug reports there and have an overview about
28039 Bug reports are automatically forwarded to the developer mailing list and
28040 will be fixed ASAP.
28041 When reporting a bug, it is very useful to include a small test program
28042 (the smaller the better) which reproduces the problem.
28043 If you can isolate the problem by looking at the generated assembly code,
28044 this can be very helpful.
28045 Compiling your program with the -
28056 \begin_inset LatexCommand \index{-\/-dumpall}
28060 option can sometimes be useful in locating optimization problems.
28061 When reporting a bug please make sure you:
28064 Attach the code you are compiling with SDCC.
28068 Specify the exact command you use to run SDCC, or attach your Makefile.
28072 Specify the SDCC version (type "
28078 "), your platform, and operating system.
28082 Provide an exact copy of any error message or incorrect output.
28086 Put something meaningful in the subject of your message.
28089 Please attempt to include these 5 important parts, as applicable, in all
28090 requests for support or when reporting any problems or bugs with SDCC.
28091 Though this will make your message lengthy, it will greatly improve your
28092 chance that SDCC users and developers will be able to help you.
28093 Some SDCC developers are frustrated by bug reports without code provided
28094 that they can use to reproduce and ultimately fix the problem, so please
28095 be sure to provide sample code if you are reporting a bug!
28098 Please have a short check that you are using a recent version of SDCC and
28099 the bug is not yet known.
28100 This is the link for reporting bugs:
28101 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
28106 With SDCC on average having more than 200 downloads
28107 \begin_inset LatexCommand \index{download}
28111 on sourceforge per day
28117 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
28118 between 2002 and 2005.
28119 This does not include other methods of distribution.
28122 there must be some users.
28123 So it's not exactly easy to find a new bug.
28124 If you find one we need it:
28126 reporting bugs is good
28131 Requesting Features
28132 \begin_inset LatexCommand \label{sub:Requesting-Features}
28137 \begin_inset LatexCommand \index{Feature request}
28142 \begin_inset LatexCommand \index{Requesting features}
28149 Like bug reports feature requests are forwarded to the developer mailing
28151 This is the link for requesting features:
28152 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28162 Like bug reports contributed patches are forwarded to the developer mailing
28164 This is the link for submitting patches
28165 \begin_inset LatexCommand \index{Patch submission}
28170 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28177 You need to specify some parameters to the
28181 command for the patches to be useful.
28182 If you modified more than one file a patch created f.e.
28187 \begin_inset Quotes sld
28190 diff -Naur unmodified_directory modified_directory >my_changes.patch
28191 \begin_inset Quotes srd
28197 will be fine, otherwise
28201 \begin_inset Quotes sld
28204 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28205 \begin_inset Quotes srd
28218 These links should take you directly to the
28219 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28229 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28230 automated messages (mid 2003)
28234 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28239 \begin_inset LatexCommand \index{Mailing list(s)}
28243 and forums are archived and searchable so if you are lucky someone already
28244 had a similar problem.
28245 While mails to the lists themselves are delivered promptly their web front
28246 end on sourceforge sometimes shows a severe time lag (up to several weeks),
28247 if you're seriously using SDCC please consider subscribing to the lists.
28253 You can follow the status of the Subversion version
28254 \begin_inset LatexCommand \index{version}
28258 of SDCC by watching the Changelog
28259 \begin_inset LatexCommand \index{Changelog}
28263 in the Subversion repository
28266 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28273 Subversion Source Code Repository
28282 or the filenames of the snapshot versions of SDCC include date and its
28284 \begin_inset LatexCommand \index{Subversion code repository}
28289 Subversion allows to download the source of recent or previous versions
28291 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28295 (by number or by date).
28296 An on-line source code browser and detailled instructions are also available
28298 SDCC versions starting from 1999 up to now are available (currently the
28299 versions prior to the conversion from cvs
28300 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28304 to Subversion (April 2006) are either by accessible by Subversion or by
28309 \begin_inset LatexCommand \index{Release policy}
28316 Historically there often were long delays between official releases and
28317 the sourceforge download area tends to get not updated at all.
28318 Excuses in the past might have referred to problems with live range analysis,
28319 but as this was fixed a while ago, the current problem is that another
28320 excuse has to be found.
28321 Kidding aside, we have to get better there! On the other hand there are
28322 daily snapshots available at
28323 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
28327 , and you can always build the very last version (hopefully with many bugs
28328 fixed, and features added) from the source code available at
28329 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
28335 \begin_inset LatexCommand \index{wiki}
28340 \begin_inset LatexCommand \index{Release wiki}
28345 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
28349 also holds some information about past and future releases.
28353 \begin_inset LatexCommand \index{Examples}
28360 You'll find some small examples in the directory
28362 sdcc/device/examples/.
28365 More examples and libraries are available at
28367 The SDCC Open Knowledge Resource
28368 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
28375 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
28388 I did insert a reference to Paul's web site here although it seems rather
28389 dedicated to a specific 8032 board (I think it's okay because it f.e.
28390 shows LCD/Harddisc interface and has a free 8051 monitor.
28391 Independent 8032 board vendors face hard competition of heavily subsidized
28392 development boards anyway).
28395 Maybe we should include some links to real world applications.
28396 Preferably pointer to pointers (one for each architecture) so this stays
28404 \begin_inset LatexCommand \label{sec:Quality-control}
28409 \begin_inset LatexCommand \index{Quality control}
28416 The compiler is passed through nightly compile and build checks.
28422 \begin_inset LatexCommand \index{Regression test}
28426 check that SDCC itself compiles flawlessly on several host platforms (i386,
28427 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
28428 the quality of the code generated by SDCC by running the code for several
28429 target platforms through simulators.
28430 The regression test suite comprises more than 100 files which expand to
28431 more than 500 test cases which include more than 4500 tests.
28432 The results of these tests are published daily on SDCC's snapshot page
28433 (click on the red or green symbols on the right side of
28434 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
28441 There is a separate document
28444 \begin_inset LatexCommand \index{Test suite}
28451 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28455 about the regression test suite.
28458 You'll find the test code in the directory
28460 sdcc/support/regression
28463 You can run these tests manually by running
28467 in this directory (or f.e.
28472 \begin_inset Quotes sld
28476 \begin_inset Quotes srd
28482 if you don't want to run the complete tests).
28483 The test code might also be interesting if you want to look for examples
28484 \begin_inset LatexCommand \index{Examples}
28488 checking corner cases of SDCC or if you plan to submit patches
28489 \begin_inset LatexCommand \index{Patch submission}
28496 The 14bit pic port uses a different set of regression tests
28497 \begin_inset LatexCommand \index{Regression test (PIC14)}
28501 , you'll find them in the directory
28503 sdcc/src/regression
28508 Use of SDCC in Education
28521 the phrase "use in education" might evoke the association "
28525 fit for use in education".
28526 This connotation is not intended but nevertheless risked as the licensing
28527 of SDCC makes it difficult to offer educational discounts
28531 If your rationales are to:
28534 give students a chance to understand the
28538 steps of code generation
28541 have a curriculum that can be extended for years.
28542 Then you could use an fpga board as target and your curriculum will seamlessly
28543 extend from logic synthesis (
28544 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
28549 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
28553 ), over assembly programming, to C to FPGA compilers (
28554 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
28561 be able to insert excursions about skills like using a revision control
28562 system, submitting/applying patches, using a type-setting (as opposed to
28563 word-processing) engine LyX/LaTeX, using
28564 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
28569 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
28573 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
28574 Source Software, CPU simulation, compiler regression tests
28575 \begin_inset LatexCommand \index{Regression test}
28582 And if there should be a shortage of ideas then you can always point students
28583 to the ever-growing feature request list
28584 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28591 not tie students to a specific host platform and instead allow them to use
28596 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
28598 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
28605 not encourage students to use illegal copies of educational software
28608 be immune to licensing/availability/price changes of the chosen tool chain
28611 be able to change to a new target platform without having to adopt a new
28615 have complete control over and insight into the tool chain
28618 make your students aware about the pros and cons of open source software
28622 give back to the public as you are probably at least partially publically
28626 give students a chance to publically prove their skills and to possibly
28627 see a world wide impact
28630 then SDCC is probably among the first choices.
28631 Well, probably SDCC might be the only choice.
28634 SDCC Technical Data
28638 \begin_inset LatexCommand \index{Optimizations}
28645 SDCC performs a host of standard optimizations in addition to some MCU specific
28650 Sub-expression Elimination
28651 \begin_inset LatexCommand \index{Subexpression elimination}
28658 The compiler does local and
28684 will be translated to
28696 Some subexpressions are not as obvious as the above example, e.g.:
28706 In this case the address arithmetic a->b[i] will be computed only once;
28707 the equivalent code in C would be.
28719 The compiler will try to keep these temporary variables in registers.
28722 Dead-Code Elimination
28723 \begin_inset LatexCommand \index{Dead-code elimination}
28744 i = 1; \SpecialChar ~
28753 global = 1;\SpecialChar ~
28766 global = 3;\SpecialChar ~
28791 \begin_inset LatexCommand \index{Copy propagation}
28847 Note: the dead stores created by this copy propagation will be eliminated
28848 by dead-code elimination.
28852 \begin_inset LatexCommand \index{Loop optimization}
28857 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
28864 Two types of loop optimizations are done by SDCC
28872 of loop induction variables.
28873 In addition to the strength reduction the optimizer marks the induction
28874 variables and the register allocator tries to keep the induction variables
28875 in registers for the duration of the loop.
28876 Because of this preference of the register allocator
28877 \begin_inset LatexCommand \index{Register allocation}
28881 , loop induction optimization causes an increase in register pressure, which
28882 may cause unwanted spilling of other temporary variables into the stack
28883 \begin_inset LatexCommand \index{stack}
28888 The compiler will generate a warning message when it is forced to allocate
28889 extra space either on the stack or data space.
28890 If this extra space allocation is undesirable then induction optimization
28891 can be eliminated either for the entire source file (with -
28901 -noinduction option) or for a given function only using #pragma\SpecialChar ~
28903 \begin_inset LatexCommand \index{\#pragma noinduction}
28916 for (i = 0 ; i < 100 ; i ++)
28932 for (i = 0; i < 100; i++)
28941 As mentioned previously some loop invariants are not as apparent, all static
28942 address computations are also moved out of the loop.
28947 \begin_inset LatexCommand \index{Strength reduction}
28951 , this optimization substitutes an expression by a cheaper expression:
28956 for (i=0;i < 100; i++)
28974 for (i=0;i< 100;i++) {
28980 ar[itemp1] = itemp2;
28997 The more expensive multiplication
28998 \begin_inset LatexCommand \index{Multiplication}
29002 is changed to a less expensive addition.
29006 \begin_inset LatexCommand \index{Loop reversing}
29013 This optimization is done to reduce the overhead of checking loop boundaries
29014 for every iteration.
29015 Some simple loops can be reversed and implemented using a
29016 \begin_inset Quotes eld
29019 decrement and jump if not zero
29020 \begin_inset Quotes erd
29024 SDCC checks for the following criterion to determine if a loop is reversible
29025 (note: more sophisticated compilers use data-dependency analysis to make
29026 this determination, SDCC uses a more simple minded analysis).
29029 The 'for' loop is of the form
29035 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
29045 The <for body> does not contain
29046 \begin_inset Quotes eld
29050 \begin_inset Quotes erd
29054 \begin_inset Quotes erd
29060 All goto's are contained within the loop.
29063 No function calls within the loop.
29066 The loop control variable <sym> is not assigned any value within the loop
29069 The loop control variable does NOT participate in any arithmetic operation
29073 There are NO switch statements in the loop.
29076 Algebraic Simplifications
29079 SDCC does numerous algebraic simplifications, the following is a small sub-set
29080 of these optimizations.
29085 i = j + 0;\SpecialChar ~
29089 /* changed to: */\SpecialChar ~
29095 i /= 2;\SpecialChar ~
29102 /* changed to: */\SpecialChar ~
29108 i = j - j;\SpecialChar ~
29112 /* changed to: */\SpecialChar ~
29118 i = j / 1;\SpecialChar ~
29122 /* changed to: */\SpecialChar ~
29129 Note the subexpressions
29130 \begin_inset LatexCommand \index{Subexpression}
29134 given above are generally introduced by macro expansions or as a result
29135 of copy/constant propagation.
29138 'switch' Statements
29139 \begin_inset LatexCommand \label{sub:'switch'-Statements}
29144 \begin_inset LatexCommand \index{switch statement}
29151 SDCC can optimize switch statements to jump tables
29152 \begin_inset LatexCommand \index{jump tables}
29157 It makes the decision based on an estimate of the generated code size.
29158 SDCC is quite liberal in the requirements for jump table generation:
29161 The labels need not be in order, and the starting number need not be one
29162 or zero, the case labels are in numerical sequence or not too many case
29163 labels are missing.
29169 switch(i) {\SpecialChar ~
29200 case 4: ...\SpecialChar ~
29232 case 5: ...\SpecialChar ~
29264 case 3: ...\SpecialChar ~
29295 case 6: ...\SpecialChar ~
29327 case 7: ...\SpecialChar ~
29359 case 8: ...\SpecialChar ~
29391 case 9: ...\SpecialChar ~
29423 case 10: ...\SpecialChar ~
29454 case 11: ...\SpecialChar ~
29521 Both the above switch statements will be implemented using a jump-table.
29522 The example to the right side is slightly more efficient as the check for
29523 the lower boundary of the jump-table is not needed.
29527 The number of case labels is not larger than supported by the target architectur
29531 If the case labels are not in numerical sequence ('gaps' between cases)
29532 SDCC checks whether a jump table with additionally inserted dummy cases
29533 is still attractive.
29537 If the starting number is not zero and a check for the lower boundary of
29538 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
29543 Switch statements which have large gaps in the numeric sequence or those
29544 that have too many case labels can be split into more than one switch statement
29545 for efficient code generation, e.g.:
29625 If the above switch statement is broken down into two switch statements
29715 then both the switch statements will be implemented using jump-tables whereas
29716 the unmodified switch statement will not be.
29725 There might be reasons which SDCC cannot know about to either favour or
29726 not favour jump tables.
29727 If the target system has to be as quick for the last switch case as for
29728 the first (pro jump table), or if the switch argument is known to be zero
29729 in the majority of the cases (contra jump table).
29735 The pragma nojtbound
29736 \begin_inset LatexCommand \index{\#pragma nojtbound}
29740 can be used to turn off checking the
29753 It has no effect if a default label is supplied.
29754 Use of this pragma is dangerous: if the switch
29755 \begin_inset LatexCommand \index{switch statement}
29759 argument is not matched by a case statement the processor will happily
29763 Bit-shifting Operations
29764 \begin_inset LatexCommand \index{Bit shifting}
29771 Bit shifting is one of the most frequently used operation in embedded programmin
29773 SDCC tries to implement bit-shift operations in the most efficient way
29789 generates the following code:
29806 In general SDCC will never setup a loop if the shift count is known.
29849 \begin_inset LatexCommand \index{Bit rotation}
29856 A special case of the bit-shift operation is bit rotation
29857 \begin_inset LatexCommand \index{rotating bits}
29861 , SDCC recognizes the following expression to be a left bit-rotation:
29871 char i;\SpecialChar ~
29882 /* unsigned is needed for rotation */
29887 i = ((i << 1) | (i >> 7));
29896 will generate the following code:
29915 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
29916 ns of this case will also be recognized as bit-rotation, i.e.:
29921 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
29924 Nibble and Byte Swapping
29927 Other special cases of the bit-shift operations are nibble or byte swapping
29928 \begin_inset LatexCommand \index{swapping nibbles/bytes}
29932 , SDCC recognizes the following expressions:
29955 i = ((i << 4) | (i >> 4));
29961 j = ((j << 8) | (j >> 8));
29964 and generates a swap instruction for the nibble swapping
29965 \begin_inset LatexCommand \index{Nibble swapping}
29969 or move instructions for the byte swapping
29970 \begin_inset LatexCommand \index{Byte swapping}
29976 \begin_inset Quotes sld
29980 \begin_inset Quotes srd
29983 example can be used to convert from little to big-endian or vice versa.
29984 If you want to change the endianness of a
29988 integer you have to cast to
29995 Note that SDCC stores numbers in little-endian
30001 Usually 8-bit processors don't care much about endianness.
30002 This is not the case for the standard 8051 which only has an instruction
30008 \begin_inset LatexCommand \index{DPTR}
30016 so little-endian is the more efficient byte order.
30020 \begin_inset LatexCommand \index{little-endian}
30025 \begin_inset LatexCommand \index{Endianness}
30030 lowest order first).
30034 \begin_inset LatexCommand \index{Highest Order Bit}
30039 \begin_inset LatexCommand \index{Any Order Bit}
30046 It is frequently required to obtain the highest order bit of an integral
30047 type (long, int, short or char types).
30048 Also obtaining any other order bit is not uncommon.
30049 SDCC recognizes the following expressions to yield the highest order bit
30050 and generates optimized code for it, e.g.:
30063 unsigned char hob1, aob1;
30067 bit hob2, hob3, aob2, aob3;
30076 hob1 = (gint >> 15) & 1;
30080 hob2 = (gint >> 15) & 1;
30084 hob3 = gint & 0x8000;
30088 aob1 = (gint >> 9) & 1;
30092 aob2 = (gint >> 8) & 1;
30096 aob3 = gint & 0x0800;
30106 will generate the following code:
30139 000A E5*01\SpecialChar ~
30166 000C 23\SpecialChar ~
30197 000D 54 01\SpecialChar ~
30224 000F F5*02\SpecialChar ~
30279 0011 E5*01\SpecialChar ~
30306 0013 33\SpecialChar ~
30336 0014 92*00\SpecialChar ~
30391 0016 E5*01\SpecialChar ~
30418 0018 33\SpecialChar ~
30448 0019 92*01\SpecialChar ~
30503 001B E5*01\SpecialChar ~
30530 001D 03\SpecialChar ~
30561 001E 54 01\SpecialChar ~
30588 0020 F5*03\SpecialChar ~
30643 0022 E5*01\SpecialChar ~
30670 0024 13\SpecialChar ~
30700 0025 92*02\SpecialChar ~
30755 0027 E5*01\SpecialChar ~
30782 0029 A2 E3\SpecialChar ~
30809 002B 92*03\SpecialChar ~
30837 Other variations of these cases however will
30842 They are standard C expressions, so I heartily recommend these be the only
30843 way to get the highest order bit, (it is portable).
30844 Of course it will be recognized even if it is embedded in other expressions,
30850 xyz = gint + ((gint >> 15) & 1);
30853 will still be recognized.
30857 \begin_inset LatexCommand \index{Higher Order Byte}
30861 / Higher Order Word
30862 \begin_inset LatexCommand \index{Higher Order Word}
30869 It is also frequently required to obtain a higher order byte or word of
30870 a larger integral type (long, int or short types).
30871 SDCC recognizes the following expressions to yield the higher order byte
30872 or word and generates optimized code for it, e.g.:
30879 unsigned long int glong;
30887 unsigned char hob1, hob2;
30891 unsigned int how1, how2;
30900 hob1 = (gint >> 8) & 0xFF;
30904 hob2 = glong >> 24;
30908 how1 = (glong >> 16) & 0xFFFF;
30922 will generate the following code:
30955 0037 85*01*06\SpecialChar ~
30977 _foo_hob1_1_1,(_gint + 1)
31007 003A 85*05*07\SpecialChar ~
31029 _foo_hob2_1_1,(_glong + 3)
31059 003D 85*04*08\SpecialChar ~
31081 _foo_how1_1_1,(_glong + 2)
31083 0040 85*05*09\SpecialChar ~
31105 (_foo_how1_1_1 + 1),(_glong + 3)
31107 0043 85*03*0A\SpecialChar ~
31129 _foo_how2_1_1,(_glong + 1)
31131 0046 85*04*0B\SpecialChar ~
31153 (_foo_how2_1_1 + 1),(_glong + 2)
31156 Again, variations of these cases may
31161 They are standard C expressions, so I heartily recommend these be the only
31162 way to get the higher order byte/word, (it is portable).
31163 Of course it will be recognized even if it is embedded in other expressions,
31169 xyz = gint + ((gint >> 8) & 0xFF);
31172 will still be recognized.
31176 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31181 \begin_inset LatexCommand \index{Peephole optimizer}
31188 The compiler uses a rule based, pattern matching and re-writing mechanism
31189 for peep-hole optimization.
31194 a peep-hole optimizer by Christopher W.
31195 Fraser (cwfraser\SpecialChar ~
31198 A default set of rules are compiled into the compiler, additional rules
31199 may be added with the
31212 \begin_inset LatexCommand \index{-\/-peep-file}
31219 The rule language is best illustrated with examples.
31243 The above rule will change the following assembly
31244 \begin_inset LatexCommand \index{Assembler routines}
31266 Note: All occurrences of a
31270 (pattern variable) must denote the same string.
31271 With the above rule, the assembly sequence:
31281 will remain unmodified.
31285 Other special case optimizations may be added by the user (via
31301 some variants of the 8051 MCU
31302 \begin_inset LatexCommand \index{MCS51 variants}
31315 The following two rules will change all
31334 replace { lcall %1 } by { acall %1 }
31336 replace { ljmp %1 } by { ajmp %1 }
31341 inline-assembler code
31343 is also passed through the peep hole optimizer, thus the peephole optimizer
31344 can also be used as an assembly level macro expander.
31345 The rules themselves are MCU dependent whereas the rule language infra-structur
31346 e is MCU independent.
31347 Peephole optimization rules for other MCU can be easily programmed using
31352 The syntax for a rule is as follows:
31357 rule := replace [ restart ] '{' <assembly sequence> '
31395 <assembly sequence> '
31413 '}' [if <functionName> ] '
31418 <assembly sequence> := assembly instruction (each instruction including
31419 labels must be on a separate line).
31423 The optimizer will apply to the rules one by one from the top in the sequence
31424 of their appearance, it will terminate when all rules are exhausted.
31425 If the 'restart' option is specified, then the optimizer will start matching
31426 the rules again from the top, this option for a rule is expensive (performance)
31427 , it is intended to be used in situations where a transformation will trigger
31428 the same rule again.
31429 An example of this (not a good one, it has side effects) is the following
31452 Note that the replace pattern cannot be a blank, but can be a comment line.
31453 Without the 'restart' option only the innermost 'pop' 'push' pair would
31454 be eliminated, i.e.:
31484 the restart option the rule will be applied again to the resulting code
31485 and then all the pop-push pairs will be eliminated to yield:
31495 A conditional function can be attached to a rule.
31496 Attaching rules are somewhat more involved, let me illustrate this with
31523 The optimizer does a look-up of a function name table defined in function
31528 in the source file SDCCpeeph.c, with the name
31533 If it finds a corresponding entry the function is called.
31534 Note there can be no parameters specified for these functions, in this
31539 is crucial, since the function
31543 expects to find the label in that particular variable (the hash table containin
31544 g the variable bindings is passed as a parameter).
31545 If you want to code more such functions, take a close look at the function
31546 labelInRange and the calling mechanism in source file SDCCpeeph.c.
31547 Currently implemented are
31549 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
31550 24bitMode, portIsDS390, 24bitModeAndPortDS390
31559 I know this whole thing is a little kludgey, but maybe some day we will
31560 have some better means.
31561 If you are looking at this file, you will see the default rules that are
31562 compiled into the compiler, you can add your own rules in the default set
31563 there if you get tired of specifying the -
31577 \begin_inset LatexCommand \index{ANSI-compliance}
31582 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
31589 The latest publically available version of the standard
31591 ISO/IEC 9899 - Programming languages - C
31593 should be available at:
31594 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31603 Deviations from the compliance:
31606 functions are not reentrant
31607 \begin_inset LatexCommand \index{reentrant}
31611 unless explicitly declared as such or the
31624 \begin_inset LatexCommand \index{-\/-stack-auto}
31630 command line option is specified.
31634 \begin_inset LatexCommand \index{struct}
31639 \begin_inset LatexCommand \index{union}
31643 cannot be assigned values directly, cannot be passed as function parameters
31644 or assigned to each other and cannot be a return value
31645 \begin_inset LatexCommand \index{return value}
31649 from a function, e.g.:
31675 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
31694 s parms) /* invalid in SDCC although allowed in ANSI */
31715 return rets; /* is invalid in SDCC although allowed in ANSI */
31721 initialization of structure arrays must be fully braced.
31727 struct s { char x } a[] = {1, 2};\SpecialChar ~
31732 /* invalid in SDCC */
31734 struct s { char x } a[] = {{1}, {2}}; /* OK */
31739 \begin_inset LatexCommand \index{long long (not supported)}
31744 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
31752 \begin_inset LatexCommand \index{double (not supported)}
31756 ' precision floating point
31757 \begin_inset LatexCommand \index{Floating point support}
31765 \begin_inset LatexCommand \index{K\&R style}
31769 function declarations are NOT allowed.
31775 foo(i,j) /* this old style of function declarations */
31777 int i,j; /* are valid in ANSI but not valid in SDCC */
31792 Most enhancements in C99 are not supported, f.e.:
31800 \begin_inset LatexCommand \index{inline (not supported)}
31806 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
31812 can be used as a work around */
31820 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
31824 Certain words that are valid identifiers in the standard may be reserved
31825 words in SDCC unless the
31838 \begin_inset LatexCommand \index{-\/-std-c89}
31853 \begin_inset LatexCommand \index{-\/-std-c99}
31859 command line options are used.
31860 These may include (depending on the selected processor): 'at', 'banked',
31861 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
31862 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
31863 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
31865 Compliant equivalents of these keywords are always available in a form
31866 that begin with two underscores
31867 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
31872 '__data' instead of 'data'.
31875 Cyclomatic Complexity
31876 \begin_inset LatexCommand \index{Cyclomatic complexity}
31883 Cyclomatic complexity of a function is defined as the number of independent
31884 paths the program can take during execution of the function.
31885 This is an important number since it defines the number test cases you
31886 have to generate to validate the function.
31887 The accepted industry standard for complexity number is 10, if the cyclomatic
31888 complexity reported by SDCC exceeds 10 you should think about simplification
31889 of the function logic.
31890 Note that the complexity level is not related to the number of lines of
31891 code in a function.
31892 Large functions can have low complexity, and small functions can have large
31898 SDCC uses the following formula to compute the complexity:
31903 complexity = (number of edges in control flow graph) - (number of nodes
31904 in control flow graph) + 2;
31908 Having said that the industry standard is 10, you should be aware that in
31909 some cases it be may unavoidable to have a complexity level of less than
31911 For example if you have switch statement with more than 10 case labels,
31912 each case label adds one to the complexity level.
31913 The complexity level is by no means an absolute measure of the algorithmic
31914 complexity of the function, it does however provide a good starting point
31915 for which functions you might look at for further optimization.
31918 Retargetting for other Processors
31921 The issues for retargetting the compiler are far too numerous to be covered
31923 What follows is a brief description of each of the seven phases of the
31924 compiler and its MCU dependency.
31927 Parsing the source and building the annotated parse tree.
31928 This phase is largely MCU independent (except for the language extensions).
31929 Syntax & semantic checks are also done in this phase, along with some initial
31930 optimizations like back patching labels and the pattern matching optimizations
31931 like bit-rotation etc.
31934 The second phase involves generating an intermediate code which can be easy
31935 manipulated during the later phases.
31936 This phase is entirely MCU independent.
31937 The intermediate code generation assumes the target machine has unlimited
31938 number of registers, and designates them with the name iTemp.
31939 The compiler can be made to dump a human readable form of the code generated
31953 This phase does the bulk of the standard optimizations and is also MCU independe
31955 This phase can be broken down into several sub-phases:
31959 Break down intermediate code (iCode) into basic blocks.
31961 Do control flow & data flow analysis on the basic blocks.
31963 Do local common subexpression elimination, then global subexpression elimination
31965 Dead code elimination
31969 If loop optimizations caused any changes then do 'global subexpression eliminati
31970 on' and 'dead code elimination' again.
31973 This phase determines the live-ranges; by live range I mean those iTemp
31974 variables defined by the compiler that still survive after all the optimization
31976 Live range analysis
31977 \begin_inset LatexCommand \index{Live range analysis}
31981 is essential for register allocation, since these computation determines
31982 which of these iTemps will be assigned to registers, and for how long.
31985 Phase five is register allocation.
31986 There are two parts to this process.
31990 The first part I call 'register packing' (for lack of a better term).
31991 In this case several MCU specific expression folding is done to reduce
31996 The second part is more MCU independent and deals with allocating registers
31997 to the remaining live ranges.
31998 A lot of MCU specific code does creep into this phase because of the limited
31999 number of index registers available in the 8051.
32002 The Code generation phase is (unhappily), entirely MCU dependent and very
32003 little (if any at all) of this code can be reused for other MCU.
32004 However the scheme for allocating a homogenized assembler operand for each
32005 iCode operand may be reused.
32008 As mentioned in the optimization section the peep-hole optimizer is rule
32009 based system, which can reprogrammed for other MCUs.
32012 More information is available in a wiki
32013 \begin_inset LatexCommand \index{wiki}
32018 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
32022 ) and in the thread
32023 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
32031 \begin_inset LatexCommand \index{Compiler internals}
32038 The anatomy of the compiler
32039 \begin_inset LatexCommand \label{sub:The-anatomy-of}
32048 This is an excerpt from an article published in Circuit Cellar Magazine
32054 It's a little outdated (the compiler is much more efficient now and user/develo
32055 per friendly), but pretty well exposes the guts of it all.
32061 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
32062 It is fairly easy to retarget for other 8-bit MCU.
32063 Here we take a look at some of the internals of the compiler.
32068 \begin_inset LatexCommand \index{Parsing}
32075 Parsing the input source file and creating an AST (Annotated Syntax Tree
32076 \begin_inset LatexCommand \index{Annotated syntax tree}
32081 This phase also involves propagating types (annotating each node of the
32082 parse tree with type information) and semantic analysis.
32083 There are some MCU specific parsing rules.
32084 For example the storage classes, the extended storage classes are MCU specific
32085 while there may be a xdata storage class for 8051 there is no such storage
32086 class for z80 or Atmel AVR.
32087 SDCC allows MCU specific storage class extensions, i.e.
32088 xdata will be treated as a storage class specifier when parsing 8051 C
32089 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
32094 \begin_inset LatexCommand \index{iCode}
32101 Intermediate code generation.
32102 In this phase the AST is broken down into three-operand form (iCode).
32103 These three operand forms are represented as doubly linked lists.
32104 ICode is the term given to the intermediate form generated by the compiler.
32105 ICode example section shows some examples of iCode generated for some simple
32106 C source functions.
32110 \begin_inset LatexCommand \index{Optimizations}
32117 Bulk of the target independent optimizations is performed in this phase.
32118 The optimizations include constant propagation, common sub-expression eliminati
32119 on, loop invariant code movement, strength reduction of loop induction variables
32120 and dead-code elimination.
32123 Live range analysis
32124 \begin_inset LatexCommand \index{Live range analysis}
32131 During intermediate code generation phase, the compiler assumes the target
32132 machine has infinite number of registers and generates a lot of temporary
32134 The live range computation determines the lifetime of each of these compiler-ge
32135 nerated temporaries.
32136 A picture speaks a thousand words.
32137 ICode example sections show the live range annotations for each of the
32139 It is important to note here, each iCode is assigned a number in the order
32140 of its execution in the function.
32141 The live ranges are computed in terms of these numbers.
32142 The from number is the number of the iCode which first defines the operand
32143 and the to number signifies the iCode which uses this operand last.
32146 Register Allocation
32147 \begin_inset LatexCommand \index{Register allocation}
32154 The register allocation determines the type and number of registers needed
32156 In most MCUs only a few registers can be used for indirect addressing.
32157 In case of 8051 for example the registers R0 & R1 can be used to indirectly
32158 address the internal ram and DPTR to indirectly address the external ram.
32159 The compiler will try to allocate the appropriate register to pointer variables
32161 ICode example section shows the operands annotated with the registers assigned
32163 The compiler will try to keep operands in registers as much as possible;
32164 there are several schemes the compiler uses to do achieve this.
32165 When the compiler runs out of registers the compiler will check to see
32166 if there are any live operands which is not used or defined in the current
32167 basic block being processed, if there are any found then it will push that
32168 operand and use the registers in this block, the operand will then be popped
32169 at the end of the basic block.
32173 There are other MCU specific considerations in this phase.
32174 Some MCUs have an accumulator; very short-lived operands could be assigned
32175 to the accumulator instead of a general-purpose register.
32181 Figure II gives a table of iCode
32182 \begin_inset LatexCommand \index{iCode}
32186 operations supported by the compiler.
32187 The code generation involves translating these operations into corresponding
32188 assembly code for the processor.
32189 This sounds overly simple but that is the essence of code generation.
32190 Some of the iCode operations are generated on a MCU specific manner for
32191 example, the z80 port does not use registers to pass parameters so the
32192 SEND and RECV iCode operations will not be generated, and it also does
32193 not support JUMPTABLES.
32202 \begin_inset Tabular
32203 <lyxtabular version="3" rows="39" columns="4">
32204 <features islongtable="true" headBottomDL="true">
32205 <column alignment="block" valignment="top" leftline="true" width="13col%">
32206 <column alignment="left" valignment="top" leftline="true" width="13col%">
32207 <column alignment="block" valignment="top" leftline="true" width="22col%">
32208 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32209 <row topline="true" bottomline="true" endhead="true">
32210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32220 \begin_inset LatexCommand \index{iCode}
32227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32258 <row topline="true">
32259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32276 IC_LEFT() IC_RESULT()
32279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32296 IC_RESULT = ! IC_LEFT;
32300 <row topline="true">
32301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32318 IC_LEFT() IC_RESULT()
32321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 Bitwise complement of
32331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32338 IC_RESULT = ~IC_LEFT;
32342 <row topline="true">
32343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32360 IC_LEFT() IC_RESULT()
32363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32370 Rotate right with carry
32373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32380 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
32384 <row topline="true">
32385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32402 IC_LEFT() IC_RESULT()
32405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32412 Rotate left with carry
32415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32422 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
32426 <row topline="true">
32427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32444 IC_LEFT() IC_RESULT()
32447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32454 Get the highest order bit of IC_LEFT
32457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32464 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
32468 <row topline="true">
32469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32486 IC_LEFT() IC_RESULT()
32489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32506 IC_RESULT = - IC_LEFT;
32510 <row topline="true">
32511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32538 Push the operand into stack
32541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32552 <row topline="true">
32553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32580 Pop the operand from the stack
32583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32594 <row topline="true">
32595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32612 IC_LEFT() IC_RESULT()
32615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32622 Call the function represented by IC_LEFT
32625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32632 IC_RESULT = IC_LEFT();
32636 <row topline="true">
32637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32654 IC_LEFT() IC_RESULT()
32657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32664 Call via function pointer
32667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32674 IC_RESULT = (*IC_LEFT)();
32678 <row topline="true">
32679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32706 Return the value in operand IC_LEFT
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32720 <row topline="true">
32721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32762 <row topline="true">
32763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32804 <row topline="true">
32805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32822 IC_LEFT() IC_RIGHT() IC_RESULT()
32825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32842 IC_RESULT = IC_LEFT + IC_RIGHT
32846 <row topline="true">
32847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32864 IC_LEFT() IC_RIGHT() IC_RESULT()
32867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32884 IC_RESULT = IC_LEFT - IC_RIGHT
32888 <row topline="true">
32889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32906 IC_LEFT() IC_RIGHT() IC_RESULT()
32909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32926 IC_RESULT = IC_LEFT * IC_RIGHT;
32930 <row topline="true">
32931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32948 IC_LEFT() IC_RIGHT() IC_RESULT()
32951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32968 IC_RESULT = IC_LEFT / IC_RIGHT;
32972 <row topline="true">
32973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32990 IC_LEFT() IC_RIGHT() IC_RESULT()
32993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33010 IC_RESULT = IC_LEFT % IC_RIGHT;
33014 <row topline="true">
33015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33032 IC_LEFT() IC_RIGHT() IC_RESULT()
33035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33052 IC_RESULT = IC_LEFT < IC_RIGHT;
33056 <row topline="true">
33057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33074 IC_LEFT() IC_RIGHT() IC_RESULT()
33077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33094 IC_RESULT = IC_LEFT > IC_RIGHT;
33098 <row topline="true">
33099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33116 IC_LEFT() IC_RIGHT() IC_RESULT()
33119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33136 IC_RESULT = IC_LEFT == IC_RIGHT;
33140 <row topline="true">
33141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33158 IC_LEFT() IC_RIGHT() IC_RESULT()
33161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33168 Logical and operation
33171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33178 IC_RESULT = IC_LEFT && IC_RIGHT;
33182 <row topline="true">
33183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33200 IC_LEFT() IC_RIGHT() IC_RESULT()
33203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33210 Logical or operation
33213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33220 IC_RESULT = IC_LEFT || IC_RIGHT;
33224 <row topline="true">
33225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33242 IC_LEFT() IC_RIGHT() IC_RESULT()
33245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33262 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33266 <row topline="true">
33267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33284 IC_LEFT() IC_RIGHT() IC_RESULT()
33287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33304 IC_RESULT = IC_LEFT | IC_RIGHT;
33308 <row topline="true">
33309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33326 IC_LEFT() IC_RIGHT() IC_RESULT()
33329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33346 IC_RESULT = IC_LEFT & IC_RIGHT;
33350 <row topline="true">
33351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33368 IC_LEFT() IC_RIGHT() IC_RESULT()
33371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33388 IC_RESULT = IC_LEFT << IC_RIGHT
33392 <row topline="true">
33393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33410 IC_LEFT() IC_RIGHT() IC_RESULT()
33413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33430 IC_RESULT = IC_LEFT >> IC_RIGHT
33434 <row topline="true">
33435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33454 IC_LEFT() IC_RESULT()
33457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33474 IC_RESULT = (*IC_LEFT);
33478 <row topline="true">
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33496 IC_RIGHT() IC_RESULT()
33499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33516 (*IC_RESULT) = IC_RIGHT;
33520 <row topline="true">
33521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33538 IC_RIGHT() IC_RESULT()
33541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33558 IC_RESULT = IC_RIGHT;
33562 <row topline="true">
33563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33580 IC_COND IC_TRUE IC_LABEL
33583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33591 If true label is present then jump to true label if condition is true else
33592 jump to false label if condition is false
33595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33602 if (IC_COND) goto IC_TRUE;
33608 If (!IC_COND) goto IC_FALSE;
33612 <row topline="true">
33613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33630 IC_LEFT() IC_RESULT()
33633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33650 IC_RESULT = &IC_LEFT();
33654 <row topline="true">
33655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33672 IC_JTCOND IC_JTLABELS
33675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33682 Jump to list of labels depending on the value of JTCOND
33685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33696 <row topline="true">
33697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33714 IC_RIGHT() IC_LEFT() IC_RESULT()
33717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33734 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
33738 <row topline="true">
33739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33766 This is used for passing parameters in registers;
33768 move IC_LEFT to the next available parameter register.
33771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33782 <row topline="true">
33783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33810 This is used for receiving parameters passed in registers;
33812 Move the values in the next parameter register to IC_RESULT
33815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33826 <row topline="true" bottomline="true">
33827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33835 (some more have been added)
33838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33884 In the original article Figure II was announced to be downloadable on
33889 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
33896 \begin_inset LatexCommand \index{iCode}
33903 This section shows some details of iCode.
33904 The example C code does not do anything useful; it is used as an example
33905 to illustrate the intermediate code generated by the compiler.
33917 /* This function does nothing useful.
33924 for the purpose of explaining iCode */
33927 short function (data int *x)
33935 short i=10; \SpecialChar ~
33937 /* dead initialization eliminated */
33942 short sum=10; /* dead initialization eliminated */
33955 while (*x) *x++ = *p++;
33969 /* compiler detects i,j to be induction variables */
33973 for (i = 0, j = 10 ; i < 10 ; i++, j
33999 mul += i * 3; \SpecialChar ~
34001 /* this multiplication remains */
34007 gint += j * 3;\SpecialChar ~
34009 /* this multiplication changed to addition */
34023 In addition to the operands each iCode contains information about the filename
34024 and line it corresponds to in the source file.
34025 The first field in the listing should be interpreted as follows:
34030 Filename(linenumber: iCode Execution sequence number : ICode hash table
34031 key : loop depth of the iCode).
34036 Then follows the human readable form of the ICode operation.
34037 Each operand of this triplet form can be of three basic types a) compiler
34038 generated temporary b) user defined variable c) a constant value.
34039 Note that local variables and parameters are replaced by compiler generated
34042 \begin_inset LatexCommand \index{Live range analysis}
34046 are computed only for temporaries (i.e.
34047 live ranges are not computed for global variables).
34049 \begin_inset LatexCommand \index{Register allocation}
34053 are allocated for temporaries only.
34054 Operands are formatted in the following manner:
34059 Operand Name [lr live-from : live-to ] { type information } [ registers
34065 As mentioned earlier the live ranges are computed in terms of the execution
34066 sequence number of the iCodes, for example
34068 the iTemp0 is live from (i.e.
34069 first defined in iCode with execution sequence number 3, and is last used
34070 in the iCode with sequence number 5).
34071 For induction variables such as iTemp21 the live range computation extends
34072 the lifetime from the start to the end of the loop.
34074 The register allocator used the live range information to allocate registers,
34075 the same registers may be used for different temporaries if their live
34076 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
34077 iTemp17 since their live ranges do not overlap.
34078 In addition the allocator also takes into consideration the type and usage
34079 of a temporary, for example itemp6 is a pointer to near space and is used
34080 as to fetch data from (i.e.
34081 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
34082 Some short lived temporaries are allocated to special registers which have
34083 meaning to the code generator e.g.
34084 iTemp13 is allocated to a pseudo register CC which tells the back end that
34085 the temporary is used only for a conditional jump the code generation makes
34086 use of this information to optimize a compare and jump ICode.
34088 There are several loop optimizations
34089 \begin_inset LatexCommand \index{Loop optimization}
34093 performed by the compiler.
34094 It can detect induction variables iTemp21(i) and iTemp23(j).
34095 Also note the compiler does selective strength reduction
34096 \begin_inset LatexCommand \index{Strength reduction}
34101 the multiplication of an induction variable in line 18 (gint = j * 3) is
34102 changed to addition, a new temporary iTemp17 is allocated and assigned
34103 a initial value, a constant 3 is then added for each iteration of the loop.
34104 The compiler does not change the multiplication
34105 \begin_inset LatexCommand \index{Multiplication}
34109 in line 17 however since the processor does support an 8 * 8 bit multiplication.
34111 Note the dead code elimination
34112 \begin_inset LatexCommand \index{Dead-code elimination}
34116 optimization eliminated the dead assignments in line 7 & 8 to I and sum
34124 Sample.c (5:1:0:0) _entry($9) :
34129 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34134 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
34139 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34144 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34150 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34155 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34161 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34166 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34172 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34178 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34184 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34190 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34191 * int}[r0] + 0x2 {short}
34196 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34201 Sample.c(11:17:21:0)_whilebreak_0($3) :
34206 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34211 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34216 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34221 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34226 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34231 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34236 Sample.c(15:24:26:1)_forcond_0($4) :
34241 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34247 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34252 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34253 + ITemp21 [lr21:38]{short}[r4]
34258 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
34264 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
34265 + iTemp15 [lr29:30]{short}[r1]
34270 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
34276 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
34282 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
34288 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
34294 Sample.c(19:38:47:1) goto _forcond_0($4)
34299 Sample.c(19:39:48:0)_forbreak_0($7) :
34304 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
34305 + ITemp11 [lr19:40]{short}[r3]
34310 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
34315 Sample.c(20:42:51:0)_return($8) :
34320 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
34326 Finally the code generated for this function:
34367 ; ----------------------------------------------
34372 ; function function
34377 ; ----------------------------------------------
34387 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
34399 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
34411 ;_whilecontinue_0($1) :
34421 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
34426 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34485 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
34504 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
34551 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
34591 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
34617 ; iTemp6 [lr5:16]{_near * int}[r0] =
34622 ; iTemp6 [lr5:16]{_near * int}[r0] +
34639 ; goto _whilecontinue_0($1)
34651 ; _whilebreak_0($3) :
34661 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34673 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34685 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34697 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34716 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34745 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
34750 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34795 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
34800 ; iTemp21 [lr21:38]{short}[r4]
34826 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
34859 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
34864 ; iTemp15 [lr29:30]{short}[r1]
34883 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
34930 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
34977 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
34989 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
35003 cjne r5,#0xff,00104$
35015 ; goto _forcond_0($4)
35027 ; _forbreak_0($7) :
35037 ; ret iTemp24 [lr40:41]{short}
35080 A few words about basic block successors, predecessors and dominators
35083 Successors are basic blocks
35084 \begin_inset LatexCommand \index{Basic blocks}
35088 that might execute after this basic block.
35090 Predecessors are basic blocks that might execute before reaching this basic
35093 Dominators are basic blocks that WILL execute before reaching this basic
35127 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35130 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35133 c) domVect of [BB4] = BB1 ...
35134 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35142 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35152 Thanks to all the other volunteer developers who have helped with coding,
35153 testing, web-page creation, distribution sets, etc.
35154 You know who you are :-)
35162 Also thanks to Sourceforge
35163 \begin_inset LatexCommand \url{http://www.sf.net}
35167 which has hosted the project since 1999 and donates significant download
35168 bandwidth and probably more than
35176 CPU cycles per day.
35184 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35185 minutes for (configure+make+regression test), and there is (i386, amd64,
35186 alpha, ppc64, (mingw32), sparc, macosx).
35193 This document was initially written by Sandeep Dutta
35196 All product names mentioned herein may be trademarks
35197 \begin_inset LatexCommand \index{Trademarks}
35201 of their respective companies.
35208 To avoid confusion, the installation and building options for SDCC itself
35209 (chapter 2) are not part of the index.
35213 \begin_inset LatexCommand \printindex{}