1 #LyX 1.4.1 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
31 \use_numerical_citations 0
32 \paperorientation portrait
39 \paragraph_separation indent
41 \quotes_language swedish
51 Please note: double dashed longoptions (e.g.
52 --version) are written this way: -
68 three consecutive dashes simply result in a long resp.
72 Architecture specific stuff (like memory models, code examples) should maybe
76 into seperate sections/chapters/appendices (it is hard to document PIC or
80 a 8051 centered document) - for now simply add.
87 SDCC Compiler User Guide
105 The above strings enclosed in $ are automatically updated by Subversion
112 \begin_inset LatexCommand \tableofcontents{}
145 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
150 designed for 8 bit Microprocessors.
151 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
153 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
157 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
158 Zilog Z80 based MCUs.
159 It can be retargeted for other microprocessors, support for Microchip PIC,
160 Atmel AVR is under development.
161 The entire source code for the compiler is distributed under GPL.
163 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
168 \begin_inset LatexCommand \index{aslink}
172 , an open source retargetable assembler & linker.
173 SDCC has extensive language extensions suitable for utilizing various microcont
174 rollers and underlying hardware effectively.
179 In addition to the MCU specific optimizations SDCC also does a host of
180 standard optimizations like:
183 global sub expression elimination,
186 loop optimizations (loop invariant, strength reduction of induction variables
190 constant folding & propagation,
196 dead code elimination
206 For the back-end SDCC uses a global register allocation scheme which should
207 be well suited for other 8 bit MCUs.
212 The peep hole optimizer uses a rule based substitution mechanism which
218 Supported data-types are:
222 <lyxtabular version="3" rows="8" columns="5">
224 <column alignment="center" valignment="top" leftline="true" width="0">
225 <column alignment="center" valignment="top" leftline="true" width="0">
226 <column alignment="center" valignment="top" leftline="true" width="0">
227 <column alignment="center" valignment="top" leftline="true" width="0">
228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
229 <row topline="true" bottomline="true">
230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 <row topline="true" bottomline="true">
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 -2.147.483.648, +2.147.483.647
472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
481 <row topline="true" bottomline="true">
482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
532 <row topline="true" bottomline="true">
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 The compiler also allows
582 inline assembler code
584 to be embedded anywhere in a function.
585 In addition, routines developed in assembly can also be called.
590 provides an option (-
602 -cyclomatic) to report the relative complexity of a function.
603 These functions can then be further optimized, or hand coded in assembly
609 SDCC also comes with a companion source level debugger SDCDB, the debugger
610 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
615 The latest version can be downloaded from
616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
626 Please note: the compiler will probably always be some steps ahead of this
631 \begin_inset LatexCommand \index{Status of documentation}
640 Obviously this has pros and cons
650 All packages used in this compiler system are
658 ; source code for all the sub-packages (pre-processor, assemblers, linkers
659 etc) is distributed with the package.
660 This documentation is maintained using a freeware word processor (LyX).
663 program is free software; you can redistribute it and/or modify it under
664 the terms of the GNU General Public License
665 \begin_inset LatexCommand \index{GNU General Public License, GPL}
669 as published by the Free Software Foundation; either version 2, or (at
670 your option) any later version.
671 This program is distributed in the hope that it will be useful, but WITHOUT
672 ANY WARRANTY; without even the implied warranty
673 \begin_inset LatexCommand \index{warranty}
677 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
678 See the GNU General Public License for more details.
679 You should have received a copy of the GNU General Public License along
680 with this program; if not, write to the Free Software Foundation, 59 Temple
681 Place - Suite 330, Boston, MA 02111-1307, USA.
682 In other words, you are welcome to use, share and improve this program.
683 You are forbidden to forbid anyone else to use, share and improve what
685 Help stamp out software-hoarding!
688 Typographic conventions
689 \begin_inset LatexCommand \index{Typographic conventions}
696 Throughout this manual, we will use the following convention.
697 Commands you have to type in are printed in
705 Code samples are printed in
710 Interesting items and new terms are printed in
716 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
720 with previous versions
721 \begin_inset LatexCommand \index{Compatibility with previous versions}
728 This version has numerous bug fixes compared with the previous version.
729 But we also introduced some incompatibilities with older versions.
730 Not just for the fun of it, but to make the compiler more stable, efficient
732 \begin_inset LatexCommand \index{ANSI-compliance}
737 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
741 for ANSI-Compliance).
747 short is now equivalent to int (16 bits), it used to be equivalent to char
748 (8 bits) which is not ANSI compliant.
751 the default directory for gcc-builds where include, library and documentation
752 files are stored is now in /usr/local/share.
755 char type parameters to vararg
756 \begin_inset LatexCommand \index{vararg, va\_arg}
760 functions are casted to int unless explicitly casted
761 \begin_inset Marginal
788 will push a as an int and as a char resp.
803 -regextend has been removed.
818 -noregparms has been removed.
833 -stack-after-data has been removed.
837 \begin_inset LatexCommand \index{bit}
842 \begin_inset LatexCommand \index{sbit}
847 \begin_inset LatexCommand \index{\_\_sbit}
851 types now consistently behave like the C99 _Bool type with respect to type
853 \begin_inset LatexCommand \index{type conversion}
858 \begin_inset LatexCommand \index{type promotion}
863 The most common incompatibility resulting from this change is related to
865 \begin_inset LatexCommand \index{Bit toggling}
880 \begin_inset LatexCommand \index{\~\/ Operator}
884 b; /* equivalent to b=1 instead of toggling b */
885 \begin_inset Marginal
900 b = !b; /* toggles b */
904 In previous versions, both forms would have toggled the bit.
909 <pending: more incompatibilities?>
915 What do you need before you start installation of SDCC? A computer, and
917 The preferred method of installation is to compile SDCC from source using
919 For Windows some pre-compiled binary distributions are available for your
921 You should have some experience with command line tools and compiler use.
927 The SDCC home page at
928 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
932 is a great place to find distribution sets.
933 You can also find links to the user mailing lists that offer help or discuss
934 SDCC with other SDCC users.
935 Web links to other SDCC related sites can also be found here.
936 This document can be found in the DOC directory of the source package as
938 A pdf version of this document is available at
939 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
944 Some of the other tools (simulator and assembler) included with SDCC contain
945 their own documentation and can be found in the source distribution.
946 If you want the latest unreleased software, the complete source package
947 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
951 Wishes for the future
954 There are (and always will be) some things that could be done.
955 Here are some I can think of:
962 char KernelFunction3(char p) at 0x340;
970 \begin_inset LatexCommand \index{code banking (limited support)}
980 If you can think of some more, please see the section
981 \begin_inset LatexCommand \ref{sub:Requesting-Features}
985 about filing feature requests
986 \begin_inset LatexCommand \index{Requesting features}
991 \begin_inset LatexCommand \index{Feature request}
1001 \begin_inset LatexCommand \index{Installation}
1008 For most users it is sufficient to skip to either section
1009 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1014 \begin_inset LatexCommand \ref{sub:Windows-Install}
1019 More detailed instructions follow below.
1023 \begin_inset LatexCommand \index{Options SDCC configuration}
1030 The install paths, search paths and other options are defined when running
1032 The defaults can be overridden by:
1035 \labelwidthstring 00.00.0000
1048 -prefix see table below
1051 \labelwidthstring 00.00.0000
1064 -exec_prefix see table below
1067 \labelwidthstring 00.00.0000
1080 -bindir see table below
1083 \labelwidthstring 00.00.0000
1096 -datadir see table below
1099 \labelwidthstring 00.00.0000
1112 -datarootdir see table below
1117 \labelwidthstring 00.00.0000
1120 docdir environment variable, see table below
1123 \labelwidthstring 00.00.0000
1126 include_dir_suffix environment variable, see table below
1129 \labelwidthstring 00.00.0000
1132 lib_dir_suffix environment variable, see table below
1135 \labelwidthstring 00.00.0000
1138 sdccconf_h_dir_separator environment variable, either / or
1143 This character will only be used in sdccconf.h; don't forget it's a C-header,
1144 therefore a double-backslash is needed there.
1149 \labelwidthstring 00.00.0000
1162 -disable-mcs51-port Excludes the Intel mcs51 port
1165 \labelwidthstring 00.00.0000
1178 -disable-gbz80-port Excludes the Gameboy gbz80 port
1181 \labelwidthstring 00.00.0000
1194 -disable-z80-port Excludes the z80 port
1197 \labelwidthstring 00.00.0000
1210 -disable-avr-port Excludes the AVR port
1213 \labelwidthstring 00.00.0000
1226 -disable-ds390-port Excludes the DS390 port
1229 \labelwidthstring 00.00.0000
1242 -disable-hc08-port Excludes the HC08 port
1245 \labelwidthstring 00.00.0000
1258 -disable-pic-port Excludes the PIC port
1261 \labelwidthstring 00.00.0000
1274 -disable-xa51-port Excludes the XA51 port
1277 \labelwidthstring 00.00.0000
1290 -disable-ucsim Disables configuring and building of ucsim
1293 \labelwidthstring 00.00.0000
1306 -disable-device-lib Disables automatically building device libraries
1309 \labelwidthstring 00.00.0000
1322 -disable-packihx Disables building packihx
1327 \labelwidthstring 00.00.0000
1340 -enable-doc Build pdf, html and txt files from the lyx sources
1343 \labelwidthstring 00.00.0000
1356 -enable-libgc Use the Bohem memory allocator.
1357 Lower runtime footprint.
1360 Furthermore the environment variables CC, CFLAGS, ...
1361 the tools and their arguments can be influenced.
1362 Please see `configure -
1374 -help` and the man/info pages of `configure` for details.
1379 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1380 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1381 SDCC_LIB_NAME are defined by `configure` too.
1382 At the moment it's not possible to change the default settings (it was
1383 simply never required).
1387 These configure options are compiled into the binaries,
1388 and can only be changed by rerunning 'configure' and recompiling SDCC.
1389 The configure options are written in
1393 to distinguish them from run time environment variables (see section search
1399 \begin_inset Quotes sld
1403 \begin_inset Quotes srd
1406 are used by the SDCC team to build the official Win32 binaries.
1407 The SDCC team uses Mingw32 to build the official Windows binaries, because
1414 a gcc compiler and last but not least
1417 the binaries can be built by cross compiling on SDCC Distributed Compile
1421 See the examples, how to pass the Win32 settings to 'configure'.
1422 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1423 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1434 \begin_inset Tabular
1435 <lyxtabular version="3" rows="9" columns="3">
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" width="0in">
1439 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1440 <row topline="true" bottomline="true">
1441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1466 <row topline="true">
1467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1496 <row topline="true">
1497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1528 <row topline="true">
1529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1566 <row topline="true">
1567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1598 <row topline="true">
1599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1632 <row topline="true">
1633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1698 <row topline="true" bottomline="true">
1699 <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">
1736 'configure' also computes relative paths.
1737 This is needed for full relocatability of a binary package and to complete
1738 search paths (see section search paths below):
1744 \begin_inset Tabular
1745 <lyxtabular version="3" rows="4" columns="3">
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" width="0in">
1749 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1750 <row topline="true" bottomline="true">
1751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1776 <row topline="true" bottomline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1804 <row bottomline="true">
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1832 <row bottomline="true">
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1888 \begin_inset Quotes srd
1892 \begin_inset Quotes srd
1908 \begin_inset Quotes srd
1912 \begin_inset Quotes srd
1944 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1953 \begin_inset Quotes srd
1956 i586-mingw32msvc-gcc
1957 \begin_inset Quotes srd
1961 \begin_inset Quotes srd
1964 i586-mingw32msvc-g++
1965 \begin_inset Quotes srd
1973 \begin_inset Quotes srd
1976 i586-mingw32msvc-ranlib
1977 \begin_inset Quotes srd
1985 \begin_inset Quotes srd
1988 i586-mingw32msvc-strip
1989 \begin_inset Quotes srd
2009 \begin_inset Quotes srd
2013 \begin_inset Quotes srd
2033 \begin_inset Quotes srd
2037 \begin_inset Quotes srd
2045 \begin_inset Quotes srd
2051 \begin_inset Quotes srd
2059 \begin_inset Quotes srd
2063 \begin_inset Quotes srd
2071 \begin_inset Quotes srd
2075 \begin_inset Quotes srd
2082 sdccconf_h_dir_separator=
2083 \begin_inset Quotes srd
2095 \begin_inset Quotes srd
2130 -host=i586-mingw32msvc
2146 -build=unknown-unknown-linux-gnu
2150 \begin_inset Quotes sld
2154 \begin_inset Quotes srd
2157 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2178 \begin_inset Quotes srd
2182 \begin_inset Quotes srd
2202 \begin_inset Quotes srd
2206 \begin_inset Quotes srd
2214 \begin_inset Quotes srd
2220 \begin_inset Quotes srd
2228 \begin_inset Quotes srd
2232 \begin_inset Quotes srd
2240 \begin_inset Quotes srd
2244 \begin_inset Quotes srd
2251 sdccconf_h_dir_separator=
2252 \begin_inset Quotes srd
2264 \begin_inset Quotes srd
2272 \begin_inset Quotes srd
2276 \begin_inset Quotes srd
2284 \begin_inset Quotes srd
2288 \begin_inset Quotes srd
2294 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2307 -C' turns on caching, which gives a little bit extra speed.
2308 However if options are changed, it can be necessary to delete the config.cache
2313 \added_space_bottom medskip
2314 \begin_inset LatexCommand \label{sub:Install-paths}
2319 \begin_inset LatexCommand \index{Install paths}
2328 \begin_inset Tabular
2329 <lyxtabular version="3" rows="5" columns="4">
2331 <column alignment="left" valignment="top" leftline="true" width="0">
2332 <column alignment="left" valignment="top" leftline="true" width="0">
2333 <column alignment="left" valignment="top" leftline="true" width="0">
2334 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2335 <row topline="true" bottomline="true">
2336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2377 <row topline="true">
2378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2417 <row topline="true">
2418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2432 $DATADIR/ $INCLUDE_DIR_SUFFIX
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2440 /usr/local/share/sdcc/include
2444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2457 <row topline="true">
2458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2472 $DATADIR/$LIB_DIR_SUFFIX
2476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2480 /usr/local/share/sdcc/lib
2484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2497 <row topline="true" bottomline="true">
2498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2520 /usr/local/share/sdcc/doc
2524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2546 *compiler, preprocessor, assembler, and linker
2552 is auto-appended by the compiler, e.g.
2553 small, large, z80, ds390 etc
2557 The install paths can still be changed during `make install` with e.g.:
2560 make install prefix=$(HOME)/local/sdcc
2563 Of course this doesn't change the search paths compiled into the binaries.
2568 r the install path can be changed by defining DESTDIR
2569 \begin_inset LatexCommand \index{DESTDIR}
2576 make install DESTDIR=$(HOME)/sdcc.rpm/
2579 Please note that DESTDIR must have a trailing slash!
2583 \begin_inset LatexCommand \label{sub:Search-Paths}
2588 \begin_inset LatexCommand \index{Search path}
2595 Some search paths or parts of them are determined by configure variables
2600 , see section above).
2601 Further search paths are determined by environment variables during runtime.
2604 The paths searched when running the compiler are as follows (the first
2610 Binary files (preprocessor, assembler and linker)
2616 \begin_inset Tabular
2617 <lyxtabular version="3" rows="4" columns="3">
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" width="0in">
2621 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2622 <row topline="true" bottomline="true">
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2648 <row topline="true">
2649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2678 <row topline="true">
2679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2683 Path of argv[0] (if available)
2687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2704 <row topline="true" bottomline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2747 \begin_inset Tabular
2748 <lyxtabular version="3" rows="6" columns="3">
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2752 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2753 <row topline="true" bottomline="true">
2754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2779 <row topline="true">
2780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2841 <row topline="true">
2842 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2867 <row topline="true">
2868 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2882 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2905 <row topline="true">
2906 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2987 <row topline="true" bottomline="true">
2988 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3004 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3008 /usr/local/share/sdcc/
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3045 -nostdinc disables the last two search paths.
3055 With the exception of
3056 \begin_inset Quotes sld
3072 \begin_inset Quotes srd
3079 is auto-appended by the compiler (e.g.
3080 small, large, z80, ds390 etc.).
3087 \begin_inset Tabular
3088 <lyxtabular version="3" rows="6" columns="3">
3090 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3091 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3092 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3093 <row topline="true" bottomline="true">
3094 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3102 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3119 <row topline="true">
3120 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3181 <row topline="true">
3182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3194 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3221 <row topline="true">
3222 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3232 $LIB_DIR_SUFFIX/<model>
3236 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3250 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3267 <row topline="true">
3268 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3282 $LIB_DIR_SUFFIX/<model>
3286 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3395 <row topline="true" bottomline="true">
3396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3404 $LIB_DIR_SUFFIX/<model>
3408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3412 /usr/local/share/sdcc/
3420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3442 Don't delete any of the stray spaces in the table above without checking
3443 the HTML output (last line)!
3465 -nostdlib disables the last two search paths.
3469 \begin_inset LatexCommand \index{Building SDCC}
3476 Building SDCC on Linux
3477 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3486 Download the source package
3488 either from the SDCC Subversion repository or from snapshot builds
3490 , it will be named something like sdcc
3501 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3510 Bring up a command line terminal, such as xterm.
3515 Unpack the file using a command like:
3518 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3519 \begin_inset Quotes srd
3525 , this will create a sub-directory called sdcc with all of the sources.
3528 Change directory into the main SDCC directory, for example type:
3545 This configures the package for compilation on your system.
3561 All of the source packages will compile, this can take a while.
3577 This copies the binary executables, the include files, the libraries and
3578 the documentation to the install directories.
3579 Proceed with section
3580 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3587 Building SDCC on OSX 2.x
3590 Follow the instruction for Linux.
3594 On OSX 2.x it was reported, that the default
3595 gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3596 Fortunately there's also gcc 2.9.x installed, which works fine.
3597 This compiler can be selected by running 'configure' with:
3600 ./configure CC=gcc2 CXX=g++2
3603 Cross compiling SDCC on Linux for Windows
3606 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3607 See section 'Configure Options'.
3610 Building SDCC using Cygwin and Mingw32
3613 For building and installing a Cygwin executable follow the instructions
3619 \begin_inset Quotes sld
3623 \begin_inset Quotes srd
3626 Win32-binary can be built, which will not need the Cygwin-DLL.
3627 For the necessary 'configure' options see section 'configure options' or
3628 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3633 Cygwin on Windows download setup.exe from
3634 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3640 \begin_inset Quotes sld
3643 default text file type
3644 \begin_inset Quotes srd
3648 \begin_inset Quotes sld
3652 \begin_inset Quotes srd
3655 and download/install at least the following packages.
3656 Some packages are selected by default, others will be automatically selected
3657 because of dependencies with the manually selected packages.
3658 Never deselect these packages!
3667 gcc ; version 3.x is fine, no need to use the old 2.9x
3670 binutils ; selected with gcc
3676 rxvt ; a nice console, which makes life much easier under windoze (see below)
3679 man ; not really needed for building SDCC, but you'll miss it sooner or
3683 less ; not really needed for building SDCC, but you'll miss it sooner or
3687 svn ; only if you use Subversion access
3690 If you want to develop something you'll need:
3693 python ; for the regression tests
3696 gdb ; the gnu debugger, together with the nice GUI
3697 \begin_inset Quotes sld
3701 \begin_inset Quotes srd
3707 openssh ; to access the CF or commit changes
3710 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3711 use autoconf-stable!
3714 rxvt is a nice console with history.
3715 Replace in your cygwin.bat the line
3736 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3739 -bg black -fg white -geometry 100x65 -e bash -
3754 Text selected with the mouse is automatically copied to the clipboard, pasting
3755 works with shift-insert.
3759 The other good tip is to make sure you have no //c/-styl
3760 e paths anywhere, use /cygdrive/c/ instead.
3761 Using // invokes a network lookup which is very slow.
3763 \begin_inset Quotes sld
3767 \begin_inset Quotes srd
3770 is too long, you can change it with e.g.
3776 SDCC sources use the unix line ending LF.
3777 Life is much easier, if you store the source tree on a drive which is mounted
3779 And use an editor which can handle LF-only line endings.
3780 Make sure not to commit files with windows line endings.
3781 The tabulator spacing
3782 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3786 used in the project is 8.
3787 Although a tabulator spacing of 8 is a sensible choice for programmers
3788 (it's a power of 2 and allows to display 8/16 bit signed variables without
3789 loosing columns) the plan is to move towards using only spaces in the source.
3792 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3797 Download the source package
3799 either from the SDCC Subversion repository or from the
3800 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
3806 , it will be named something like sdcc
3810 -yyyymmdd-rrrr.tar.bz2.
3813 SDCC is distributed with all the projects, workspaces, and files you need
3814 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3815 The workspace name is 'sdcc.dsw'.
3816 Please note that as it is now, all the executables are created in a folder
3820 Once built you need to copy the executables from sdcc
3824 bin before running SDCC.
3829 WARNING: Visual studio is very picky with line terminations; it expects
3830 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3831 When using the Subversion repository it's easiest to configure the svn
3832 client to convert automatically for you.
3833 If however you are getting a message such as "This makefile was not generated
3834 by Developer Studio etc.
3836 \begin_inset Quotes srd
3839 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3840 need to convert the Unix style line endings to DOS style line endings.
3841 To do so you can use the
3842 \begin_inset Quotes sld
3846 \begin_inset Quotes srd
3849 utility freely available on the internet.
3850 Doug Hawkins reported in the sdcc-user list that this works:
3858 SDCC> unix2dos sdcc.dsw
3864 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3868 In order to build SDCC with MSVC
3869 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3870 One good place to get them is
3871 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3879 Download the file UnxUtils
3880 \begin_inset LatexCommand \index{UnxUtils}
3885 Now you have to install the utilities and setup MSVC so it can locate the
3887 Here there are two alternatives (choose one!):
3894 a) Extract UnxUtils.zip to your C:
3896 hard disk PRESERVING the original paths, otherwise bison won't work.
3897 (If you are using WinZip make certain that 'Use folder names' is selected)
3902 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3903 'Show directories for:' select 'Executable files', and in the directories
3904 window add a new path: 'C:
3914 (As a side effect, you get a bunch of Unix utilities that
3915 could be useful, such as diff and patch.)
3922 This one avoids extracting a bunch of files you may not
3923 use, but requires some extra work:
3927 a) Create a directory were to put the
3928 tools needed, or use a directory already present.
3935 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3936 gawk.exe to such directory WITHOUT preserving the original paths.
3937 (If you are using WinZip make certain that 'Use folder names' is not selected)
3942 ) Rename bison.exe to '_bison.exe'.
3946 d) Create a batch file 'bison.bat' in 'C:
3950 ' and add these lines:
3970 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3974 Steps 'c' and 'd' are needed
3975 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3976 reside in some weird Unix directory, '/usr/local/share/' I think.
3977 So it is necessary to tell bison where those files are located if they
3978 are not in such directory.
3979 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3984 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3985 in 'Show directories for:' select 'Executable files', and in the directories
3986 window add a new path: 'c:
3989 Note that you can use any other path instead of 'c:
3991 util', even the path where the Visual C++ tools are, probably: 'C:
3995 Microsoft Visual Studio
4000 So you don't have to execute step 'e' :)
4004 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4005 the executables from sdcc
4009 bin, and you can compile using SDCC.
4012 Building SDCC Using Borland
4015 From the sdcc directory, run the command "make -f Makefile.bcc".
4016 This should regenerate all the .exe files in the bin directory except for
4020 If you modify any source files and need to rebuild, be aware that the dependenci
4021 es may not be correctly calculated.
4022 The safest option is to delete all .obj files and run the build again.
4023 From a Cygwin BASH prompt, this can easily be done with the command (be
4024 sure you are in the sdcc directory):
4034 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4036 ) -print -exec rm {}
4045 or on Windows NT/2000/XP from the command prompt with the command:
4052 del /s *.obj *.lib *.rul
4055 from the sdcc directory.
4058 Windows Install Using a ZIP Package
4061 Download the binary zip package from
4062 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4066 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4067 This should unpack to a group of sub-directories.
4068 An example directory structure after unpacking the mingw32 package is:
4073 bin for the executables, c:
4081 lib for the include and libraries.
4084 Adjust your environment variable PATH to include the location of the bin
4085 directory or start sdcc using the full path.
4088 Windows Install Using the Setup Program
4089 \begin_inset LatexCommand \label{sub:Windows-Install}
4096 Download the setup program
4098 sdcc-x.y.z-setup.exe
4100 for an official release from
4103 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4107 or a setup program for one of the snapshots
4109 sdcc-yyyymmdd-xxxx-setup.exe
4112 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4117 A windows typical installer will guide you through the installation process.
4121 \begin_inset LatexCommand \index{VPATH}
4128 SDCC supports the VPATH feature provided by configure and make.
4129 It allows to separate the source and build trees.
4161 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4162 # extract source to directory sdcc
4167 mkdir sdcc.build\SpecialChar ~
4176 # put output in sdcc.build
4186 ../sdcc/configure\SpecialChar ~
4194 # configure is doing all the magic!
4207 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4208 It automagically computes the variables srcdir, top_srcdir and top_buildir
4214 the generated files will be in ~/sdcc.build, while the source files stay
4217 This is not only usefull for building different binaries, e.g.
4218 when cross compiling.
4219 It also gives you a much better overview in the source tree when all the
4220 generated files are not scattered between the source files.
4221 And the best thing is: if you want to change a file you can leave the original
4222 file untouched in the source directory.
4223 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4224 Makefile.dep` and `make`.
4229 will do the rest for you!
4232 Building the Documentation
4247 -enable-doc to the configure arguments to build the documentation together
4248 with all the other stuff.
4249 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4250 dvips and makeindex) to get the job done.
4251 Another possibility is to change to the doc directory and to type
4255 \begin_inset Quotes srd
4259 \begin_inset Quotes srd
4266 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4269 \begin_inset LatexCommand \url{http://www.lyx.org}
4273 as editor is straightforward.
4274 Prebuilt documentation in html and pdf format is available from
4275 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4282 Reading the Documentation
4283 \begin_inset LatexCommand \index{Documentation}
4290 Currently reading the document in pdf format is recommended, as for unknown
4291 reason the hyperlinks are working there whereas in the html version they
4297 If you should know why please drop us a note
4304 You'll find the pdf version
4305 \begin_inset LatexCommand \index{PDF version of this document}
4310 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4318 \begin_inset LatexCommand \index{HTML version of this document}
4323 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4329 This documentation is in some aspects different from a commercial documentation:
4333 It tries to document SDCC for several processor architectures in one document
4334 (commercially these probably would be separate documents/products).
4336 \begin_inset LatexCommand \index{Status of documentation}
4340 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4342 Z80, PIC14, PIC16 and HC08.
4345 There are many references pointing away from this documentation.
4346 Don't let this distract you.
4348 was a reference like
4349 \begin_inset LatexCommand \url{http://www.opencores.org}
4353 together with a statement
4354 \begin_inset Quotes sld
4357 some processors which are targetted by SDCC can be implemented in a
4374 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4379 \begin_inset Quotes srd
4383 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4388 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4393 \begin_inset Quotes sld
4396 have you ever heard of an open source compiler that compiles a subset of
4398 \begin_inset Quotes srd
4401 we expect you to have a quick look there and come back.
4402 If you read this you are on the right track.
4405 Some sections attribute more space to problems, restrictions and warnings
4406 than to the solution.
4409 The installation section and the section about the debugger is intimidating.
4412 There are still lots of typos and there are more different writing styles
4416 Testing the SDCC Compiler
4417 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4424 The first thing you should do after installing your SDCC compiler is to
4442 \begin_inset LatexCommand \index{version}
4449 at the prompt, and the program should run and output its version like:
4454 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4458 If it doesn't run, or gives a message about not finding sdcc program, then
4459 you need to check over your installation.
4460 Make sure that the sdcc bin directory is in your executable search path
4461 defined by the PATH environment setting (
4466 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4473 Install trouble-shooting for suggestions
4476 Make sure that the sdcc program is in the bin folder, if not perhaps something
4477 did not install correctly.
4485 is commonly installed as described in section
4486 \begin_inset Quotes sld
4489 Install and search paths
4490 \begin_inset Quotes srd
4499 Make sure the compiler works on a very simple example.
4500 Type in the following test.c program using your favorite
4526 Compile this using the following command:
4535 If all goes well, the compiler will generate a test.asm and test.rel file.
4536 Congratulations, you've just compiled your first program with SDCC.
4537 We used the -c option to tell SDCC not to link the generated code, just
4538 to keep things simple for this step.
4546 The next step is to try it with the linker.
4556 If all goes well the compiler will link with the libraries and produce
4557 a test.ihx output file.
4562 (no test.ihx, and the linker generates warnings), then the problem is most
4571 usr/local/share/sdcc/lib directory
4578 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4585 Install trouble-shooting for suggestions).
4593 The final test is to ensure
4601 header files and libraries.
4602 Edit test.c and change it to the following:
4619 strcpy(str1, "testing");
4626 Compile this by typing
4633 This should generate a test.ihx output file, and it should give no warnings
4634 such as not finding the string.h file.
4635 If it cannot find the string.h file, then the problem is that
4639 cannot find the /usr/local/share/sdcc/include directory
4646 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4653 Install trouble-shooting section for suggestions).
4673 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4677 to find exactly where SDCC is looking for the include and lib files.
4680 Install Trouble-shooting
4681 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4686 \begin_inset LatexCommand \index{Install trouble-shooting}
4693 If SDCC does not build correctly
4696 A thing to try is starting from scratch by unpacking the .tgz source package
4697 again in an empty directory.
4705 ./configure 2>&1 | tee configure.log
4719 make 2>&1 | tee make.log
4726 If anything goes wrong, you can review the log files to locate the problem.
4727 Or a relevant part of this can be attached to an email that could be helpful
4728 when requesting help from the mailing list.
4732 \begin_inset Quotes sld
4736 \begin_inset Quotes srd
4743 \begin_inset Quotes sld
4747 \begin_inset Quotes srd
4750 command is a script that analyzes your system and performs some configuration
4751 to ensure the source package compiles on your system.
4752 It will take a few minutes to run, and will compile a few tests to determine
4753 what compiler features are installed.
4757 \begin_inset Quotes sld
4761 \begin_inset Quotes srd
4767 This runs the GNU make tool, which automatically compiles all the source
4768 packages into the final installed binary executables.
4772 \begin_inset Quotes sld
4776 \begin_inset Quotes erd
4782 This will install the compiler, other executables libraries and include
4783 files into the appropriate directories.
4785 \begin_inset LatexCommand \ref{sub:Install-paths}
4791 \begin_inset LatexCommand \ref{sub:Search-Paths}
4796 about install and search paths.
4798 On most systems you will need super-user privilege
4805 SDCC is not just a compiler, but a collection of tools by various developers.
4806 These include linkers, assemblers, simulators and other components.
4807 Here is a summary of some of the components.
4808 Note that the included simulator and assembler have separate documentation
4809 which you can find in the source package in their respective directories.
4810 As SDCC grows to include support for other processors, other packages from
4811 various developers are included and may have their own sets of documentation.
4816 might want to look at the files which are installed in <installdir>.
4817 At the time of this writing, we find the following programs for gcc-builds:
4822 In <installdir>/bin:
4825 sdcc - The compiler.
4828 sdcpp - The C preprocessor.
4831 asx8051 - The assembler for 8051 type processors.
4838 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4841 aslink -The linker for 8051 type processors.
4848 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4851 s51 - The ucSim 8051 simulator.
4854 sdcdb - The source debugger.
4857 packihx - A tool to pack (compress) Intel hex files.
4860 In <installdir>/share/sdcc/include
4866 In <installdir>/share/sdcc/lib
4869 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4873 In <installdir>/share/sdcc/doc
4879 As development for other processors proceeds, this list will expand to include
4880 executables to support processors like AVR, PIC, etc.
4886 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4887 the assembler and linkage editor.
4890 sdcpp - The C-Preprocessor
4894 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4898 is a modified version of the GNU cpp
4899 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4904 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4909 The C preprocessor is used to pull in #include sources, process #ifdef
4910 statements, #defines and so on.
4921 - The Assemblers and Linkage Editors
4924 This is retargettable assembler & linkage editor, it was developed by Alan
4926 John Hartman created the version for 8051, and I (Sandeep) have made some
4927 enhancements and bug fixes for it to work properly with SDCC.
4934 \begin_inset LatexCommand \index{s51}
4938 is a freeware, opensource simulator developed by Daniel Drotos.
4939 The simulator is built as part of the build process.
4940 For more information visit Daniel's web site at:
4941 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4946 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4950 sdcdb - Source Level Debugger
4954 \begin_inset LatexCommand \index{SDCDB (debugger)}
4958 is the companion source level debugger.
4959 More about SDCDB in section
4960 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4965 The current version of the debugger uses Daniel's Simulator S51
4966 \begin_inset LatexCommand \index{s51}
4970 , but can be easily changed to use other simulators.
4979 Single Source File Projects
4982 For single source file 8051 projects the process is very simple.
4983 Compile your programs with the following command
4986 "sdcc sourcefile.c".
4990 This will compile, assemble and link your source file.
4991 Output files are as follows:
4995 \begin_inset LatexCommand \index{<file>.asm}
5000 \begin_inset LatexCommand \index{Assembler source}
5004 file created by the compiler
5008 \begin_inset LatexCommand \index{<file>.lst}
5013 \begin_inset LatexCommand \index{Assembler listing}
5017 file created by the Assembler
5021 \begin_inset LatexCommand \index{<file>.rst}
5026 \begin_inset LatexCommand \index{Assembler listing}
5030 file updated with linkedit information, created by linkage editor
5034 \begin_inset LatexCommand \index{<file>.sym}
5039 \begin_inset LatexCommand \index{Symbol listing}
5043 for the sourcefile, created by the assembler
5047 \begin_inset LatexCommand \index{<file>.rel}
5052 \begin_inset LatexCommand \index{<file>.o}
5057 \begin_inset LatexCommand \index{Object file}
5061 created by the assembler, input to Linkage editor
5065 \begin_inset LatexCommand \index{<file>.map}
5070 \begin_inset LatexCommand \index{Memory map}
5074 for the load module, created by the Linker
5078 \begin_inset LatexCommand \index{<file>.mem}
5082 - A file with a summary of the memory usage
5086 \begin_inset LatexCommand \index{<file>.ihx}
5090 - The load module in Intel hex format
5091 \begin_inset LatexCommand \index{Intel hex format}
5095 (you can select the Motorola S19 format
5096 \begin_inset LatexCommand \index{Motorola S19 format}
5113 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5118 If you need another format you might want to use
5125 \begin_inset LatexCommand \index{objdump (tool)}
5136 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5141 Both formats are documented in the documentation of srecord
5142 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5150 \begin_inset LatexCommand \index{<file>.adb}
5154 - An intermediate file containing debug information needed to create the
5168 \begin_inset LatexCommand \index{-\/-debug}
5176 \begin_inset LatexCommand \index{<file>.cdb}
5180 - An optional file (with -
5192 -debug) containing debug information.
5193 The format is documented in cdbfileformat.pdf
5198 \begin_inset LatexCommand \index{<file> (no extension)}
5202 An optional AOMF or AOMF51
5203 \begin_inset LatexCommand \index{AOMF, AOMF51}
5208 \begin_inset LatexCommand \label{OMF file}
5212 file containing debug information (generated with option -
5241 ormat is commonly used by third party tools (debuggers
5242 \begin_inset LatexCommand \index{Debugger}
5246 , simulators, emulators)
5250 \begin_inset LatexCommand \index{<file>.dump*}
5254 - Dump file to debug the compiler it self (generated with option -
5266 -dumpall) (see section
5267 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5273 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5279 \begin_inset Quotes sld
5282 Anatomy of the compiler
5283 \begin_inset Quotes srd
5289 Postprocessing the Intel Hex
5290 \begin_inset LatexCommand \index{Intel hex format}
5297 In most cases this won't be needed but the Intel Hex file
5298 \begin_inset LatexCommand \index{<file>.ihx}
5302 which is generated by SDCC might include lines of varying length and the
5303 addresses within the file are not guaranteed to be strictly ascending.
5304 If your toolchain or a bootloader does not like this you can use the tool
5310 \begin_inset LatexCommand \index{packihx (tool)}
5314 which is part of the SDCC distribution:
5321 packihx sourcefile.ihx >sourcefile.hex
5328 The separately available
5333 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5337 package additionally allows to set undefined locations to a predefined
5338 value, to insert checksums
5339 \begin_inset LatexCommand \index{checksum}
5343 of various flavours (crc, add, xor) and to perform other manipulations
5344 (convert, split, crop, offset, ...).
5352 srec_cat\SpecialChar ~
5354 sourcefile.ihx -intel\SpecialChar ~
5356 -o sourcefile.hex -intel
5363 An example for a more complex command line
5368 the command backfills
5369 \begin_inset LatexCommand \index{backfill unused memory}
5373 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5375 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5376 will be interpreted as an
5384 (where an emergency routine could sit).
5396 srec_cat\SpecialChar ~
5397 sourcefile.ihx -intel\SpecialChar ~
5399 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5400 -little-endian-checksum-nega
5401 tive 0xfffe 0x02 0x02\SpecialChar ~
5403 -o sourcefile.hex -intel
5412 The srecord package is available at
5413 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5420 Projects with Multiple Source Files
5423 SDCC can compile only ONE file at a time.
5424 Let us for example assume that you have a project containing the following
5429 foo1.c (contains some functions)
5431 foo2.c (contains some more functions)
5434 n.c (contains more functions and the function main)
5442 The first two files will need to be compiled separately with the commands:
5474 Then compile the source file containing the
5479 \begin_inset LatexCommand \index{Linker}
5483 the files together with the following command:
5491 foomain.c\SpecialChar ~
5492 foo1.rel\SpecialChar ~
5497 \begin_inset LatexCommand \index{<file>.rel}
5509 can be separately compiled as well:
5520 sdcc foomain.rel foo1.rel foo2.rel
5527 The file containing the
5542 file specified in the command line, since the linkage editor processes
5543 file in the order they are presented to it.
5544 The linker is invoked from SDCC using a script file with extension .lnk
5545 \begin_inset LatexCommand \index{<file>.lnk}
5550 You can view this file to troubleshoot linking problems such as those arising
5551 from missing libraries.
5554 Projects with Additional Libraries
5555 \begin_inset LatexCommand \index{Libraries}
5562 Some reusable routines may be compiled into a library, see the documentation
5563 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5567 \begin_inset LatexCommand \index{<file>.lib}
5574 Libraries created in this manner can be included in the command line.
5575 Make sure you include the -L <library-path> option to tell the linker where
5576 to look for these files if they are not in the current directory.
5577 Here is an example, assuming you have the source file
5589 (if that is not the same as your current project):
5596 sdcc foomain.c foolib.lib -L mylib
5607 must be an absolute path name.
5611 The most efficient way to use libraries is
5612 to keep separate modules in separate source files.
5613 The lib file now should name all the modules.rel
5614 \begin_inset LatexCommand \index{<file>.rel}
5619 For an example see the standard library file
5623 in the directory <installdir>/share/lib/small.
5626 Using sdcclib to Create and Manage Libraries
5627 \begin_inset LatexCommand \index{sdcclib}
5634 Alternatively, instead of having a .rel file for each entry on the library
5635 file as described in the preceding section, sdcclib can be used to embed
5636 all the modules belonging to such library in the library file itself.
5637 This results in a larger library file, but it greatly reduces the number
5638 of disk files accessed by the linker.
5639 Additionally, the packed library file contains an index of all include
5640 modules and symbols that significantly speeds up the linking process.
5641 To display a list of options supported by sdcclib type:
5650 \begin_inset LatexCommand \index{sdcclib}
5661 To create a new library file, start by compiling all the required modules.
5699 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5701 The next step is to add the .rel files to the library file:
5709 sdcclib libint.lib _divsint.rel
5712 \begin_inset LatexCommand \index{sdcclib}
5722 sdcclib libint.lib _divuint.rel
5728 sdcclib libint.lib _modsint.rel
5734 sdcclib libint.lib _moduint.rel
5740 sdcclib libint.lib _mulint.rel
5747 If the file already exists in the library, it will be replaced.
5748 To see what modules and symbols are included in the library, options -s
5749 and -m are available.
5757 sdcclib -s libint.lib
5760 \begin_inset LatexCommand \index{sdcclib}
5870 \added_space_bottom bigskip
5871 If the source files are compiled using -
5884 \begin_inset LatexCommand \index{-\/-debug}
5888 , the corresponding debug information file .adb will be include in the library
5890 The library files created with sdcclib are plain text files, so they can
5891 be viewed with a text editor.
5892 It is not recomended to modify a library file created with sdcclib using
5893 a text editor, as there are file indexes numbers located accross the file
5894 used by the linker to quickly locate the required module to link.
5895 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5896 it can be safely deleted, since all the information required for linking
5897 is embedded in the library file itself.
5898 Library files created using sdcclib are used as described in the preceding
5904 Command Line Options
5905 \begin_inset LatexCommand \index{Command Line Options}
5912 Processor Selection Options
5913 \begin_inset LatexCommand \index{Options processor selection}
5918 \begin_inset LatexCommand \index{Processor selection options}
5925 \labelwidthstring 00.00.0000
5929 \begin_inset LatexCommand \index{-mmcs51}
5935 Generate code for the Intel MCS51
5936 \begin_inset LatexCommand \index{MCS51}
5940 family of processors.
5941 This is the default processor target.
5944 \labelwidthstring 00.00.0000
5948 \begin_inset LatexCommand \index{-mds390}
5954 Generate code for the Dallas DS80C390
5955 \begin_inset LatexCommand \index{DS80C390}
5962 \labelwidthstring 00.00.0000
5966 \begin_inset LatexCommand \index{-mds400}
5972 Generate code for the Dallas DS80C400
5973 \begin_inset LatexCommand \index{DS80C400}
5980 \labelwidthstring 00.00.0000
5984 \begin_inset LatexCommand \index{-mhc08}
5990 Generate code for the Freescale/Motorola HC08
5991 \begin_inset LatexCommand \index{HC08}
5995 family of processors.
5998 \labelwidthstring 00.00.0000
6002 \begin_inset LatexCommand \index{-mz80}
6008 Generate code for the Zilog Z80
6009 \begin_inset LatexCommand \index{Z80}
6013 family of processors.
6016 \labelwidthstring 00.00.0000
6020 \begin_inset LatexCommand \index{-mgbz80}
6026 Generate code for the GameBoy Z80
6027 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6031 processor (Not actively maintained).
6034 \labelwidthstring 00.00.0000
6038 \begin_inset LatexCommand \index{-mavr}
6044 Generate code for the Atmel AVR
6045 \begin_inset LatexCommand \index{AVR}
6049 processor (Not maintained, not complete).
6050 AVR users should probably have a look at winavr
6051 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6056 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6067 I think it is fair to direct users there for now.
6068 Open source is also about avoiding unnecessary work .
6069 But I didn't find the 'official' link.
6076 \labelwidthstring 00.00.0000
6080 \begin_inset LatexCommand \index{-mpic14}
6086 Generate code for the Microchip PIC 14
6087 \begin_inset LatexCommand \index{PIC14}
6091 -bit processors (p16f84 and variants.
6092 In development, not complete).
6099 p16f627 p16f628 p16f84 p16f873 p16f877?
6106 \labelwidthstring 00.00.0000
6110 \begin_inset LatexCommand \index{-mpic16}
6116 Generate code for the Microchip PIC 16
6117 \begin_inset LatexCommand \index{PIC16}
6121 -bit processors (p18f452 and variants.
6122 In development, not complete).
6125 \labelwidthstring 00.00.0000
6130 Generate code for the Toshiba TLCS-900H
6131 \begin_inset LatexCommand \index{TLCS-900H}
6135 processor (Not maintained, not complete).
6138 \labelwidthstring 00.00.0000
6139 \added_space_bottom bigskip
6143 \begin_inset LatexCommand \index{-mxa51}
6149 Generate code for the Phillips XA51
6150 \begin_inset LatexCommand \index{XA51}
6154 processor (Not maintained, not complete).
6158 Preprocessor Options
6159 \begin_inset LatexCommand \index{Options preprocessor}
6164 \begin_inset LatexCommand \index{Preprocessor options}
6169 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6176 \labelwidthstring 00.00.0000
6180 \begin_inset LatexCommand \index{-I<path>}
6186 The additional location where the pre processor will look for <..h> or
6187 \begin_inset Quotes eld
6191 \begin_inset Quotes erd
6197 \labelwidthstring 00.00.0000
6201 \begin_inset LatexCommand \index{-D<macro[=value]>}
6207 Command line definition of macros.
6208 Passed to the preprocessor.
6211 \labelwidthstring 00.00.0000
6215 \begin_inset LatexCommand \index{-M}
6221 Tell the preprocessor to output a rule suitable for make describing the
6222 dependencies of each object file.
6223 For each source file, the preprocessor outputs one make-rule whose target
6224 is the object file name for that source file and whose dependencies are
6225 all the files `#include'd in it.
6226 This rule may be a single line or may be continued with `
6228 '-newline if it is long.
6229 The list of rules is printed on standard output instead of the preprocessed
6232 \begin_inset LatexCommand \index{-E}
6239 \labelwidthstring 00.00.0000
6243 \begin_inset LatexCommand \index{-C}
6249 Tell the preprocessor not to discard comments.
6250 Used with the `-E' option.
6253 \labelwidthstring 00.00.0000
6257 \begin_inset LatexCommand \index{-MM}
6268 Like `-M' but the output mentions only the user header files included with
6270 \begin_inset Quotes eld
6274 System header files included with `#include <file>' are omitted.
6277 \labelwidthstring 00.00.0000
6281 \begin_inset LatexCommand \index{-Aquestion(answer)}
6287 Assert the answer answer for question, in case it is tested with a preprocessor
6288 conditional such as `#if #question(answer)'.
6289 `-A-' disables the standard assertions that normally describe the target
6293 \labelwidthstring 00.00.0000
6297 \begin_inset LatexCommand \index{-Umacro}
6303 Undefine macro macro.
6304 `-U' options are evaluated after all `-D' options, but before any `-include'
6305 and `-imacros' options.
6308 \labelwidthstring 00.00.0000
6312 \begin_inset LatexCommand \index{-dM}
6318 Tell the preprocessor to output only a list of the macro definitions that
6319 are in effect at the end of preprocessing.
6320 Used with the `-E' option.
6323 \labelwidthstring 00.00.0000
6327 \begin_inset LatexCommand \index{-dD}
6333 Tell the preprocessor to pass all macro definitions into the output, in
6334 their proper sequence in the rest of the output.
6337 \labelwidthstring 00.00.0000
6341 \begin_inset LatexCommand \index{-dN}
6352 Like `-dD' except that the macro arguments and contents are omitted.
6353 Only `#define name' is included in the output.
6356 \labelwidthstring 00.00.0000
6359 -pedantic-parse-number
6360 \begin_inset LatexCommand \index{-pedantic-parse-number}
6371 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6372 and the macro LO_B(3) gets expanded.
6373 See also #pragma pedantic_parse_number in section
6374 \begin_inset LatexCommand \ref{sec:Pragmas}
6380 Note: this functionality is not in conformance with standard!
6383 \labelwidthstring 00.00.0000
6384 \added_space_bottom bigskip
6388 preprocessorOption[,preprocessorOption]
6391 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6396 Pass the preprocessorOption to the preprocessor
6401 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6406 SDCC uses an adapted version of the preprocessor
6410 of the GNU Compiler Collection
6411 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6420 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6424 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6429 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6438 \begin_inset LatexCommand \index{Options linker}
6443 \begin_inset LatexCommand \index{Linker options}
6450 \labelwidthstring 00.00.0000
6471 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6476 \begin_inset LatexCommand \index{-L -\/-lib-path}
6483 <absolute path to additional libraries> This option is passed to the linkage
6484 editor's additional libraries
6485 \begin_inset LatexCommand \index{Libraries}
6490 The path name must be absolute.
6491 Additional library files may be specified in the command line.
6492 See section Compiling programs for more details.
6495 \labelwidthstring 00.00.0000
6513 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6518 <Value> The start location of the external ram
6519 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6523 , default value is 0.
6524 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6536 -xram-loc 0x8000 or -
6551 \labelwidthstring 00.00.0000
6569 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6574 <Value> The start location of the code
6575 \begin_inset LatexCommand \index{code}
6579 segment, default value 0.
6580 Note when this option is used the interrupt vector table
6581 \begin_inset LatexCommand \index{interrupt vector table}
6585 is also relocated to the given address.
6586 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6598 -code-loc 0x8000 or -
6613 \labelwidthstring 00.00.0000
6631 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6636 <Value> By default the stack
6637 \begin_inset LatexCommand \index{stack}
6641 is placed after the data segment.
6642 Using this option the stack can be placed anywhere in the internal memory
6644 The value entered can be in Hexadecimal or Decimal format, e.g.
6657 -stack-loc 0x20 or -
6670 Since the sp register is incremented before a push or call, the initial
6671 sp will be set to one byte prior the provided value.
6672 The provided value should not overlap any other memory areas such as used
6673 register banks or the data segment and with enough space for the current
6693 \begin_inset LatexCommand \index{-\/-pack-iram}
6697 option (which is now a default setting) will override this setting, so
6698 you should also specify the
6716 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6720 option if you need to manually place the stack.
6723 \labelwidthstring 00.00.0000
6741 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6746 <Value> By default the external stack
6747 \begin_inset LatexCommand \index{xstack}
6751 is placed after the pdata
6752 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6757 Using this option the xstack can be placed anywhere in the external memory
6759 The value entered can be in Hexadecimal or Decimal format, e.g.
6772 -xstack-loc 0x8000 or -
6785 The provided value should not overlap any other memory areas such as the
6786 pdata or xdata segment and with enough space for the current application.
6789 \labelwidthstring 00.00.0000
6807 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6812 <Value> The start location of the internal ram data
6813 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6818 The value entered can be in Hexadecimal or Decimal format, eg.
6844 (By default, the start location of the internal ram data segment is set
6845 as low as possible in memory, taking into account the used register banks
6846 and the bit segment at address 0x20.
6847 For example if register banks 0 and 1 are used without bit variables, the
6848 data segment will be set, if -
6860 -data-loc is not used, to location 0x10.)
6863 \labelwidthstring 00.00.0000
6881 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6886 <Value> The start location of the indirectly addressable internal ram
6887 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6891 of the 8051, default value is 0x80.
6892 The value entered can be in Hexadecimal or Decimal format, eg.
6905 -idata-loc 0x88 or -
6920 \labelwidthstring 00.00.0000
6938 <Value> The start location of the bit
6939 \begin_inset LatexCommand \index{bit}
6943 addressable internal ram of the 8051.
6949 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6953 \labelwidthstring 00.00.0000
6969 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6978 The linker output (final object code) is in Intel Hex format.
6979 \begin_inset LatexCommand \index{Intel hex format}
6983 This is the default option.
6984 The format itself is documented in the documentation of srecord
6985 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6992 \labelwidthstring 00.00.0000
7008 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7017 The linker output (final object code) is in Motorola S19 format
7018 \begin_inset LatexCommand \index{Motorola S19 format}
7023 The format itself is documented in the documentation of srecord.
7026 \labelwidthstring 00.00.0000
7042 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7047 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7056 The linker output (final object code) is in ELF format
7057 \begin_inset LatexCommand \index{ELF format}
7062 (Currently only supported for the HC08
7063 \begin_inset LatexCommand \index{HC08}
7070 \labelwidthstring 00.00.0000
7071 \added_space_bottom bigskip
7075 linkOption[,linkOption]
7078 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7083 Pass the linkOption to the linker.
7084 If a bootloader is used an option like
7085 \begin_inset Quotes sld
7090 \begin_inset Quotes srd
7093 would be typical to set the start of the code segment.
7094 See also #pragma constseg and #pragma codeseg in section
7095 \begin_inset LatexCommand \ref{sec:Pragmas}
7100 File sdcc/as/doc/asxhtm.html has more on linker options.
7105 \begin_inset LatexCommand \index{Options MCS51}
7110 \begin_inset LatexCommand \index{MCS51 options}
7117 \labelwidthstring 00.00.0000
7133 \begin_inset LatexCommand \index{-\/-model-small}
7144 Generate code for Small Model programs, see section Memory Models for more
7146 This is the default model.
7149 \labelwidthstring 00.00.0000
7165 \begin_inset LatexCommand \index{-\/-model-medium}
7171 Generate code for Medium model programs, see section Memory Models for
7173 If this option is used all source files in the project have to be compiled
7175 It must also be used when invoking the linker.
7178 \labelwidthstring 00.00.0000
7194 \begin_inset LatexCommand \index{-\/-model-large}
7200 Generate code for Large model programs, see section Memory Models for more
7202 If this option is used all source files in the project have to be compiled
7204 It must also be used when invoking the linker.
7207 \labelwidthstring 00.00.0000
7223 \begin_inset LatexCommand \index{-\/-xstack}
7229 Uses a pseudo stack in the pdata
7230 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7234 area (usually the first 256 bytes in the external ram) for allocating variables
7235 and passing parameters.
7237 \begin_inset LatexCommand \ref{sub:External-Stack}
7242 External Stack for more details.
7245 \labelwidthstring 00.00.0000
7264 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7268 Causes the linker to check if the internal ram usage is within limits of
7272 \labelwidthstring 00.00.0000
7291 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7295 Causes the linker to check if the external ram usage is within limits of
7299 \labelwidthstring 00.00.0000
7318 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7322 Causes the linker to check if the code memory usage is within limits of
7326 \labelwidthstring 00.00.0000
7345 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7349 Causes the linker to check if there is at minimum <Value> bytes for stack.
7352 \labelwidthstring 00.00.0000
7371 \begin_inset LatexCommand \index{-\/-pack-iram}
7375 Causes the linker to use unused register banks for data variables and pack
7376 data, idata and stack together.
7377 This is the default now.
7380 \labelwidthstring 00.00.0000
7381 \added_space_bottom bigskip
7400 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7404 Causes the linker to use old style for allocating memory areas.
7408 DS390 / DS400 Options
7409 \begin_inset LatexCommand \index{Options DS390}
7414 \begin_inset LatexCommand \index{DS390}
7421 \labelwidthstring 00.00.0000
7439 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7449 Generate 24-bit flat mode code.
7450 This is the one and only that the ds390 code generator supports right now
7451 and is default when using
7456 See section Memory Models for more details.
7459 \labelwidthstring 00.00.0000
7475 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7481 disable interrupts during ESP:SP updates.
7484 \labelwidthstring 00.00.0000
7502 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7506 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7507 This is the one and only that the ds390 code generator supports right now
7508 and is default when using
7513 In this mode, the stack is located in the lower 1K of the internal RAM,
7514 which is mapped to 0x400000.
7515 Note that the support is incomplete, since it still uses a single byte
7516 as the stack pointer.
7517 This means that only the lower 256 bytes of the potential 1K stack space
7518 will actually be used.
7519 However, this does allow you to reclaim the precious 256 bytes of low RAM
7520 for use for the DATA and IDATA segments.
7521 The compiler will not generate any code to put the processor into 10 bit
7523 It is important to ensure that the processor is in this mode before calling
7524 any re-entrant functions compiled with this option.
7525 In principle, this should work with the
7540 \begin_inset LatexCommand \index{-\/-stack-auto}
7546 option, but that has not been tested.
7547 It is incompatible with the
7562 \begin_inset LatexCommand \index{-\/-xstack}
7569 It also only makes sense if the processor is in 24 bit contiguous addressing
7584 -model-flat24 option
7589 \labelwidthstring 00.00.0000
7605 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7611 insert call to function __stack_probe at each function prologue.
7614 \labelwidthstring 00.00.0000
7630 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7636 <nnnn> LibraryID used in -mTININative.
7640 \labelwidthstring 00.00.0000
7641 \added_space_bottom bigskip
7657 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7663 generate code for DS390 Arithmetic Accelerator.
7669 \begin_inset LatexCommand \index{Options Z80}
7674 \begin_inset LatexCommand \index{Z80}
7681 \labelwidthstring 00.00.0000
7699 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7709 Force a called function to always save BC.
7712 \labelwidthstring 00.00.0000
7713 \added_space_bottom bigskip
7731 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7735 When linking, skip the standard crt0.o object file.
7736 You must provide your own crt0.o for your system when linking.
7741 Optimization Options
7742 \begin_inset LatexCommand \index{Options optimization}
7747 \begin_inset LatexCommand \index{Optimization options}
7754 \labelwidthstring 00.00.0000
7770 \begin_inset LatexCommand \index{-\/-nogcse}
7776 Will not do global subexpression elimination, this option may be used when
7777 the compiler creates undesirably large stack/data spaces to store compiler
7787 \begin_inset LatexCommand \index{sloc (spill location)}
7792 A warning message will be generated when this happens and the compiler
7793 will indicate the number of extra bytes it allocated.
7794 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7796 \begin_inset LatexCommand \index{\#pragma nogcse}
7800 can be used to turn off global subexpression elimination
7801 \begin_inset LatexCommand \index{Subexpression elimination}
7805 for a given function only.
7808 \labelwidthstring 00.00.0000
7824 \begin_inset LatexCommand \index{-\/-noinvariant}
7830 Will not do loop invariant optimizations, this may be turned off for reasons
7831 explained for the previous option.
7832 For more details of loop optimizations performed see Loop Invariants in
7834 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7839 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7841 \begin_inset LatexCommand \index{\#pragma noinvariant}
7845 can be used to turn off invariant optimizations for a given function only.
7848 \labelwidthstring 00.00.0000
7864 \begin_inset LatexCommand \index{-\/-noinduction}
7870 Will not do loop induction optimizations, see section strength reduction
7872 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7874 \begin_inset LatexCommand \index{\#pragma noinduction}
7878 can be used to turn off induction optimizations for a given function only.
7881 \labelwidthstring 00.00.0000
7897 \begin_inset LatexCommand \index{-\/-nojtbound}
7908 Will not generate boundary condition check when switch statements
7909 \begin_inset LatexCommand \index{switch statement}
7913 are implemented using jump-tables.
7915 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7920 Switch Statements for more details.
7921 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7923 \begin_inset LatexCommand \index{\#pragma nojtbound}
7927 can be used to turn off boundary checking for jump tables for a given function
7931 \labelwidthstring 00.00.0000
7947 \begin_inset LatexCommand \index{-\/-noloopreverse}
7956 Will not do loop reversal
7957 \begin_inset LatexCommand \index{Loop reversing}
7964 \labelwidthstring 00.00.0000
7982 \begin_inset LatexCommand \index{-\/-nolabelopt }
7986 Will not optimize labels (makes the dumpfiles more readable).
7989 \labelwidthstring 00.00.0000
8005 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8011 Will not memcpy initialized data from code space into xdata space.
8012 This saves a few bytes in code space if you don't have initialized data
8013 \begin_inset LatexCommand \index{Variable initialization}
8020 \labelwidthstring 00.00.0000
8036 \begin_inset LatexCommand \index{-\/-nooverlay}
8042 The compiler will not overlay parameters and local variables of any function,
8043 see section Parameters and local variables for more details.
8046 \labelwidthstring 00.00.0000
8062 \begin_inset LatexCommand \index{-\/-no-peep}
8068 Disable peep-hole optimization with built-in rules.
8071 \labelwidthstring 00.00.0000
8089 \begin_inset LatexCommand \index{-\/-peep-file}
8094 <filename> This option can be used to use additional rules to be used by
8095 the peep hole optimizer.
8097 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8102 Peep Hole optimizations for details on how to write these rules.
8105 \labelwidthstring 00.00.0000
8121 \begin_inset LatexCommand \index{-\/-peep-asm}
8127 Pass the inline assembler code through the peep hole optimizer.
8128 This can cause unexpected changes to inline assembler code, please go through
8129 the peephole optimizer
8130 \begin_inset LatexCommand \index{Peephole optimizer}
8134 rules defined in the source file tree '<target>/peeph.def' before using
8138 \labelwidthstring 00.00.0000
8154 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8160 The compiler will optimize code generation towards fast code, possibly
8161 at the expense of code size.
8164 \labelwidthstring 00.00.0000
8165 \added_space_bottom bigskip
8181 \begin_inset LatexCommand \index{-\/-opt-code-size}
8187 The compiler will optimize code generation towards compact code, possibly
8188 at the expense of code speed.
8193 \begin_inset LatexCommand \index{Options other}
8200 \labelwidthstring 00.00.0000
8217 \begin_inset LatexCommand \index{-\/-compile-only}
8222 \begin_inset LatexCommand \index{-c -\/-compile-only}
8228 will compile and assemble the source, but will not call the linkage editor.
8231 \labelwidthstring 00.00.0000
8251 \begin_inset LatexCommand \index{-\/-c1mode}
8257 reads the preprocessed source from standard input and compiles it.
8258 The file name for the assembler output must be specified using the -o option.
8261 \labelwidthstring 00.00.0000
8265 \begin_inset LatexCommand \index{-E}
8271 Run only the C preprocessor.
8272 Preprocess all the C source files specified and output the results to standard
8276 \labelwidthstring 00.00.0000
8281 \begin_inset LatexCommand \index{-o <path/file>}
8287 The output path resp.
8288 file where everything will be placed.
8289 If the parameter is a path, it must have a trailing slash (or backslash
8290 for the Windows binaries) to be recognized as a path.
8294 \labelwidthstring 00.00.0000
8310 \begin_inset LatexCommand \index{-\/-stack-auto}
8321 All functions in the source file will be compiled as
8326 \begin_inset LatexCommand \index{reentrant}
8331 the parameters and local variables will be allocated on the stack
8332 \begin_inset LatexCommand \index{stack}
8338 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8342 Parameters and Local Variables for more details.
8343 If this option is used all source files in the project should be compiled
8345 It automatically implies --int-long-reent and --float-reent.
8349 \labelwidthstring 00.00.0000
8365 \begin_inset LatexCommand \index{-\/-callee-saves}
8369 function1[,function2][,function3]....
8372 The compiler by default uses a caller saves convention for register saving
8373 across function calls, however this can cause unnecessary register pushing
8374 & popping when calling small functions from larger functions.
8375 This option can be used to switch the register saving convention for the
8376 function names specified.
8377 The compiler will not save registers when calling these functions, no extra
8378 code will be generated at the entry & exit (function prologue
8381 \begin_inset LatexCommand \index{function prologue}
8390 \begin_inset LatexCommand \index{function epilogue}
8396 ) for these functions to save & restore the registers used by these functions,
8397 this can SUBSTANTIALLY reduce code & improve run time performance of the
8399 In the future the compiler (with inter procedural analysis) will be able
8400 to determine the appropriate scheme to use for each function call.
8401 DO NOT use this option for built-in functions such as _mulint..., if this
8402 option is used for a library function the appropriate library function
8403 needs to be recompiled with the same option.
8404 If the project consists of multiple source files then all the source file
8405 should be compiled with the same -
8417 -callee-saves option string.
8418 Also see #pragma\SpecialChar ~
8420 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8427 \labelwidthstring 00.00.0000
8443 \begin_inset LatexCommand \index{-\/-debug}
8452 When this option is used the compiler will generate debug information.
8453 The debug information collected in a file with .cdb extension can be used
8455 For more information see documentation for SDCDB.
8456 Another file with no extension contains debug information in AOMF or AOMF51
8457 \begin_inset LatexCommand \index{AOMF, AOMF51}
8461 format which is commonly used by third party tools.
8464 \labelwidthstring 00.00.0000
8468 \begin_inset LatexCommand \index{-S}
8479 Stop after the stage of compilation proper; do not assemble.
8480 The output is an assembler code file for the input file specified.
8483 \labelwidthstring 00.00.0000
8499 \begin_inset LatexCommand \index{-\/-int-long-reent}
8505 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8506 Note by default these libraries are compiled as non-reentrant.
8507 See section Installation for more details.
8510 \labelwidthstring 00.00.0000
8526 \begin_inset LatexCommand \index{-\/-cyclomatic}
8535 This option will cause the compiler to generate an information message for
8536 each function in the source file.
8537 The message contains some
8541 information about the function.
8542 The number of edges and nodes the compiler detected in the control flow
8543 graph of the function, and most importantly the
8545 cyclomatic complexity
8546 \begin_inset LatexCommand \index{Cyclomatic complexity}
8552 see section on Cyclomatic Complexity for more details.
8555 \labelwidthstring 00.00.0000
8571 \begin_inset LatexCommand \index{-\/-float-reent}
8577 Floating point library is compiled as reentrant
8578 \begin_inset LatexCommand \index{reentrant}
8583 See section Installation for more details.
8586 \labelwidthstring 00.00.0000
8602 \begin_inset LatexCommand \index{-\/-funsigned-char}
8608 The default signedness for every type is
8613 In some embedded environments the default signedness of
8622 To set the signess for characters to unsigned, use the option --funsigned-char.
8623 If this option is set and no signedness keyword (unsigned/signed) is given,
8624 a char will be signed.
8625 All other types are unaffected.
8628 \labelwidthstring 00.00.0000
8644 \begin_inset LatexCommand \index{-\/-main-return}
8650 This option can be used if the code generated is called by a monitor program
8651 or if the main routine includes an endless loop.
8652 This option results in slightly smaller code and saves two bytes of stack
8654 The return from the 'main'
8655 \begin_inset LatexCommand \index{main return}
8659 function will return to the function calling main.
8660 The default setting is to lock up i.e.
8668 \labelwidthstring 00.00.0000
8684 \begin_inset LatexCommand \index{-\/-nostdinc}
8690 This will prevent the compiler from passing on the default include path
8691 to the preprocessor.
8694 \labelwidthstring 00.00.0000
8710 \begin_inset LatexCommand \index{-\/-nostdlib}
8716 This will prevent the compiler from passing on the default library
8717 \begin_inset LatexCommand \index{Libraries}
8724 \labelwidthstring 00.00.0000
8740 \begin_inset LatexCommand \index{-\/-verbose}
8746 Shows the various actions the compiler is performing.
8749 \labelwidthstring 00.00.0000
8753 \begin_inset LatexCommand \index{-V}
8759 Shows the actual commands the compiler is executing.
8762 \labelwidthstring 00.00.0000
8778 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8784 Hides your ugly and inefficient c-code from the asm file, so you can always
8785 blame the compiler :)
8788 \labelwidthstring 00.00.0000
8804 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8810 Will not include peep-hole comments in the generated files.
8813 \labelwidthstring 00.00.0000
8829 \begin_inset LatexCommand \index{-\/-no-gen-comments}
8835 Will not include code generator comments in the generated files.
8838 \labelwidthstring 00.00.0000
8854 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8860 Include i-codes in the asm file.
8861 Sounds like noise but is most helpful for debugging the compiler itself.
8864 \labelwidthstring 00.00.0000
8880 \begin_inset LatexCommand \index{-\/-less-pedantic}
8886 Disable some of the more pedantic warnings
8887 \begin_inset LatexCommand \index{Warnings}
8891 (jwk burps: please be more specific here, please!).
8894 \labelwidthstring 00.00.0000
8909 -disable-warning\SpecialChar ~
8911 \begin_inset LatexCommand \index{-\/-disable-warning}
8917 Disable specific warning with number <nnnn>.
8920 \labelwidthstring 00.00.0000
8936 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8942 Display the directories in the compiler's search path
8945 \labelwidthstring 00.00.0000
8961 \begin_inset LatexCommand \index{-\/-vc}
8967 Display errors and warnings using MSVC style, so you can use SDCC with
8968 the visual studio IDE
8969 \begin_inset LatexCommand \index{IDE}
8974 With SDCC both offering a GCC-like (the default) and a MSVC-like
8975 \begin_inset LatexCommand \index{MSVC output style}
8979 output style, integration into most programming editors should be straightforwa
8983 \labelwidthstring 00.00.0000
8999 \begin_inset LatexCommand \index{-\/-use-stdout}
9005 Send errors and warnings to stdout instead of stderr.
9008 \labelwidthstring 00.00.0000
9012 asmOption[,asmOption]
9015 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9020 Pass the asmOption to the assembler
9021 \begin_inset LatexCommand \index{Options assembler}
9026 \begin_inset LatexCommand \index{Assembler options}
9031 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9034 \labelwidthstring 00.00.0000
9050 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9056 Generally follow the C89 standard, but allow SDCC features that conflict
9057 with the standard (default).
9060 \labelwidthstring 00.00.0000
9076 \begin_inset LatexCommand \index{-\/-std-c89}
9082 Follow the C89 standard and disable SDCC features that conflict with the
9086 \labelwidthstring 00.00.0000
9102 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9108 Generally follow the C99 standard, but allow SDCC features that conflict
9109 with the standard (incomplete support).
9112 \labelwidthstring 00.00.0000
9128 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9134 Follow the C99 standard and disable SDCC features that conflict with the
9135 standard (incomplete support).
9138 \labelwidthstring 00.00.0000
9156 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9161 <Name> The name to be used for the code
9162 \begin_inset LatexCommand \index{code}
9166 segment, default CSEG.
9167 This is useful if you need to tell the compiler to put the code in a special
9168 segment so you can later on tell the linker to put this segment in a special
9170 Can be used for instance when using bank switching to put the code in a
9174 \labelwidthstring 00.00.0000
9192 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9197 <Name> The name to be used for the const
9198 \begin_inset LatexCommand \index{code}
9202 segment, default CONST.
9203 This is useful if you need to tell the compiler to put the const data in
9204 a special segment so you can later on tell the linker to put this segment
9205 in a special place in memory.
9206 Can be used for instance when using bank switching to put the const data
9210 \labelwidthstring 00.00.0000
9225 -fdollars-in-identifiers
9226 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9232 Permit '$' as an identifier character
9235 \labelwidthstring 00.00.0000
9236 \added_space_bottom bigskip
9247 a SDCC compiler option but if you want
9251 warnings you can use a separate tool dedicated to syntax checking like
9253 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9258 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9263 \begin_inset LatexCommand \url{http://www.splint.org}
9268 To make your source files parseable by splint you will have to include
9274 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9278 in your source file and add brackets around extended keywords (like
9281 \begin_inset Quotes sld
9294 \begin_inset Quotes srd
9302 \begin_inset Quotes sld
9305 __interrupt\SpecialChar ~
9307 \begin_inset Quotes srd
9315 Splint has an excellent on line manual at
9316 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9320 and it's capabilities go beyond pure syntax checking.
9321 You'll need to tell splint the location of SDCC's include files so a typical
9322 command line could look like this:
9326 splint\SpecialChar ~
9328 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9334 Intermediate Dump Options
9335 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9340 \begin_inset LatexCommand \index{Options intermediate dump}
9345 \begin_inset LatexCommand \index{Intermediate dump options}
9352 The following options are provided for the purpose of retargetting and debugging
9354 They provide a means to dump the intermediate code (iCode
9355 \begin_inset LatexCommand \index{iCode}
9359 ) generated by the compiler in human readable form at various stages of
9360 the compilation process.
9361 More on iCodes see chapter
9362 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9367 \begin_inset Quotes srd
9370 The anatomy of the compiler
9371 \begin_inset Quotes srd
9377 \labelwidthstring 00.00.0000
9393 \begin_inset LatexCommand \index{-\/-dumpraw}
9399 This option will cause the compiler to dump the intermediate code into
9402 <source filename>.dumpraw
9404 just after the intermediate code has been generated for a function, i.e.
9405 before any optimizations are done.
9407 \begin_inset LatexCommand \index{Basic blocks}
9411 at this stage ordered in the depth first number, so they may not be in
9412 sequence of execution.
9415 \labelwidthstring 00.00.0000
9431 \begin_inset LatexCommand \index{-\/-dumpgcse}
9437 Will create a dump of iCode's, after global subexpression elimination
9438 \begin_inset LatexCommand \index{Global subexpression elimination}
9444 <source filename>.dumpgcse.
9447 \labelwidthstring 00.00.0000
9463 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9469 Will create a dump of iCode's, after deadcode elimination
9470 \begin_inset LatexCommand \index{Dead-code elimination}
9476 <source filename>.dumpdeadcode.
9479 \labelwidthstring 00.00.0000
9495 \begin_inset LatexCommand \index{-\/-dumploop}
9504 Will create a dump of iCode's, after loop optimizations
9505 \begin_inset LatexCommand \index{Loop optimization}
9511 <source filename>.dumploop.
9514 \labelwidthstring 00.00.0000
9530 \begin_inset LatexCommand \index{-\/-dumprange}
9539 Will create a dump of iCode's, after live range analysis
9540 \begin_inset LatexCommand \index{Live range analysis}
9546 <source filename>.dumprange.
9549 \labelwidthstring 00.00.0000
9565 \begin_inset LatexCommand \index{-\/-dumlrange}
9571 Will dump the life ranges
9572 \begin_inset LatexCommand \index{Live range analysis}
9579 \labelwidthstring 00.00.0000
9595 \begin_inset LatexCommand \index{-\/-dumpregassign}
9604 Will create a dump of iCode's, after register assignment
9605 \begin_inset LatexCommand \index{Register assignment}
9611 <source filename>.dumprassgn.
9614 \labelwidthstring 00.00.0000
9630 \begin_inset LatexCommand \index{-\/-dumplrange}
9636 Will create a dump of the live ranges of iTemp's
9639 \labelwidthstring 00.00.0000
9640 \added_space_bottom bigskip
9656 \begin_inset LatexCommand \index{-\/-dumpall}
9667 Will cause all the above mentioned dumps to be created.
9671 Redirecting output on Windows Shells
9674 \added_space_bottom bigskip
9675 By default SDCC writes it's error messages to
9676 \begin_inset Quotes sld
9680 \begin_inset Quotes srd
9684 To force all messages to
9685 \begin_inset Quotes sld
9689 \begin_inset Quotes srd
9715 \begin_inset LatexCommand \index{-\/-use-stdout}
9720 Additionally, if you happen to have visual studio installed in your windows
9721 machine, you can use it to compile your sources using a custom build and
9739 \begin_inset LatexCommand \index{-\/-vc}
9744 Something like this should work:
9792 -model-large -c $(InputPath)
9799 Environment variables
9800 \begin_inset LatexCommand \index{Environment variables}
9807 SDCC recognizes the following environment variables:
9810 \labelwidthstring 00.00.0000
9814 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9820 SDCC installs a signal handler
9821 \begin_inset LatexCommand \index{signal handler}
9825 to be able to delete temporary files after an user break (^C) or an exception.
9826 If this environment variable is set, SDCC won't install the signal handler
9827 in order to be able to debug SDCC.
9830 \labelwidthstring 00.00.0000
9836 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9842 Path, where temporary files will be created.
9843 The order of the variables is the search order.
9844 In a standard *nix environment these variables are not set, and there's
9845 no need to set them.
9846 On Windows it's recommended to set one of them.
9849 \labelwidthstring 00.00.0000
9853 \begin_inset LatexCommand \index{SDCC\_HOME}
9860 \begin_inset LatexCommand \ref{sub:Install-paths}
9866 \begin_inset Quotes sld
9870 \begin_inset Quotes srd
9876 \labelwidthstring 00.00.0000
9880 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9887 \begin_inset LatexCommand \ref{sub:Search-Paths}
9893 \begin_inset Quotes sld
9897 \begin_inset Quotes srd
9903 \labelwidthstring 00.00.0000
9907 \begin_inset LatexCommand \index{SDCC\_LIB}
9914 \begin_inset LatexCommand \ref{sub:Search-Paths}
9920 \begin_inset Quotes sld
9924 \begin_inset Quotes srd
9930 \added_space_bottom bigskip
9931 There are some more environment variables recognized by SDCC, but these
9932 are solely used for debugging purposes.
9933 They can change or disappear very quickly, and will never be documented.
9938 Storage Class Language Extensions
9941 MCS51/DS390 Storage Class
9942 \begin_inset LatexCommand \index{Storage class}
9949 In addition to the ANSI storage classes SDCC allows the following MCS51
9950 specific storage classes:
9952 \layout Subsubsection
9954 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9959 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9964 \begin_inset LatexCommand \index{near (storage class)}
9969 \begin_inset LatexCommand \index{\_\_near (storage class)}
9980 storage class for the Small Memory model (
9988 or the more ANSI-C compliant forms
9996 can be used synonymously).
9997 Variables declared with this storage class will be allocated in the directly
9998 addressable portion of the internal RAM of a 8051, e.g.:
10003 __data unsigned char test_data;
10006 Writing 0x01 to this variable generates the assembly code:
10011 75*00 01\SpecialChar ~
10018 \layout Subsubsection
10020 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10025 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10030 \begin_inset LatexCommand \index{far (storage class)}
10035 \begin_inset LatexCommand \index{\_\_far (storage class)}
10042 Variables declared with this storage class will be placed in the external
10048 storage class for the Large Memory model, e.g.:
10053 __xdata unsigned char test_xdata;
10056 Writing 0x01 to this variable generates the assembly code:
10061 90s00r00\SpecialChar ~
10091 \layout Subsubsection
10093 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10098 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10105 Variables declared with this storage class will be allocated into the indirectly
10106 addressable portion of the internal ram of a 8051, e.g.:
10111 __idata unsigned char test_idata;
10114 Writing 0x01 to this variable generates the assembly code:
10119 78r00\SpecialChar ~
10143 Please note, the first 128 byte of idata physically access the same RAM
10144 as the data memory.
10145 The original 8051 had 128 byte idata memory, nowadays most devices have
10146 256 byte idata memory.
10148 \begin_inset LatexCommand \index{stack}
10152 is located in idata memory.
10154 \layout Subsubsection
10156 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10161 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10168 Paged xdata access is just as straightforward as using the other addressing
10170 It is typically located at the start of xdata and has a maximum size of
10172 The following example writes 0x01 to the pdata variable.
10173 Please note, pdata access physically accesses xdata memory.
10174 The high byte of the address is determined by port P2
10175 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10179 (or in case of some 8051 variants by a separate Special Function Register,
10181 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10190 storage class for the Medium Memory model, e.g.:
10195 __pdata unsigned char test_pdata;
10198 Writing 0x01 to this variable generates the assembly code:
10203 78r00\SpecialChar ~
10209 mov r0,#_test_pdata
10211 74 01\SpecialChar ~
10244 \begin_inset LatexCommand \index{-\/-xstack}
10248 option is used the pdata memory area is followed by the xstack memory area
10249 and the sum of their sizes is limited to 256 bytes.
10251 \layout Subsubsection
10253 \begin_inset LatexCommand \index{code}
10258 \begin_inset LatexCommand \index{\_\_code}
10265 'Variables' declared with this storage class will be placed in the code
10271 __code unsigned char test_code;
10274 Read access to this variable generates the assembly code:
10279 90s00r6F\SpecialChar ~
10282 mov dptr,#_test_code
10311 indexed arrays of characters in code memory can be accessed efficiently:
10316 __code char test_array[] = {'c','h','e','a','p'};
10319 Read access to this array using an 8-bit unsigned index generates the assembly
10325 E5*00\SpecialChar ~
10336 90s00r41\SpecialChar ~
10339 mov dptr,#_test_array
10355 \layout Subsubsection
10357 \begin_inset LatexCommand \index{bit}
10362 \begin_inset LatexCommand \index{\_\_bit}
10369 This is a data-type and a storage class specifier.
10370 When a variable is declared as a bit, it is allocated into the bit addressable
10371 memory of 8051, e.g.:
10379 Writing 1 to this variable generates the assembly code:
10384 D2*00\SpecialChar ~
10395 The bit addressable memory consists of 128 bits which are located from 0x20
10396 to 0x2f in data memory.
10399 Apart from this 8051 specific storage class most architectures support
10401 \begin_inset LatexCommand \index{bitfields}
10410 Not really meant as examples, but nevertheless showing what bitfields are
10411 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10416 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10417 signed modifier are implemented as unsigned.
10419 \layout Subsubsection
10421 \begin_inset LatexCommand \index{sfr}
10426 \begin_inset LatexCommand \index{\_\_sfr}
10431 \begin_inset LatexCommand \index{sfr16}
10436 \begin_inset LatexCommand \index{\_\_sfr16}
10441 \begin_inset LatexCommand \index{sfr32}
10446 \begin_inset LatexCommand \index{\_\_sfr32}
10451 \begin_inset LatexCommand \index{\_\_sbit}
10456 \begin_inset LatexCommand \index{sbit}
10463 Like the bit keyword,
10465 sfr / sfr16 / sfr32 / sbit
10467 signify both a data-type and storage class, they are used to describe the
10488 variables of a 8051, eg:
10494 \begin_inset LatexCommand \index{at}
10499 \begin_inset LatexCommand \index{\_\_at}
10503 (0x80) P0;\SpecialChar ~
10504 /* special function register P0 at location 0x80 */
10509 special function register combination for timer 0
10513 with the high byte at
10514 location 0x8C and the low byte at location 0x8A */
10516 __sfr16 __at (0x8C8A)
10522 \begin_inset LatexCommand \index{at}
10527 \begin_inset LatexCommand \index{\_\_at}
10531 (0xd7) CY;\SpecialChar ~
10533 \begin_inset LatexCommand \index{Flags}
10538 \begin_inset LatexCommand \index{Carry flag}
10545 Special function registers which are located on an address dividable by
10546 8 are bit-addressable, an
10550 addresses a specific bit within these sfr.
10552 16 Bit and 32 bit special function
10553 register combinations which require a certain access order are better not
10563 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10564 this is not guaranteed.
10569 Please note, if you use a header file which was written for another compiler
10570 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10576 Specifically the syntax
10579 sfr P0 = 0x80;\SpecialChar ~
10586 by SDCC to an assignment of 0x80 to a variable called P0
10589 \begin_inset Marginal
10603 Nevertheless it is possible to write header files
10604 \begin_inset LatexCommand \index{Header files}
10609 \begin_inset LatexCommand \index{Include files}
10613 which can be shared among different compilers (see section
10614 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10621 \layout Subsubsection
10623 \begin_inset LatexCommand \index{Pointer}
10627 to MCS51/DS390 specific memory spaces
10630 SDCC allows (via language extensions) pointers to explicitly point to any
10631 of the memory spaces
10632 \begin_inset LatexCommand \index{Memory model}
10637 In addition to the explicit pointers, the compiler uses (by default) generic
10638 pointers which can be used to point to any of the memory spaces.
10643 declaration examples:
10648 /* pointer physically in internal ram pointing to object in external ram
10651 __xdata unsigned char * __data p;
10655 /* pointer physically in external ram
10656 pointing to object in internal ram */
10658 __data unsigned char * __xdata p;
10663 pointer physically in code rom pointing to data in xdata space */
10666 unsigned char * __code p;
10670 /* pointer physically in code space pointing to
10671 data in code space */
10673 __code unsigned char * __code p;
10678 physically located in xdata space */
10680 unsigned char * __xdata p;
10685 pointer physically located in default memory space */
10692 the following is a function pointer
10693 \begin_inset LatexCommand \index{function pointer}
10697 physically located in data space */
10699 char (* __data fp)(void);
10702 Well you get the idea.
10707 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10720 The highest order byte of the
10724 pointers contains the data space information.
10725 Assembler support routines are called whenever data is stored or retrieved
10731 These are useful for developing reusable library
10732 \begin_inset LatexCommand \index{Libraries}
10737 Explicitly specifying the pointer
10738 \begin_inset LatexCommand \index{pointer}
10742 type will generate the most efficient code.
10744 \layout Subsubsection
10745 Notes on MCS51 memory
10746 \begin_inset LatexCommand \index{MCS51 memory}
10753 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10754 RAM memory which is structured as follows:
10758 - Bytes 00-1F - 32 bytes to hold
10759 up to 4 banks of the registers R0 to R7,
10761 - Bytes 20-2F - 16 bytes to hold
10763 \begin_inset LatexCommand \index{bit}
10769 - Bytes 30-7F - 80 bytes for general purpose use.
10774 Additionally some members of the MCS51 family may have up to 128 bytes of
10775 additional, indirectly addressable, internal RAM memory (
10780 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10785 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10790 Furthermore, some chips may have some built in external memory (
10795 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10800 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10804 ) which should not be confused with the internal, directly addressable RAM
10810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10815 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10820 Sometimes this built in
10824 memory has to be activated before using it (you can probably find this
10825 information on the datasheet of the microcontroller your are using, see
10827 \begin_inset LatexCommand \ref{sub:Startup-Code}
10835 Normally SDCC will only use the first bank
10836 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10840 of registers (register bank 0), but it is possible to specify that other
10841 banks of registers (keyword
10848 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10853 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10859 ) should be used in interrupt
10860 \begin_inset LatexCommand \index{interrupt}
10865 \begin_inset LatexCommand \index{\_\_interrupt}
10870 By default, the compiler will place the stack after the last byte of allocated
10871 memory for variables.
10872 For example, if the first 2 banks of registers are used, and only four
10877 variables, it will position the base of the internal stack at address 20
10879 This implies that as the stack
10880 \begin_inset LatexCommand \index{stack}
10884 grows, it will use up the remaining register banks, and the 16 bytes used
10885 by the 128 bit variables, and 80 bytes for general purpose use.
10886 If any bit variables are used, the data variables will be placed in unused
10887 register banks and after the byte holding the last bit variable.
10888 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10893 variables will be placed starting from address 0x10 to 0x20 and continue
10908 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10912 to specify the start address of the
10929 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10933 to specify the size of the total internal RAM (
10947 By default the 8051 linker will place the stack after the last byte of (i)data
10962 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10966 allows you to specify the start of the stack, i.e.
10967 you could start it after any data in the general purpose area.
10968 If your microcontroller has additional indirectly addressable internal
10973 ) you can place the stack on it.
10974 You may also need to use -
10987 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10991 to set the start address of the external RAM (
11008 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11012 to specify its size.
11013 Same goes for the code memory, using -
11026 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11043 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11048 If in doubt, don't specify any options and see if the resulting memory
11049 layout is appropriate, then you can adjust it.
11052 \added_space_bottom bigskip
11053 The linker generates two files with memory allocation information.
11054 The first, with extension .map
11055 \begin_inset LatexCommand \index{<file>.map}
11059 shows all the variables and segments.
11060 The second with extension .mem
11061 \begin_inset LatexCommand \index{<file>.mem}
11065 shows the final memory layout.
11066 The linker will complain either if memory segments overlap, there is not
11067 enough memory, or there is not enough space for stack.
11068 If you get any linking warnings and/or errors related to stack or segments
11069 allocation, take a look at either the .map or .mem files to find out what
11071 The .mem file may even suggest a solution to the problem.
11076 Z80/Z180 Storage Class
11077 \begin_inset LatexCommand \index{Z80!Storage class}
11081 Language Extensions
11083 \layout Subsubsection
11085 \begin_inset LatexCommand \index{sfr}
11090 \begin_inset LatexCommand \index{\_\_sfr}
11094 (in/out to 8-bit addresses)
11098 \begin_inset LatexCommand \index{Z80}
11102 family has separate address spaces for memory and
11112 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11117 \begin_inset LatexCommand \index{Z80!I/O memory}
11122 \begin_inset LatexCommand \index{Z180!I/O memory}
11126 is accessed with special instructions, e.g.:
11131 sfr at 0x78 IoPort;\SpecialChar ~
11133 /* define a var in I/O space at 78h called IoPort */
11137 Writing 0x01 to this variable generates the assembly code:
11142 3E 01\SpecialChar ~
11150 D3 78\SpecialChar ~
11158 \layout Subsubsection
11160 \begin_inset LatexCommand \index{sfr}
11165 \begin_inset LatexCommand \index{\_\_sfr}
11169 (in/out to 16-bit addresses)
11176 is used to support 16 bit addresses in I/O memory e.g.:
11182 \begin_inset LatexCommand \index{at}
11187 \begin_inset LatexCommand \index{\_\_at}
11194 Writing 0x01 to this variable generates the assembly code:
11199 01 23 01\SpecialChar ~
11204 3E 01\SpecialChar ~
11212 ED 79\SpecialChar ~
11220 \layout Subsubsection
11222 \begin_inset LatexCommand \index{sfr}
11227 \begin_inset LatexCommand \index{\_\_sfr}
11231 (in0/out0 to 8 bit addresses on Z180
11232 \begin_inset LatexCommand \index{Z180}
11237 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11244 \added_space_bottom bigskip
11245 The compiler option -
11258 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11262 =180 (80) and a compiler #pragma\SpecialChar ~
11264 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11268 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11278 If you include the file z180.h this will be set automatically.
11284 \begin_inset LatexCommand \index{HC08!Storage class}
11288 Language Extensions
11290 \layout Subsubsection
11292 \begin_inset LatexCommand \index{data (hc08 storage class)}
11297 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11304 The data storage class declares a variable that resides in the first 256
11305 bytes of memory (the direct page).
11307 \begin_inset LatexCommand \index{HC08}
11311 is most efficient at accessing variables (especially pointers) stored here.
11313 \layout Subsubsection
11315 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11320 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11327 \added_space_bottom bigskip
11328 The xdata storage class declares a variable that can reside anywhere in
11330 This is the default if no storage class is specified.
11336 Absolute Addressing
11337 \begin_inset LatexCommand \index{Absolute addressing}
11344 Data items can be assigned an absolute address with the
11347 \begin_inset LatexCommand \index{at}
11352 \begin_inset LatexCommand \index{\_\_at}
11358 keyword, in addition to a storage class, e.g.:
11364 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11369 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11374 \begin_inset LatexCommand \index{at}
11379 \begin_inset LatexCommand \index{\_\_at}
11383 0x7ffe unsigned int chksum;
11386 or, better conforming to ISO/IEC 9899 C:
11391 __xdata __at (0x7ffe) unsigned int chksum;
11394 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11395 of the external ram.
11400 reserve any space for variables declared in this way
11401 \begin_inset Marginal
11412 (they are implemented with an equate in the assembler).
11413 Thus it is left to the programmer to make sure there are no overlaps with
11414 other variables that are declared without the absolute address.
11415 The assembler listing file (.lst
11416 \begin_inset LatexCommand \index{<file>.lst}
11420 ) and the linker output files (.rst
11421 \begin_inset LatexCommand \index{<file>.rst}
11426 \begin_inset LatexCommand \index{<file>.map}
11430 ) are good places to look for such overlaps.
11431 Variables with an absolute address are
11434 \begin_inset Marginal
11448 \begin_inset LatexCommand \index{Variable initialization}
11455 In case of memory mapped I/O devices the keyword
11459 has to be used to tell the compiler that accesses might not be removed:
11465 \begin_inset LatexCommand \index{volatile}
11470 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11475 \begin_inset LatexCommand \index{at}
11479 (0x8000) unsigned char PORTA_8255;
11482 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11487 \begin_inset LatexCommand \index{Aligned array}
11494 starts at a block (256 byte) boundary
11495 \begin_inset LatexCommand \index{block boundary}
11500 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11506 Absolute addresses can be specified for variables in all
11507 storage classes, e.g.:
11513 \begin_inset LatexCommand \index{bit}
11518 \begin_inset LatexCommand \index{at}
11525 The above example will allocate the variable at offset 0x02 in the bit-addressab
11527 There is no real advantage to assigning absolute addresses to variables
11528 in this manner, unless you want strict control over all the variables allocated.
11529 One possible use would be to write hardware portable code.
11530 For example, if you have a routine that uses one or more of the microcontroller
11531 I/O pins, and such pins are different for two different hardwares, you
11532 can declare the I/O pins in your routine using:
11538 \begin_inset LatexCommand \index{volatile}
11542 __bit MOSI;\SpecialChar ~
11546 /* master out, slave in */
11548 extern volatile __bit MISO;\SpecialChar ~
11555 extern volatile __bit MCLK;\SpecialChar ~
11564 Output of a byte on a 3-wire serial bus.
11569 If needed adapt polarity of clock,
11570 polarity of data and bit order
11575 unsigned char spi_io(unsigned char out_byte)
11600 MOSI = out_byte & 0x80;
11631 /* _asm nop _endasm; */\SpecialChar ~
11639 /* for slow peripherals */
11691 Then, someplace in the code for the first hardware you would use
11697 \begin_inset LatexCommand \index{at}
11702 \begin_inset LatexCommand \index{\_\_at}
11706 (0x80) MOSI;\SpecialChar ~
11710 /* I/O port 0, bit 0 */
11712 __bit __at (0x81) MISO;\SpecialChar ~
11719 __bit __at (0x82) MCLK;\SpecialChar ~
11723 /* I/O port 0, bit 2 */
11726 Similarly, for the second hardware you would use
11731 __bit __at (0x83) MOSI;\SpecialChar ~
11735 /* I/O port 0, bit 3 */
11737 __bit __at (0x91) MISO;\SpecialChar ~
11742 I/O port 1, bit 1 */
11745 \begin_inset LatexCommand \index{bit}
11749 __at (0x92) MCLK;\SpecialChar ~
11753 /* I/O port 1, bit 2 */
11756 \added_space_bottom bigskip
11757 and you can use the same hardware dependent routine without changes, as
11758 for example in a library.
11759 This is somehow similar to sbit, but only one absolute address has to be
11760 specified in the whole project.
11766 \begin_inset LatexCommand \index{Parameters}
11771 \begin_inset LatexCommand \index{function parameter}
11776 \begin_inset LatexCommand \index{local variables}
11781 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11788 Automatic (local) variables and parameters to functions can either be placed
11789 on the stack or in data-space.
11790 The default action of the compiler is to place these variables in the internal
11791 RAM (for small model) or external RAM (for large model).
11792 This in fact makes them similar to
11795 \begin_inset LatexCommand \index{static}
11801 so by default functions are non-reentrant
11802 \begin_inset LatexCommand \index{reentrant}
11811 They can be placed on the stack
11812 \begin_inset LatexCommand \index{stack}
11831 \begin_inset LatexCommand \index{-\/-stack-auto}
11839 #pragma\SpecialChar ~
11843 \begin_inset LatexCommand \index{\#pragma stackauto}
11850 \begin_inset LatexCommand \index{reentrant}
11856 keyword in the function declaration, e.g.:
11861 unsigned char foo(char i) __reentrant
11875 Since stack space on 8051 is limited, the
11895 option should be used sparingly.
11896 Note that the reentrant keyword just means that the parameters & local
11897 variables will be allocated to the stack, it
11901 mean that the function is register bank
11902 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11911 \begin_inset LatexCommand \index{local variables}
11915 can be assigned storage classes and absolute
11916 \begin_inset LatexCommand \index{Absolute addressing}
11925 unsigned char foo()
11933 __xdata unsigned char i;
11946 \begin_inset LatexCommand \index{at}
11950 (0x31) unsigned char j;
11962 In the above example the variable
11966 will be allocated in the external ram,
11970 in bit addressable space and
11991 or when a function is declared as
11995 this should only be done for static variables.
11999 \begin_inset LatexCommand \index{function parameter}
12003 however are not allowed any storage class
12004 \begin_inset LatexCommand \index{Storage class}
12008 , (storage classes for parameters will be ignored), their allocation is
12009 governed by the memory model in use, and the reentrancy options.
12012 It is however allowed to use bit parameters in reentrant functions and also
12013 non-static local bit variables are supported.
12014 Efficient use is limited to 8 semi-bitregisters in bit space.
12015 They are pushed and popped to stack
12016 \begin_inset LatexCommand \index{stack}
12020 as a single byte just like the normal registers.
12024 \begin_inset LatexCommand \label{sub:Overlaying}
12029 \begin_inset LatexCommand \index{Overlaying}
12037 \begin_inset LatexCommand \index{reentrant}
12041 functions SDCC will try to reduce internal ram space usage by overlaying
12042 parameters and local variables of a function (if possible).
12043 Parameters and local variables
12044 \begin_inset LatexCommand \index{local variables}
12048 of a function will be allocated to an overlayable segment if the function
12051 no other function calls and the function is non-reentrant and the memory
12053 \begin_inset LatexCommand \index{Memory model}
12060 If an explicit storage class
12061 \begin_inset LatexCommand \index{Storage class}
12065 is specified for a local variable, it will NOT be overlayed.
12068 Note that the compiler (not the linkage editor) makes the decision for overlayin
12070 Functions that are called from an interrupt service routine
12071 \begin_inset Marginal
12081 should be preceded by a #pragma\SpecialChar ~
12083 \begin_inset LatexCommand \index{\#pragma nooverlay}
12087 if they are not reentrant.
12090 Also note that the compiler does not do any processing of inline assembler
12091 code, so the compiler might incorrectly assign local variables and parameters
12092 of a function into the overlay segment if the inline assembler code calls
12093 other c-functions that might use the overlay.
12094 In that case the #pragma\SpecialChar ~
12095 nooverlay should be used.
12098 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12100 \begin_inset LatexCommand \index{Multiplication}
12105 \begin_inset LatexCommand \index{Division}
12109 will NOT be overlayed since these are implemented using external functions,
12118 \begin_inset LatexCommand \index{\#pragma nooverlay}
12124 void set_error(unsigned char errcd)
12141 some_isr () __interrupt
12142 \begin_inset LatexCommand \index{interrupt}
12172 \added_space_bottom bigskip
12173 In the above example the parameter
12181 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12183 not present, this could cause unpredictable runtime behavior when called
12184 from an interrupt service routine.
12185 The #pragma\SpecialChar ~
12186 nooverlay ensures that the parameters and local variables for
12187 the function are NOT overlayed.
12192 Interrupt Service Routines
12193 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12200 General Information
12215 outines to be coded in C, with some extended keywords.
12220 void timer_isr (void) __interrupt (1) __using (1)
12234 The optional number following the
12237 \begin_inset LatexCommand \index{interrupt}
12242 \begin_inset LatexCommand \index{\_\_interrupt}
12248 keyword is the interrupt number this routine will service.
12249 When present, the compiler will insert a call to this routine in the interrupt
12251 \begin_inset LatexCommand \index{interrupt vector table}
12255 for the interrupt number specified.
12256 If you have multiple source files in your project, interrupt service routines
12257 can be present in any of them, but a prototype of the isr MUST be present
12258 or included in the file that contains the function
12263 The optional (8051 specific) keyword
12266 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12271 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12277 can be used to tell the compiler to use the specified register bank when
12278 generating code for this function.
12281 Interrupt service routines open the door for some very interesting bugs:
12283 \layout Subsubsection
12284 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12288 Common interrupt pitfall: variable not declared
12293 If an interrupt service routine changes variables which are accessed by
12294 other functions these variables have to be declared
12299 \begin_inset LatexCommand \index{volatile}
12305 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12311 \layout Subsubsection
12312 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12316 Common interrupt pitfall:
12321 If the access to these variables is not
12324 \begin_inset LatexCommand \index{atomic}
12331 the processor needs more than one instruction for the access and could
12332 be interrupted while accessing the variable) the interrupt must be disabled
12333 during the access to avoid inconsistent data.
12336 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12337 and should be protected by disabling interrupts.
12338 You're not automatically on the safe side if you use 8 bit variables though.
12339 We need an example here: f.e.
12340 on the 8051 the harmless looking
12341 \begin_inset Quotes srd
12346 flags\SpecialChar ~
12351 \begin_inset Quotes sld
12360 \begin_inset Quotes srd
12365 flags\SpecialChar ~
12370 \begin_inset Quotes sld
12373 from within an interrupt routine might get lost if the interrupt occurs
12376 \begin_inset Quotes sld
12381 counter\SpecialChar ~
12386 \begin_inset Quotes srd
12389 is not atomic on the 8051 even if
12393 is located in data memory.
12395 Bugs like these are hard to reproduce and can
12396 cause a lot of trouble.
12399 \layout Subsubsection
12400 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12404 Common interrupt pitfall:
12409 The return address and the registers used in the interrupt service routine
12410 are saved on the stack
12411 \begin_inset LatexCommand \index{stack}
12415 so there must be sufficient stack space.
12416 If there isn't variables or registers (or even the return address itself)
12423 \begin_inset LatexCommand \index{stack overflow}
12427 is most likely to happen if the interrupt occurs during the
12428 \begin_inset Quotes sld
12432 \begin_inset Quotes srd
12435 subroutine when the stack is already in use for f.e.
12436 many return addresses.
12438 \layout Subsubsection
12439 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12443 Common interrupt pitfall:
12445 use of non-reentrant functions
12448 A special note here, int (16 bit) and long (32 bit) integer division
12449 \begin_inset LatexCommand \index{Division}
12454 \begin_inset LatexCommand \index{Multiplication}
12459 \begin_inset LatexCommand \index{Modulus}
12464 \begin_inset LatexCommand \index{Floating point support}
12468 operations are implemented using external support routines.
12469 If an interrupt service routine needs to do any of these operations then
12470 the support routines (as mentioned in a following section) will have to
12471 be recompiled using the
12486 \begin_inset LatexCommand \index{-\/-stack-auto}
12492 option and the source file will need to be compiled using the
12509 \begin_inset LatexCommand \index{-\/-int-long-reent}
12516 Note, the type promotion
12517 \begin_inset LatexCommand \index{type promotion}
12521 required by ANSI C can cause 16 bit routines to be used
12522 \begin_inset Marginal
12533 without the programmer being aware of it.
12537 (unsigned char)(tail-1)
12539 within the if clause in section
12540 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12547 \added_space_bottom bigskip
12548 Calling other functions from an interrupt service routine is not recommended,
12549 avoid it if possible.
12550 Note that when some function is called from an interrupt service routine
12551 it should be preceded by a #pragma\SpecialChar ~
12553 \begin_inset LatexCommand \index{\#pragma nooverlay}
12557 if it is not reentrant.
12558 Furthermore nonreentrant functions should not be called from the main program
12559 while the interrupt service routine might be active.
12560 They also must not be called from low priority interrupt service routines
12561 while a high priority interrupt service routine might be active.
12562 You could use semaphores or make the function
12566 if all parameters are passed in registers.
12569 \begin_inset LatexCommand \ref{sub:Overlaying}
12574 about Overlaying and section
12575 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12580 about Functions using private register banks.
12585 MCS51/DS390 Interrupt Service Routines
12589 \begin_inset LatexCommand \index{interrupt}
12593 numbers and the corresponding address & descriptions for the Standard 8051/8052
12595 SDCC will automatically adjust the
12596 \begin_inset LatexCommand \index{interrupt vector table}
12600 to the maximum interrupt number specified.
12606 \begin_inset Tabular
12607 <lyxtabular version="3" rows="9" columns="3">
12609 <column alignment="center" valignment="top" leftline="true" width="0in">
12610 <column alignment="left" valignment="top" leftline="true" width="0in">
12611 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12612 <row topline="true" bottomline="true">
12613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12638 <row topline="true">
12639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12664 <row topline="true">
12665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12690 <row topline="true">
12691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12716 <row topline="true">
12717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12742 <row topline="true">
12743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12768 <row topline="true">
12769 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12794 <row topline="true">
12795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12820 <row topline="true" bottomline="true">
12821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12855 If the interrupt service routine is defined without
12858 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12863 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12869 a register bank or with register bank 0 (
12873 0), the compiler will save the registers used by itself on the stack upon
12874 entry and restore them at exit, however if such an interrupt service routine
12875 calls another function then the entire register bank will be saved on the
12877 This scheme may be advantageous for small interrupt service routines which
12878 have low register usage.
12881 \added_space_bottom bigskip
12882 If the interrupt service routine is defined to be using a specific register
12887 & psw are saved and restored, if such an interrupt service routine calls
12888 another function (using another register bank) then the entire register
12889 bank of the called function will be saved on the stack
12890 \begin_inset LatexCommand \index{stack}
12895 This scheme is recommended for larger interrupt service routines.
12901 \begin_inset LatexCommand \index{HC08}
12905 Interrupt Service Routines
12908 \added_space_bottom bigskip
12909 Since the number of interrupts
12910 \begin_inset LatexCommand \index{HC08!interrupt}
12914 available is chip specific and the interrupt vector table always ends at
12915 the last byte of memory, the interrupt numbers corresponds to the interrupt
12916 vectors in reverse order of address.
12917 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12918 2 will use the interrupt vector at 0xfffa, and so on.
12919 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12920 this way; instead see section
12921 \begin_inset LatexCommand \ref{sub:Startup-Code}
12925 for details on customizing startup.
12930 Z80 Interrupt Service Routines
12934 \begin_inset LatexCommand \index{Z80}
12938 uses several different methods for determining the correct interrupt
12939 \begin_inset LatexCommand \index{Z80!interrupt}
12943 vector depending on the hardware implementation.
12944 Therefore, SDCC ignores the optional interrupt number and does not attempt
12945 to generate an interrupt vector table.
12948 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12949 instruction to return from the interrupt.
12950 To write an interrupt handler for the non-maskable interrupt, which needs
12951 a RETN instruction instead, add the
12960 void nmi_isr (void) critical interrupt
12974 \added_space_bottom bigskip
12975 However if you need to create a non-interruptable interrupt service routine
12976 you would also require the
12981 To distinguish between this and an nmi_isr you must provide an interrupt
12987 Enabling and Disabling Interrupts
12990 Critical Functions and Critical Statements
12993 A special keyword may be associated with a block or a function declaring
12999 SDCC will generate code to disable all interrupts
13000 \begin_inset LatexCommand \index{interrupt}
13004 upon entry to a critical function and restore the interrupt enable to the
13005 previous state before returning.
13006 Nesting critical functions will need one additional byte on the stack
13007 \begin_inset LatexCommand \index{stack}
13016 int foo () __critical
13017 \begin_inset LatexCommand \index{critical}
13022 \begin_inset LatexCommand \index{\_\_critical}
13047 The critical attribute maybe used with other attributes like
13057 may also be used to disable interrupts more locally:
13065 More than one statement could have been included in the block.
13068 Enabling and Disabling Interrupts directly
13072 \begin_inset LatexCommand \index{interrupt}
13076 can also be disabled and enabled directly (8051):
13081 EA = 0;\SpecialChar ~
13144 EA = 1;\SpecialChar ~
13211 On other architectures which have seperate opcodes for enabling and disabling
13212 interrupts you might want to make use of defines with inline assembly
13213 \begin_inset LatexCommand \index{Assembler routines}
13218 \begin_inset LatexCommand \index{HC08!interrupt}
13228 \begin_inset LatexCommand \index{\_asm}
13237 \begin_inset LatexCommand \index{\_endasm}
13246 #define SEI _asm\SpecialChar ~
13258 Note: it is sometimes sufficient to disable only a specific interrupt source
13260 a timer or serial interrupt by manipulating an
13263 \begin_inset LatexCommand \index{interrupt mask}
13273 Usually the time during which interrupts are disabled should be kept as
13275 This minimizes both
13280 \begin_inset LatexCommand \index{interrupt latency}
13284 (the time between the occurrence of the interrupt and the execution of
13285 the first code in the interrupt routine) and
13290 \begin_inset LatexCommand \index{interrupt jitter}
13294 (the difference between the shortest and the longest interrupt latency).
13295 These really are something different, f.e.
13296 a serial interrupt has to be served before its buffer overruns so it cares
13297 for the maximum interrupt latency, whereas it does not care about jitter.
13298 On a loudspeaker driven via a digital to analog converter which is fed
13299 by an interrupt a latency of a few milliseconds might be tolerable, whereas
13300 a much smaller jitter will be very audible.
13303 You can reenable interrupts within an interrupt routine and on some architecture
13304 s you can make use of two (or more) levels of
13306 interrupt priorities
13309 \begin_inset LatexCommand \index{interrupt priority}
13314 On some architectures which don't support interrupt priorities these can
13315 be implemented by manipulating the interrupt mask and reenabling interrupts
13316 within the interrupt routine.
13317 Check there is sufficient space on the stack
13318 \begin_inset LatexCommand \index{stack}
13322 and don't add complexity unless you have to.
13327 \begin_inset LatexCommand \index{semaphore}
13331 locking (mcs51/ds390)
13334 Some architectures (mcs51/ds390) have an atomic
13335 \begin_inset LatexCommand \index{atomic}
13348 These type of instructions are typically used in preemptive multitasking
13349 systems, where a routine f.e.
13350 claims the use of a data structure ('acquires a lock
13351 \begin_inset LatexCommand \index{lock}
13355 on it'), makes some modifications and then releases the lock when the data
13356 structure is consistent again.
13357 The instruction may also be used if interrupt and non-interrupt code have
13358 to compete for a resource.
13359 With the atomic bit test and clear instruction interrupts
13360 \begin_inset LatexCommand \index{interrupt}
13364 don't have to be disabled for the locking operation.
13368 SDCC generates this instruction if the source follows this pattern:
13374 \begin_inset LatexCommand \index{volatile}
13378 bit resource_is_free;
13382 if (resource_is_free)
13392 resource_is_free=0;
13405 resource_is_free=1;
13412 Note, mcs51 and ds390 support only an atomic
13413 \begin_inset LatexCommand \index{atomic}
13421 instruction (as opposed to atomic bit test and
13426 Functions using private register banks
13427 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13434 Some architectures have support for quickly changing register sets.
13435 SDCC supports this feature with the
13438 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13443 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13449 attribute (which tells the compiler to use a register bank
13450 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13454 other than the default bank zero).
13455 It should only be applied to
13458 \begin_inset LatexCommand \index{interrupt}
13464 functions (see footnote below).
13465 This will in most circumstances make the generated ISR code more efficient
13466 since it will not have to save registers on the stack.
13473 attribute will have no effect on the generated code for a
13477 function (but may occasionally be useful anyway
13482 possible exception: if a function is called ONLY from 'interrupt' functions
13483 using a particular bank, it can be declared with the same 'using' attribute
13484 as the calling 'interrupt' functions.
13485 For instance, if you have several ISRs using bank one, and all of them
13486 call memcpy(), it might make sense to create a specialized version of memcpy()
13487 'using 1', since this would prevent the ISR from having to save bank zero
13488 to the stack on entry and switch to bank zero before calling the function
13496 (pending: Note, nowadays the
13500 attribute has an effect on
13504 the generated code for a
13519 function using a non-zero bank will assume that it can trash that register
13520 bank, and will not save it.
13521 Since high-priority interrupts
13522 \begin_inset LatexCommand \index{interrupts}
13527 \begin_inset LatexCommand \index{interrupt priority}
13531 can interrupt low-priority ones on the 8051 and friends, this means that
13532 if a high-priority ISR
13536 a particular bank occurs while processing a low-priority ISR
13540 the same bank, terrible and bad things can happen.
13541 To prevent this, no single register bank should be
13545 by both a high priority and a low priority ISR.
13546 This is probably most easily done by having all high priority ISRs use
13547 one bank and all low priority ISRs use another.
13548 If you have an ISR which can change priority at runtime, you're on your
13549 own: I suggest using the default bank zero and taking the small performance
13553 \added_space_bottom bigskip
13554 It is most efficient if your ISR calls no other functions.
13555 If your ISR must call other functions, it is most efficient if those functions
13556 use the same bank as the ISR (see note 1 below); the next best is if the
13557 called functions use bank zero.
13558 It is very inefficient to call a function using a different, non-zero bank
13566 \begin_inset LatexCommand \label{sub:Startup-Code}
13571 \begin_inset LatexCommand \index{Startup code}
13578 MCS51/DS390 Startup Code
13581 The compiler triggers the linker to link certain initialization modules
13582 from the runtime library
13583 \begin_inset LatexCommand \index{Runtime library}
13587 called crt<something>.
13588 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
13589 GSINIT5) is not linked unless the --xstack option is used.
13590 These modules are highly entangled by the use of special segments/areas,
13591 but a common layout is shown below:
13624 ljmp __sdcc_gsinit_startup
13645 .area GSINIT0 (CODE)
13647 __sdcc_gsinit_startup::
13657 mov sp,#__start__stack - 1
13678 .area GSINIT1 (CODE)
13680 __sdcc_init_xstack::
13682 ; Need to initialize in GSINIT1 in
13683 case the user's __sdcc_external_startup uses the xstack.
13693 mov __XPAGE,#(__start__x
13704 mov _spx,#__start__xstack
13725 .area GSINIT2 (CODE)
13735 lcall __sdcc_external_startup
13755 jz __sdcc_init_data
13766 __sdcc_program_startup
13789 .area GSINIT3 (CODE)
13842 mov r2,#((l_XINIT+255) >> 8)
13873 __XPAGE,#(s_XISEG >> 8)
13875 00001$:\SpecialChar ~
13939 00002$:\SpecialChar ~
13984 .area GSINIT4 (CODE)
13986 __mcs51_genRAMCLEAR::
14008 00004$:\SpecialChar ~
14022 ; _mcs51_genRAMCLEAR() end
14043 .area GSINIT4 (CODE)
14045 __mcs51_genXRAMCLEAR::
14096 mov __XPAGE,#(s_PSEG >> 8)
14108 00005$:\SpecialChar ~
14162 orl a,#(l_XSEG >> 8)
14205 00007$:\SpecialChar ~
14260 .area GSINIT5 (CODE)
14262 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
14265 ; and __mcs51_genRAMCLEAR modifies _spx.
14275 mov __XPAGE,#(__start__x
14286 mov _spx,#__start__xstack
14293 (application modules)
14307 .area GSINIT (CODE)
14328 .area GSFINAL (CODE)
14338 ljmp __sdcc_program_startup
14340 ;---------------------------------
14341 -----------------------
14345 ;--------------------------------------------------
14368 __sdcc_program_startup:
14381 return from main will lock up
14394 One of these modules (crtstart.asm) contains a call to the C routine
14396 _sdcc_external_startup()
14397 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
14406 at the start of the CODE area.
14407 This routine is also in the runtime library
14408 \begin_inset LatexCommand \index{Runtime library}
14412 and returns 0 by default.
14413 If this routine returns a non-zero value, the static & global variable
14414 initialization will be skipped and the function main will be invoked.
14415 Otherwise static & global variables will be initialized before the function
14419 _sdcc_external_startup()
14421 routine to your program to override the default if you need to setup hardware
14422 or perform some other critical operation prior to static & global variable
14424 \begin_inset LatexCommand \index{Variable initialization}
14429 On some mcs51 variants xdata
14430 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
14434 memory has to be explicitly enabled before it can be accessed or if the
14436 \begin_inset LatexCommand \index{watchdog}
14440 needs to be disabled, this is the place to do it.
14441 The startup code clears all internal data memory, 256 bytes by default,
14442 but from 0 to n-1 if
14457 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
14464 (recommended for Chipcon CC1010).
14467 \added_space_bottom bigskip
14468 See also the compiler options
14489 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14510 \begin_inset LatexCommand \index{-\/-main-return}
14515 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14519 about MCS51-variants.
14527 \added_space_bottom bigskip
14529 \begin_inset LatexCommand \index{HC08}
14533 startup code follows the same scheme as the MCS51 startup code.
14541 \added_space_bottom bigskip
14543 \begin_inset LatexCommand \index{Z80}
14547 the startup code is inserted by linking with crt0.o which is generated from
14548 sdcc/device/lib/z80/crt0.s.
14549 If you need a different startup code you can use the compiler option
14572 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14576 and provide your own crt0.o.
14582 Inline Assembler Code
14583 \begin_inset LatexCommand \index{Assembler routines}
14590 A Step by Step Introduction
14591 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14598 Starting from a small snippet of c-code this example shows for the MCS51
14599 how to use inline assembly, access variables, a function parameter and
14600 an array in xdata memory.
14601 The example uses an MCS51 here but is easily adapted for other architectures.
14602 This is a buffer routine which should be optimized:
14608 unsigned char __far
14609 \begin_inset LatexCommand \index{far (storage class)}
14614 \begin_inset LatexCommand \index{\_\_far (storage class)}
14619 \begin_inset LatexCommand \index{at}
14624 \begin_inset LatexCommand \index{\_\_at}
14628 (0x7f00) buf[0x100];
14629 \begin_inset LatexCommand \index{Aligned array}
14635 unsigned char head, tail;\SpecialChar ~
14653 \begin_inset LatexCommand \index{interrupt}
14705 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14717 void to_buffer( unsigned char c )
14725 if( head != (unsigned char)(tail-1)
14732 \begin_inset LatexCommand \index{promotion to signed int}
14737 \begin_inset LatexCommand \index{type promotion}
14742 \begin_inset Marginal
14763 buf[ head++ ] = c;\SpecialChar ~
14779 /* access to a 256 byte aligned array */
14784 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14785 then a corresponding buffer.asm file is generated.
14786 We define a new function
14790 in file buffer.c in which we cut and paste the generated code, removing
14791 unwanted comments and some ':'.
14793 \begin_inset Quotes sld
14797 \begin_inset Quotes srd
14801 \begin_inset Quotes sld
14805 \begin_inset Quotes srd
14808 to the beginning and the end of the function body:
14814 /* With a cut and paste from the .asm file, we have something to start with.
14820 function is not yet OK! (registers aren't saved) */
14822 void to_buffer_asm(
14832 \begin_inset LatexCommand \index{\_asm}
14837 \begin_inset LatexCommand \index{\_\_asm}
14851 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14857 \begin_inset LatexCommand \index{promotion to signed int}
14862 \begin_inset LatexCommand \index{type promotion}
14915 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14916 \begin_inset LatexCommand \index{Aligned array}
14982 \begin_inset LatexCommand \index{\_endasm}
14987 \begin_inset LatexCommand \index{\_\_endasm}
14996 The new file buffer.c should compile with only one warning about the unreferenced
14997 function argument 'c'.
14998 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14999 (1) and finally have:
15005 unsigned char __far __at(0x7f00) buf[0x100];
15007 unsigned char head, tail;
15018 void to_buffer( unsigned char c )
15027 head != (unsigned char)(tail-1) )
15056 c; // to avoid warning: unreferenced function argument
15063 \begin_inset LatexCommand \index{\_asm}
15068 \begin_inset LatexCommand \index{\_\_asm}
15082 ; save used registers here.
15093 ; If we were still using r2,r3 we would have to push them here.
15096 ; if( head != (unsigned char)(tail-1) )
15140 could do an ANL a,#0x0f here to use a smaller buffer (see below)
15176 a,dpl \SpecialChar ~
15183 ; dpl holds lower byte of function argument
15195 dpl,_head \SpecialChar ~
15198 ; buf is 0x100 byte aligned so head can be used directly
15241 ; we could do an ANL _head,#0x0f here to use a
15242 smaller buffer (see above)
15254 ; restore used registers here
15261 \begin_inset LatexCommand \index{\_endasm}
15266 \begin_inset LatexCommand \index{\_\_endasm}
15277 The inline assembler code can contain any valid code understood by the assembler
15278 , this includes any assembler directives and comment lines.
15279 The assembler does not like some characters like ':' or ''' in comments.
15280 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
15281 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
15286 \begin_inset LatexCommand \index{Assembler documentation}
15291 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
15299 The compiler does not do any validation of the code within the
15302 \begin_inset LatexCommand \index{\_asm}
15307 \begin_inset LatexCommand \index{\_\_asm}
15315 \begin_inset LatexCommand \index{\_endasm}
15320 \begin_inset LatexCommand \index{\_\_endasm}
15329 Specifically it will not know which registers are used and thus register
15331 \begin_inset LatexCommand \index{push/pop}
15335 has to be done manually.
15339 It is recommended that each assembly instruction (including labels) be placed
15340 in a separate line (as the example shows).
15356 \begin_inset LatexCommand \index{-\/-peep-asm}
15362 command line option is used, the inline assembler code will be passed through
15363 the peephole optimizer
15364 \begin_inset LatexCommand \index{Peephole optimizer}
15369 There are only a few (if any) cases where this option makes sense, it might
15370 cause some unexpected changes in the inline assembler code.
15371 Please go through the peephole optimizer rules defined in file
15375 before using this option.
15379 \begin_inset LatexCommand \label{sub:Naked-Functions}
15384 \begin_inset LatexCommand \index{Naked functions}
15391 A special keyword may be associated with a function declaring it as
15394 \begin_inset LatexCommand \index{\_naked}
15399 \begin_inset LatexCommand \index{\_\_naked}
15410 function modifier attribute prevents the compiler from generating prologue
15411 \begin_inset LatexCommand \index{function prologue}
15416 \begin_inset LatexCommand \index{function epilogue}
15420 code for that function.
15421 This means that the user is entirely responsible for such things as saving
15422 any registers that may need to be preserved, selecting the proper register
15423 bank, generating the
15427 instruction at the end, etc.
15428 Practically, this means that the contents of the function must be written
15429 in inline assembler.
15430 This is particularly useful for interrupt functions, which can have a large
15431 (and often unnecessary) prologue/epilogue.
15432 For example, compare the code generated by these two functions:
15438 \begin_inset LatexCommand \index{volatile}
15442 data unsigned char counter;
15446 void simpleInterrupt(void) __interrupt
15447 \begin_inset LatexCommand \index{interrupt}
15452 \begin_inset LatexCommand \index{\_\_interrupt}
15470 void nakedInterrupt(void) __interrupt (2) __naked
15479 \begin_inset LatexCommand \index{\_asm}
15484 \begin_inset LatexCommand \index{\_\_asm}
15501 _counter ; does not change flags, no need to save psw
15514 include ret or reti in _naked function.
15521 \begin_inset LatexCommand \index{\_endasm}
15526 \begin_inset LatexCommand \index{\_\_endasm}
15535 For an 8051 target, the generated simpleInterrupt looks like:
15544 example, recent versions of SDCC generate
15550 code for simpleInterrupt() and nakedInterrupt()!
15691 whereas nakedInterrupt looks like:
15706 _counter ; does not change flags, no need to save psw
15725 MUST explicitly include ret or reti in _naked function
15728 The related directive #pragma exclude
15729 \begin_inset LatexCommand \index{\#pragma exclude}
15733 allows a more fine grained control over pushing & popping
15734 \begin_inset LatexCommand \index{push/pop}
15741 While there is nothing preventing you from writing C code inside a
15745 function, there are many ways to shoot yourself in the foot doing this,
15746 and it is recommended that you stick to inline assembler.
15749 Use of Labels within Inline Assembler
15752 SDCC allows the use of in-line assembler with a few restrictions regarding
15754 In older versions of the compiler all labels defined within inline assembler
15763 where nnnn is a number less than 100 (which implies a limit of utmost 100
15764 inline assembler labels
15778 \begin_inset LatexCommand \index{\_asm}
15783 \begin_inset LatexCommand \index{\_\_asm}
15813 \begin_inset LatexCommand \index{\_endasm}
15818 \begin_inset LatexCommand \index{\_\_endasm}
15825 Inline assembler code cannot reference any C-Labels, however it can reference
15827 \begin_inset LatexCommand \index{Labels}
15831 defined by the inline assembler, e.g.:
15856 ; some assembler code
15877 /* some more c code */
15879 clabel:\SpecialChar ~
15881 /* inline assembler cannot reference this
15894 $0003: ;label (can be referenced by inline assembler only)
15902 \begin_inset LatexCommand \index{\_endasm}
15907 \begin_inset LatexCommand \index{\_\_endasm}
15917 /* some more c code */
15922 In other words inline assembly code can access labels defined in inline
15923 assembly within the scope of the function.
15924 The same goes the other way, i.e.
15925 labels defines in inline assembly can not be accessed by C statements.
15928 Interfacing with Assembler Code
15929 \begin_inset LatexCommand \index{Assembler routines}
15936 Global Registers used for Parameter Passing
15937 \begin_inset LatexCommand \index{Parameter passing}
15944 The compiler always uses the global registers
15947 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15952 \begin_inset LatexCommand \index{DPTR}
15957 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15966 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15972 to pass the first parameter to a routine.
15973 The second parameter onwards is either allocated on the stack (for reentrant
15986 -stack-auto is used) or in data / xdata memory (depending on the memory
15991 Assembler Routine (non-reentrant)
15994 In the following example
15995 \begin_inset LatexCommand \index{reentrant}
16000 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
16004 the function c_func calls an assembler routine asm_func, which takes two
16006 \begin_inset LatexCommand \index{function parameter}
16015 extern int asm_func(unsigned char, unsigned char);
16019 int c_func (unsigned char
16020 i, unsigned char j)
16028 return asm_func(i,j);
16042 return c_func(10,9);
16047 The corresponding assembler function is:
16052 .globl _asm_func_PARM_2
16154 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16171 Note here that the return values
16172 \begin_inset LatexCommand \index{return value}
16176 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
16178 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
16179 b' & 'acc' for four byte values.
16182 The parameter naming convention is _<function_name>_PARM_<n>, where n is
16183 the parameter number starting from 1, and counting from the left.
16184 The first parameter is passed in
16185 \begin_inset Quotes eld
16189 \begin_inset Quotes erd
16192 for a one byte parameter,
16193 \begin_inset Quotes eld
16197 \begin_inset Quotes erd
16201 \begin_inset Quotes eld
16205 \begin_inset Quotes erd
16208 for three bytes and
16209 \begin_inset Quotes eld
16213 \begin_inset Quotes erd
16216 for a four bytes parameter.
16217 The variable name for the second parameter will be _<function_name>_PARM_2.
16222 ble the assembler routine with the following command:
16229 asx8051 -losg asmfunc.asm
16236 Then compile and link the assembler routine to the C source file with the
16244 sdcc cfunc.c asmfunc.rel
16247 Assembler Routine (reentrant)
16251 \begin_inset LatexCommand \index{reentrant}
16256 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
16260 the second parameter
16261 \begin_inset LatexCommand \index{function parameter}
16265 onwards will be passed on the stack, the parameters are pushed from right
16267 after the call the leftmost parameter will be on the top of the stack.
16268 Here is an example:
16273 extern int asm_func(unsigned char, unsigned char);
16277 int c_func (unsigned char
16278 i, unsigned char j) reentrant
16286 return asm_func(i,j);
16306 The corresponding assembler routine is:
16408 \added_space_bottom bigskip
16409 The compiling and linking procedure remains the same, however note the extra
16410 entry & exit linkage required for the assembler code, _bp is the stack
16411 frame pointer and is used to compute the offset into the stack for parameters
16412 and local variables.
16418 \begin_inset LatexCommand \index{int (16 bit)}
16423 \begin_inset LatexCommand \index{long (32 bit)}
16430 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
16431 multiplication and modulus operations are implemented by support routines.
16432 These support routines are all developed in ANSI-C to facilitate porting
16433 to other MCUs, although some model specific assembler optimizations are
16435 The following files contain the described routines, all of them can be
16436 found in <installdir>/share/sdcc/lib.
16442 \begin_inset Tabular
16443 <lyxtabular version="3" rows="11" columns="2">
16445 <column alignment="left" valignment="top" leftline="true" width="0">
16446 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16447 <row topline="true" bottomline="true">
16448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16469 <row topline="true">
16470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16482 16 bit multiplication
16487 <row topline="true">
16488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16500 signed 16 bit division (calls _divuint)
16505 <row topline="true">
16506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16518 unsigned 16 bit division
16523 <row topline="true">
16524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16536 signed 16 bit modulus (calls _moduint)
16541 <row topline="true">
16542 <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">
16554 unsigned 16 bit modulus
16559 <row topline="true">
16560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16572 32 bit multiplication
16577 <row topline="true">
16578 <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">
16590 signed 32 division (calls _divulong)
16595 <row topline="true">
16596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16608 unsigned 32 division
16613 <row topline="true">
16614 <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">
16626 signed 32 bit modulus (calls _modulong)
16631 <row topline="true" bottomline="true">
16632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16644 unsigned 32 bit modulus
16658 Since they are compiled as
16663 \begin_inset LatexCommand \index{reentrant}
16668 \begin_inset LatexCommand \index{interrupt}
16672 service routines should not do any of the above operations.
16673 If this is unavoidable then the above routines will need to be compiled
16689 \begin_inset LatexCommand \index{-\/-stack-auto}
16695 option, after which the source program will have to be compiled with
16710 \begin_inset LatexCommand \index{-\/-int-long-reent}
16717 Notice that you don't have to call these routines directly.
16718 The compiler will use them automatically every time an integer operation
16722 Floating Point Support
16723 \begin_inset LatexCommand \index{Floating point support}
16730 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16731 The floating point support routines are derived from gcc's floatlib.c and
16732 consist of the following routines:
16740 \begin_inset Tabular
16741 <lyxtabular version="3" rows="17" columns="2">
16743 <column alignment="left" valignment="top" leftline="true" width="0">
16744 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16745 <row topline="true" bottomline="true">
16746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16772 <row topline="true">
16773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16803 add floating point numbers
16808 <row topline="true">
16809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16839 subtract floating point numbers
16844 <row topline="true">
16845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16875 divide floating point numbers
16880 <row topline="true">
16881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16911 multiply floating point numbers
16916 <row topline="true">
16917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16947 convert floating point to unsigned char
16952 <row topline="true">
16953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16983 convert floating point to signed char
16988 <row topline="true">
16989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17019 convert floating point to unsigned int
17024 <row topline="true">
17025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17055 convert floating point to signed int
17060 <row topline="true">
17061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17099 convert floating point to unsigned long
17104 <row topline="true">
17105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17135 convert floating point to signed long
17140 <row topline="true">
17141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17171 convert unsigned char to floating point
17176 <row topline="true">
17177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17207 convert char to floating point number
17212 <row topline="true">
17213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17243 convert unsigned int to floating point
17248 <row topline="true">
17249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17279 convert int to floating point numbers
17284 <row topline="true">
17285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17315 convert unsigned long to floating point number
17320 <row topline="true" bottomline="true">
17321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17351 convert long to floating point number
17365 \added_space_bottom bigskip
17366 These support routines are developed in ANSI-C so there is room for space
17367 and speed improvement
17372 These floating point routines (
17376 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17382 Note if all these routines are used simultaneously the data space might
17384 For serious floating point usage the large model might be needed.
17385 Also notice that you don't have to call this routines directly.
17386 The compiler will use them automatically every time a floating point operation
17393 \begin_inset LatexCommand \index{Libraries}
17402 <pending: this is messy and incomplete - a little more information is in
17403 sdcc/doc/libdoc.txt
17408 Compiler support routines (_gptrget, _mulint etc.)
17411 Stdclib functions (puts, printf, strcat etc.)
17413 \layout Subsubsection
17417 getchar(), putchar()
17420 \begin_inset LatexCommand \index{<stdio.h>}
17424 As usual on embedded systems you have to provide your own
17427 \begin_inset LatexCommand \index{getchar()}
17436 \begin_inset LatexCommand \index{putchar()}
17443 SDCC does not know whether the system connects to a serial line with or
17444 without handshake, LCD, keyboard or other device.
17458 You'll find examples for serial routines f.e.
17459 in sdcc/device/lib.
17460 For the mcs51 this minimalistic polling
17464 routine might be a start:
17469 void putchar (char c) {
17475 while (!TI)\SpecialChar ~
17478 /* assumes UART is initialized */
17512 \begin_inset LatexCommand \index{printf()}
17522 does not support float (except on ds390).
17523 To enable this recompile it with the option
17538 \begin_inset LatexCommand \index{USE\_FLOATS}
17544 on the command line.
17560 \begin_inset LatexCommand \index{-\/-model-large}
17566 for the mcs51 port, since this uses a lot of memory.
17569 If you're short on code memory you might want to use
17572 \begin_inset LatexCommand \index{printf\_small()}
17587 For the mcs51 there additionally are assembly versions
17590 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17596 (subset of printf using less than 270 bytes) and
17599 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17608 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17614 (floating-point aware version of printf_fast) which should fit the requirements
17615 of many embedded systems (printf_fast() can be customized by unsetting
17620 support long variables and field widths).
17621 Be sure to use only one of these printf options within a project.
17626 Feature matrix of different
17633 \begin_inset Tabular
17634 <lyxtabular version="3" rows="14" columns="7">
17635 <features islongtable="true">
17636 <column alignment="left" valignment="center" leftline="true" width="14col%">
17637 <column alignment="center" valignment="top" leftline="true" width="0">
17638 <column alignment="center" valignment="top" leftline="true" width="12col%">
17639 <column alignment="center" valignment="top" leftline="true" width="10col%">
17640 <column alignment="center" valignment="top" leftline="true" width="0">
17641 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17642 <column alignment="center" valignment="top" rightline="true" width="0">
17643 <row topline="true" bottomline="true" endhead="true">
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17660 \begin_inset LatexCommand \index{printf}
17668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17711 <row topline="true" endhead="true">
17712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17781 <row topline="true" endhead="true">
17782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17786 \begin_inset Quotes sld
17790 \begin_inset Quotes srd
17800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17849 <row topline="true" endhead="true">
17850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17881 0.45k / 0.47k (+ _ltoa)
17885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17910 <row topline="true">
17911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18046 <row topline="true">
18047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18051 long (32 bit) support
18055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18113 <row topline="true">
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18118 byte arguments on stack
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18171 <row topline="true">
18172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18177 \begin_inset LatexCommand \index{Floating point support}
18185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18226 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18243 <row topline="true">
18244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18248 float formats %e %g
18252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18301 <row topline="true" bottomline="true">
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18359 <row bottomline="true">
18360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18369 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18373 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18433 <row bottomline="true">
18434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18443 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18504 printf_tiny integer speed is data dependent, worst case is 0.33 ms
18513 <row bottomline="true">
18514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18523 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18584 <row bottomline="true">
18585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18594 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18661 \layout Subsubsection
18663 \begin_inset LatexCommand \index{malloc.h}
18670 As of SDCC 2.6.2 you no longer need to call an initialization routine before
18671 using dynamic memory allocation
18672 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
18677 \begin_inset LatexCommand \index{heap (malloc)}
18681 space of 1024 bytes is provided for malloc to allocate memory from.
18682 If you need a different heap size you need to recompile _heap.c with the
18683 required size defined in HEAP_SIZE.
18684 It is recommended to make a copy of this file into your project directory
18685 and compile it there with:
18690 sdcc -c _heap.c -D HEAD_SIZE=2048
18693 And then link it with:
18698 sdcc main.rel _heap.rel
18701 Math functions (sinf, powf, sqrtf etc.)
18703 \layout Subsubsection
18707 See definitions in file <math.h>.
18714 \begin_inset LatexCommand \index{Libraries}
18718 included in SDCC should have a license at least as liberal as the GNU Lesser
18719 General Public License
18720 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
18735 license statements for the libraries are missing.
18736 sdcc/device/lib/ser_ir.c
18740 come with a GPL (as opposed to LGPL) License - this will not be liberal
18741 enough for many embedded programmers.
18748 If you have ported some library or want to share experience about some code
18750 falls into any of these categories Busses (I
18751 \begin_inset Formula $^{\textrm{2}}$
18754 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
18755 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
18756 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
18757 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
18762 would certainly like to hear about it.
18765 \added_space_bottom bigskip
18766 Programmers coding for embedded systems are not especially famous for being
18767 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
18768 e these references are very valuable.
18769 Let's help to create a climate where information is shared.
18777 MCS51 Memory Models
18778 \begin_inset LatexCommand \index{Memory model}
18783 \begin_inset LatexCommand \index{MCS51 memory model}
18789 \layout Subsubsection
18790 Small, Medium and Large
18793 SDCC allows three memory models for MCS51 code,
18802 Modules compiled with different memory models should
18806 be combined together or the results would be unpredictable.
18807 The library routines supplied with the compiler are compiled as small,
18809 The compiled library modules are contained in separate directories as small,
18810 medium and large so that you can link to the appropriate set.
18813 When the medium or large model is used all variables declared without a
18814 storage class will be allocated into the external ram, this includes all
18815 parameters and local variables (for non-reentrant
18816 \begin_inset LatexCommand \index{reentrant}
18821 When the small model is used variables without storage class are allocated
18822 in the internal ram.
18825 Judicious usage of the processor specific storage classes
18826 \begin_inset LatexCommand \index{Storage class}
18830 and the 'reentrant' function type will yield much more efficient code,
18831 than using the large model.
18832 Several optimizations are disabled when the program is compiled using the
18833 large model, it is therefore recommended that the small model be used unless
18834 absolutely required.
18836 \layout Subsubsection
18838 \begin_inset LatexCommand \label{sub:External-Stack}
18843 \begin_inset LatexCommand \index{stack}
18848 \begin_inset LatexCommand \index{External stack (mcs51)}
18855 The external stack (-
18868 \begin_inset LatexCommand \index{-\/-xstack}
18872 ) is located in pdata
18873 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18877 memory (usually at the start of the external ram segment) and uses all
18878 unused space in pdata (max.
18892 -xstack option is used to compile the program, the parameters and local
18894 \begin_inset LatexCommand \index{local variables}
18898 of all reentrant functions are allocated in this area.
18899 This option is provided for programs with large stack space requirements.
18900 When used with the -
18913 \begin_inset LatexCommand \index{-\/-stack-auto}
18917 option, all parameters and local variables are allocated on the external
18918 stack (note: support libraries will need to be recompiled with the same
18920 There is a predefined target in the library makefile).
18923 The compiler outputs the higher order address byte of the external ram segment
18925 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18930 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18934 ), therefore when using the External Stack option, this port
18938 be used by the application program.
18942 \begin_inset LatexCommand \index{Memory model}
18947 \begin_inset LatexCommand \index{DS390 memory model}
18954 The only model supported is Flat 24
18955 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18960 This generates code for the 24 bit contiguous addressing mode of the Dallas
18962 In this mode, up to four meg of external RAM or code space can be directly
18964 See the data sheets at www.dalsemi.com for further information on this part.
18969 that the compiler does not generate any code to place the processor into
18970 24 bitmode (although
18974 in the ds390 libraries will do that for you).
18980 \begin_inset LatexCommand \index{Tinibios (DS390)}
18984 , the boot loader or similar code must ensure that the processor is in 24
18985 bit contiguous addressing mode before calling the SDCC startup code.
19006 option, variables will by default be placed into the XDATA segment.
19011 Segments may be placed anywhere in the 4 meg address space using the usual
19025 Note that if any segments are located above 64K, the -r flag must be passed
19026 to the linker to generate the proper segment relocations, and the Intel
19027 HEX output format must be used.
19028 The -r flag can be passed to the linker by using the option
19032 on the SDCC command line.
19033 However, currently the linker can not handle code segments > 64k.
19037 \begin_inset LatexCommand \label{sec:Pragmas}
19042 \begin_inset LatexCommand \index{Pragmas}
19049 SDCC supports the following #pragma directives:
19057 \begin_inset LatexCommand \index{\#pragma save}
19061 - this will save most current options to the save/restore stack.
19062 See #pragma\SpecialChar ~
19071 \begin_inset LatexCommand \index{\#pragma restore}
19075 - will restore saved options from the last save.
19076 saves & restores can be nested.
19077 SDCC uses a save/restore stack: save pushes current options to the stack,
19078 restore pulls current options from the stack.
19079 See #pragma\SpecialChar ~
19090 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19095 \begin_inset LatexCommand \index{function prologue}
19099 function1[,function2[,function3...]] - The compiler by default uses a caller
19100 saves convention for register saving across function calls, however this
19101 can cause unnecessary register pushing & popping
19102 \begin_inset LatexCommand \index{push/pop}
19106 when calling small functions from larger functions.
19107 This option can be used to switch off the register saving convention for
19108 the function names specified.
19109 The compiler will not save registers when calling these functions, extra
19110 code need to be manually inserted at the entry & exit for these functions
19111 to save & restore the registers used by these functions, this can SUBSTANTIALLY
19112 reduce code & improve run time performance of the generated code.
19113 In the future the compiler (with inter procedural analysis) may be able
19114 to determine the appropriate scheme to use for each function call.
19127 -callee-saves command line option is used, the function names specified
19128 in #pragma\SpecialChar ~
19130 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19134 is appended to the list of functions specified in the command line.
19142 \begin_inset LatexCommand \index{\#pragma exclude}
19146 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19147 of pairs of push/pop
19148 \begin_inset LatexCommand \index{push/pop}
19157 \begin_inset LatexCommand \index{interrupt}
19170 The directive should be placed immediately before the ISR function definition
19171 and it affects ALL ISR functions following it.
19172 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
19173 exclude\SpecialChar ~
19175 \begin_inset LatexCommand \index{\#pragma exclude}
19180 See also the related keyword _naked
19181 \begin_inset LatexCommand \index{\_naked}
19186 \begin_inset LatexCommand \index{\_\_naked}
19198 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19202 - the compiler will not warn you anymore for obvious mistakes, you'r on
19211 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19215 - the compiler will not warn you anymore about warning number <nnnn>.
19223 \begin_inset LatexCommand \index{\#pragma nogcse}
19227 - will stop global common subexpression elimination.
19235 \begin_inset LatexCommand \index{\#pragma noinduction}
19239 - will stop loop induction optimizations.
19247 \begin_inset LatexCommand \index{\#pragma noinvariant}
19251 - will not do loop invariant optimizations.
19252 For more details see Loop Invariants in section
19253 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19265 \begin_inset LatexCommand \index{\#pragma noiv}
19269 - Do not generate interrupt
19270 \begin_inset LatexCommand \index{interrupt}
19275 \begin_inset LatexCommand \index{interrupt vector table}
19279 entries for all ISR functions defined after the pragma.
19280 This is useful in cases where the interrupt vector table must be defined
19281 manually, or when there is a secondary, manually defined interrupt vector
19283 for the autovector feature of the Cypress EZ-USB FX2).
19284 More elegantly this can be achieved by obmitting the optional interrupt
19285 number after the interrupt keyword, see section
19286 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19299 \begin_inset LatexCommand \index{\#pragma nojtbound}
19303 - will not generate code for boundary value checking, when switch statements
19304 are turned into jump-tables (dangerous).
19305 For more details see section
19306 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19318 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19322 - Will not do loop reversal optimization
19330 \begin_inset LatexCommand \index{\#pragma nooverlay}
19334 - the compiler will not overlay the parameters and local variables of a
19343 \begin_inset LatexCommand \index{\#pragma stackauto}
19360 \begin_inset LatexCommand \index{-\/-stack-auto}
19365 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19369 Parameters and Local Variables.
19377 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19381 - The compiler will optimize code generation towards fast code, possibly
19382 at the expense of code size.
19383 Currently this has little effect.
19391 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19395 - The compiler will optimize code generation towards compact code, possibly
19396 at the expense of code speed.
19397 Currently this has little effect.
19405 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19409 - The compiler will attempt to generate code that is both compact and fast,
19410 as long as meeting one goal is not a detriment to the other (this is the
19420 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19424 - Generally follow the C89 standard, but allow SDCC features that conflict
19425 with the standard (default).
19433 \begin_inset LatexCommand \index{\#pragma std\_c89}
19437 - Follow the C89 standard and disable SDCC features that conflict with the
19446 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19450 - Generally follow the C99 standard, but allow SDCC features that conflict
19451 with the standard (incomplete support).
19459 \begin_inset LatexCommand \index{\#pragma std\_c99}
19463 - Follow the C99 standard and disable SDCC features that conflict with the
19464 standard (incomplete support).
19472 \begin_inset LatexCommand \index{\#pragma codeseg}
19476 - Use this name (max.
19477 8 characters) for the code segment.
19498 \begin_inset LatexCommand \index{\#pragma constseg}
19502 - Use this name (max.
19503 8 characters) for the const segment.
19519 The preprocessor SDCPP
19520 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19524 supports the following #pragma directives:
19529 pedantic_parse_number
19532 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19536 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19537 parsed properly and the macro LO_B(3) gets expanded.
19539 Below is an example on how to use this pragma.
19542 Note: this functionality is not in conformance with standard!
19547 #pragma pedantic_parse_number +
19548 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19556 #define LO_B(x) ((x) & 0xff)
19560 unsigned char foo(void)
19567 unsigned char c=0xfe-LO_B(3)
19587 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19591 (+ | -) - switch _asm _endasm block preprocessing on / off.
19593 You use this prama to define multilines of assembly code.
19594 This will prevent the preprocessor from changing the formating required
19596 Below is an example on how to use this pragma.
19601 #pragma preproc_asm -
19602 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19608 #define MYDELAY _asm
19613 nop ;my assembly comment...
19627 #pragma preproc_asm
19663 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19667 (+ | -) - Allow "naked" hash in macro definition, for example:
19671 #define DIR_LO(x) #(x & 0xff)
19676 Below is an example on how to use this pragma.
19681 #pragma preproc_asm +
19683 #pragma sdcc_hash +
19684 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19699 mov R6_B3, #(x & 0xff)
19706 mov R7_B3, #((x >> 8) & 0xff)
19730 The pragma's are intended to be used to turn-on or off certain optimizations
19731 which might cause the compiler to generate extra stack / data space to
19732 store compiler generated temporary variables.
19733 This usually happens in large functions.
19734 Pragma directives should be used as shown in the following example, they
19735 are used to control options & optimizations for a given function; pragmas
19736 should be placed before and/or after a function, placing pragma's inside
19737 a function body could have unpredictable results.
19743 \begin_inset LatexCommand \index{\#pragma save}
19754 /* save the current settings */
19757 \begin_inset LatexCommand \index{\#pragma nogcse}
19766 /* turnoff global subexpression elimination */
19768 #pragma noinduction
19769 \begin_inset LatexCommand \index{\#pragma noinduction}
19773 /* turn off induction optimizations */
19796 \begin_inset LatexCommand \index{\#pragma restore}
19800 /* turn the optimizations back on */
19803 The compiler will generate a warning message when extra space is allocated.
19804 It is strongly recommended that the save and restore pragma's be used when
19805 changing options for a function.
19814 Defines Created by the Compiler
19817 The compiler creates the following #defines
19818 \begin_inset LatexCommand \index{\#defines}
19823 \begin_inset LatexCommand \index{Defines created by the compiler}
19832 \begin_inset Tabular
19833 <lyxtabular version="3" rows="11" columns="2">
19835 <column alignment="left" valignment="top" leftline="true" width="3in">
19836 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
19837 <row topline="true" bottomline="true">
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19859 <row topline="true">
19860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19865 \begin_inset LatexCommand \index{SDCC}
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19878 Since version 2.5.6 the version number as an int (ex.
19884 <row topline="true">
19885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19890 \begin_inset LatexCommand \index{SDCC\_mcs51}
19895 \begin_inset LatexCommand \index{SDCC\_ds390}
19900 \begin_inset LatexCommand \index{SDCC\_z80}
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19912 depending on the model used (e.g.: -mds390)
19917 <row topline="true">
19918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19923 \begin_inset LatexCommand \index{\_\_mcs51}
19928 \begin_inset LatexCommand \index{\_\_ds390}
19933 \begin_inset LatexCommand \index{\_\_hc08}
19938 \begin_inset LatexCommand \index{\_\_z80}
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19950 depending on the model used (e.g.
19956 <row topline="true">
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19962 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19995 <row topline="true">
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20001 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20034 <row topline="true">
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20040 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20073 <row topline="true">
20074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20112 <row topline="true">
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20118 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20151 <row topline="true">
20152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20157 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20178 <row topline="true" bottomline="true">
20179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20184 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20212 Notes on supported Processors
20216 \begin_inset LatexCommand \label{sub:MCS51-variants}
20221 \begin_inset LatexCommand \index{MCS51 variants}
20228 MCS51 processors are available from many vendors and come in many different
20230 While they might differ considerably in respect to Special Function Registers
20231 the core MCS51 is usually not modified or is kept compatible.
20235 pdata access by SFR
20238 With the upcome of devices with internal xdata and flash memory devices
20240 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20244 as dedicated I/O port is becoming more popular.
20245 Switching the high byte for pdata
20246 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20250 access which was formerly done by port P2 is then achieved by a Special
20252 \begin_inset LatexCommand \index{sfr}
20257 In well-established MCS51 tradition the address of this
20261 is where the chip designers decided to put it.
20262 Needless to say that they didn't agree on a common name either.
20263 So that the startup code can correctly initialize xdata variables, you
20264 should define an sfr with the name _XPAGE
20267 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20273 at the appropriate location if the default, port P2, is not used for this.
20279 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
20285 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
20292 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
20298 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20304 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20308 For more exotic implementations further customizations may be needed.
20310 \begin_inset LatexCommand \ref{sub:Startup-Code}
20314 for other possibilities.
20317 Other Features available by SFR
20320 \added_space_bottom bigskip
20321 Some MCS51 variants offer features like Double DPTR
20322 \begin_inset LatexCommand \index{DPTR}
20326 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20327 These are currently not used for the MCS51 port.
20328 If you absolutely need them you can fall back to inline assembly or submit
20337 \added_space_bottom bigskip
20339 \begin_inset LatexCommand \index{DS80C400}
20344 \begin_inset LatexCommand \index{DS400}
20348 microcontroller has a rich set of peripherals.
20349 In its built-in ROM library it includes functions to access some of the
20350 features, among them is a TCP stack with IP4 and IP6 support.
20351 Library headers (currently in beta status) and other files are provided
20355 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20365 The Z80 and gbz80 port
20368 SDCC can target both the Zilog Z80
20369 \begin_inset LatexCommand \index{Z80}
20373 and the Nintendo Gameboy's Z80-like gbz80
20374 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20379 The Z80 port is passed through the same
20382 \begin_inset LatexCommand \index{Regression test}
20389 \begin_inset LatexCommand \ref{sec:Quality-control}
20393 ) as the MCS51 and DS390 ports, so floating point support, support for long
20394 variables and bitfield support is fine.
20395 See mailing lists and forums about interrupt routines.
20398 \added_space_bottom bigskip
20399 As always, the code is the authoritative reference - see z80/ralloc.c and
20402 \begin_inset LatexCommand \index{Z80!stack}
20406 frame is similar to that generated by the IAR Z80 compiler.
20407 IX is used as the base pointer, HL and IY are used as a temporary registers,
20408 and BC and DE are available for holding variables.
20410 \begin_inset LatexCommand \index{Z80!return value}
20414 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20416 The gbz80 port use the same set of registers for the return values, but
20417 in a different order of significance: E (one byte), DE (two bytes), or
20426 The port to the Freescale/Motorola HC08
20427 \begin_inset LatexCommand \index{HC08}
20431 family has been added in October 2003, and is still undergoing some basic
20433 The code generator is complete, but the register allocation is still quite
20435 Some of the SDCC's standard C library functions have embedded non-HC08
20436 inline assembly and so are not yet usable.
20440 \added_space_bottom bigskip
20441 The HC08 port passes the regression test suite (see section
20442 \begin_inset LatexCommand \ref{sec:Quality-control}
20456 \begin_inset LatexCommand \index{PIC14}
20460 port still requires a major effort from the development community.
20461 However it can work for simple code.
20462 It passes its (smaller set of) regression tests
20463 \begin_inset LatexCommand \index{Regression test (PIC14)}
20469 sdcc/src/regression
20474 C code and 14bit PIC code page
20475 \begin_inset LatexCommand \index{code page (pic14)}
20480 \begin_inset LatexCommand \index{RAM bank (pic14)}
20487 The linker organizes allocation for the code page and RAM banks.
20488 It does not have intimate knowledge of the code flow.
20489 It will put all the code section of a single asm file into a single code
20491 In order to make use of multiple code pages, separate asm files must be
20493 The compiler treats all functions of a single C file as being in the same
20494 code page unless it is non static.
20498 To get the best follow these guide lines:
20501 Make local functions static, as non static functions require code page selection
20505 For devices that have multiple code pages it is more efficient to use the
20506 same number of files as pages, i.e.
20507 for the 16F877 use 4 separate files and i.e.
20508 for the 16F874 use 2 separate files.
20509 This way the linker can put the code for each file into different code
20510 pages and there's less page selection overhead.
20513 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20514 instruction set), use 'unsigned char' whereever possible instead of 'int'.
20517 Creating a device include file
20520 For generating a device include file
20521 \begin_inset LatexCommand \index{PIC14!Header files}
20525 use the support perl script inc2h.pl kept in directory support/script.
20531 For the interrupt function, use the keyword '__interrupt'
20532 \begin_inset LatexCommand \index{PIC14!interrupt}
20536 with level number of 0 (PIC14 only has 1 interrupt so this number is only
20537 there to avoid a syntax error - it ought to be fixed).
20543 void Intr(void) __interrupt 0
20549 T0IF = 0; /* Clear timer interrupt */
20554 Linking and assembling
20557 For assembling you can use either GPUTILS'
20558 \begin_inset LatexCommand \index{gputils (pic tools)}
20562 gpasm.exe or MPLAB's mpasmwin.exe.
20563 GPUTILS is available from
20564 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
20569 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
20570 If you use MPLAB and an interrupt function then the linker script file
20571 vectors section will need to be enlarged to link with mplink.
20594 sdcc -S -V -mpic14 -p16F877 $<
20608 $(PRJ).hex: $(OBJS)
20619 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
20641 sdcc -S -V -mpic14 -p16F877 $<
20651 mpasmwin /q /o $*.asm
20655 $(PRJ).hex: $(OBJS)
20666 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
20669 Please note that indentations within a
20673 have to be done with a tabulator character.
20676 Command-line options
20679 Besides the switches common to all SDCC backends, the PIC14 port accepts
20680 the following options (for an updated list see sdcc -
20695 \labelwidthstring 00.00.0000
20709 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
20713 emit debug info in assembly output
20716 \labelwidthstring 00.00.0000
20730 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
20734 disable (slightly faulty) optimization on pCode
20737 \labelwidthstring 00.00.0000
20751 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
20755 sets the lowest address of the argument passing stack (defaults to a suitably
20756 large shared databank to reduce BANKSEL overhead)
20759 \labelwidthstring 00.00.0000
20773 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
20777 sets the size if the argument passing stack (default: 16, minimum: 4)
20782 \layout Subsubsection
20783 error: missing definition for symbol
20784 \begin_inset Quotes sld
20788 \begin_inset Quotes srd
20794 The PIC14 port uses library routines to provide more complex operations
20795 like multiplication, division/modulus and (generic) pointer dereferencing.
20796 In order to add these routines to your project, you must link with PIC14's
20802 For single source file projects this is done automatically, more complex
20807 to the linker's arguments.
20808 Make sure you also add an include path for the library (using the -I switch
20811 \layout Subsubsection
20812 Processor mismatch in file
20813 \begin_inset Quotes sld
20817 \begin_inset Quotes srd
20823 This warning can usually be ignored due to the very good compatibility amongst
20825 \begin_inset LatexCommand \index{PIC14}
20832 You might also consider recompiling the library for your specific device
20833 by changing the ARCH=p16f877 (default target) entry in
20835 device/lib/pic/Makefile.in
20839 device/lib/pic/Makefile
20841 to reflect your device.
20842 This might even improve performance for smaller devices as unneccesary
20843 BANKSELs migth be removed.
20848 \layout Subsubsection
20853 Currently, data can only be initialized if it resides in the source file
20859 Data in other source files will silently
20867 \begin_inset Marginal
20885 \begin_inset LatexCommand \index{PIC16}
20893 \begin_inset LatexCommand \index{PIC16}
20897 port is the portion of SDCC that is responsible to produce code for the
20899 \begin_inset LatexCommand \index{Microchip}
20903 (TM) microcontrollers with 16 bit core.
20904 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20905 Currently supported devices are:
20909 \begin_inset Tabular
20910 <lyxtabular version="3" rows="4" columns="6">
20912 <column alignment="center" valignment="top" leftline="true" width="0">
20913 <column alignment="center" valignment="top" leftline="true" width="0">
20914 <column alignment="center" valignment="top" leftline="true" width="0">
20915 <column alignment="center" valignment="top" leftline="true" width="0">
20916 <column alignment="center" valignment="top" leftline="true" width="0">
20917 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20918 <row topline="true">
20919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20968 <row topline="true">
20969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21018 <row topline="true">
21019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21068 <row topline="true" bottomline="true">
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21128 PIC16 port supports the standard command line arguments as supposed, with
21129 the exception of certain cases that will be mentioned in the following
21133 \labelwidthstring 00.00.0000
21147 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21166 \labelwidthstring 00.00.0000
21180 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21184 All function arguments are passed on stack by default.
21187 There is no need to specify this in the command line.
21190 \labelwidthstring 00.00.0000
21203 -fommit-frame-pointer
21204 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21208 Frame pointer will be omitted when the function uses no local variables.
21211 Port Specific Options
21212 \begin_inset LatexCommand \index{Options PIC16}
21219 The port specific options appear after the global options in the sdcc --help
21222 \layout Subsubsection
21226 General options enable certain port features and optimizations.
21229 \labelwidthstring 00.00.0000
21242 -pstack-model=[model] Used in conjuction with the command above.
21243 Defines the stack model to be used, valid stack models are :
21247 \labelwidthstring 00.00.0000
21252 Selects small stack model.
21253 8 bit stack and frame pointers.
21254 Supports 256 bytes stack size.
21257 \labelwidthstring 00.00.0000
21262 Selects large stack model.
21263 16 bit stack and frame pointers.
21264 Supports 65536 bytes stack size.
21268 \labelwidthstring 00.00.0000
21281 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21282 unitialized data variables with [kword].
21283 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21286 \labelwidthstring 00.00.0000
21299 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21300 Useful for bootloaders.
21303 \labelwidthstring 00.00.0000
21316 -asm= sets the full path and name of an external assembler to call.
21319 \labelwidthstring 00.00.0000
21332 -link= sets the full path and name of an external linker to call.
21335 \labelwidthstring 00.00.0000
21349 \begin_inset LatexCommand \index{PIC16!MPLAB}
21353 compatibility option.
21354 Currently only suppresses special gpasm directives.
21356 \layout Subsubsection
21357 Optimization Options
21360 \labelwidthstring 00.00.0000
21373 -optimize-goto Try to use (conditional) BRA instead of GOTO
21376 \labelwidthstring 00.00.0000
21389 -optimize-cmp Try to optimize some compares.
21392 \labelwidthstring 00.00.0000
21405 -optimize-df Analyze the dataflow of the generated code and improve it.
21408 \labelwidthstring 00.00.0000
21421 -obanksel=nn Set optimization level for inserting BANKSELs.
21427 \labelwidthstring 00.00.0000
21431 \labelwidthstring 00.00.0000
21432 1 checks previous used register and if it is the same then does not emit
21433 BANKSEL, accounts only for labels.
21436 \labelwidthstring 00.00.0000
21437 2 tries to check the location of (even different) symbols and removes BANKSELs
21438 if they are in the same bank.
21443 Important: There might be problems if the linker script has data sections
21444 across bank borders!
21447 \layout Subsubsection
21451 \labelwidthstring 00.00.0000
21464 -nodefaultlibs do not link default libraries when linking
21467 \labelwidthstring 00.00.0000
21480 -no-crt Don't link the default run-time modules
21483 \labelwidthstring 00.00.0000
21496 -use-crt= Use a custom run-time module instead of the defaults.
21498 \layout Subsubsection
21502 Debugging options enable extra debugging information in the output files.
21505 \labelwidthstring 00.00.0000
21518 -debug-xtra Similar to -
21531 \begin_inset LatexCommand \index{-\/-debug}
21535 , but dumps more information.
21538 \labelwidthstring 00.00.0000
21551 -debug-ralloc Force register allocator to dump <source>.d file with debugging
21553 <source> is the name of the file compiled.
21556 \labelwidthstring 00.00.0000
21569 -pcode-verbose Enable pcode debugging information in translation.
21572 \labelwidthstring 00.00.0000
21585 -denable-peeps Force the usage of peepholes.
21589 \labelwidthstring 00.00.0000
21602 -gstack Trace push/pops for stack pointer overflow
21605 \labelwidthstring 00.00.0000
21618 -call-tree dump call tree in .calltree file
21621 Enviromental Variables
21624 There is a number of enviromental variables that can be used when running
21625 SDCC to enable certain optimizations or force a specific program behaviour.
21626 these variables are primarily for debugging purposes so they can be enabled/dis
21630 Currently there is only two such variables available:
21633 \labelwidthstring 00.00.0000
21634 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
21635 bitfields is optimized by directly loading FSR0 with the address of the
21636 bitfield structure.
21637 Normally SDCC will cast the bitfield structure to a bitfield pointer and
21639 This step saves data ram and code space for functions that perform heavy
21642 80 bytes of code space are saved when compiling malloc.c with this option).
21646 \labelwidthstring 00.00.0000
21647 NO_REG_OPT do not perform pCode registers optimization.
21648 This should be used for debugging purposes.
21649 In some where bugs in the pcode optimizer are found, users can benefit
21650 from temporarily disabling the optimizer until the bug is fixed.
21653 Preprocessor Macros
21657 \begin_inset LatexCommand \index{PIC16}
21661 port defines the following preprocessor macros while translating a source.
21665 \begin_inset Tabular
21666 <lyxtabular version="3" rows="6" columns="2">
21668 <column alignment="center" valignment="top" leftline="true" width="0">
21669 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21670 <row topline="true" bottomline="true">
21671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21688 <row topline="true">
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21701 Port identification
21706 <row topline="true">
21707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21731 Port identification (same as above)
21736 <row topline="true">
21737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21749 MCU Identification.
21754 is the microcontrol identification number, i.e.
21760 <row topline="true">
21761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21785 MCU Identification (same as above)
21790 <row topline="true" bottomline="true">
21791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21803 nnn = SMALL or LARGE respectively according to the stack model used
21815 In addition the following macros are defined when calling assembler:
21819 \begin_inset Tabular
21820 <lyxtabular version="3" rows="4" columns="2">
21822 <column alignment="center" valignment="top" leftline="true" width="0">
21823 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21824 <row topline="true" bottomline="true">
21825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21842 <row topline="true">
21843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21855 MCU Identification.
21860 is the microcontrol identification number, i.e.
21866 <row topline="true">
21867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21879 nnn = SMALL or LARGE respectively according to the memory model used for
21885 <row topline="true" bottomline="true">
21886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21898 nnn = SMALL or LARGE respectively according to the stack model used
21914 \begin_inset LatexCommand \index{PIC16}
21918 port uses the following directories for searching header files and libraries.
21922 \begin_inset Tabular
21923 <lyxtabular version="3" rows="3" columns="4">
21925 <column alignment="center" valignment="top" leftline="true" width="0">
21926 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21927 <column alignment="center" valignment="top" width="0">
21928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21929 <row topline="true" bottomline="true">
21930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21963 <row topline="true">
21964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21968 PREFIX/sdcc/include/pic16
21972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21976 PIC16 specific headers
21980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21997 <row topline="true" bottomline="true">
21998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22002 PREFIX/sdcc/lib/pic16
22006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22010 PIC16 specific libraries
22014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22039 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22047 \begin_inset LatexCommand \index{PIC16}
22051 port currently supports the following pragmas:
22054 \labelwidthstring 00.00.0000
22056 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22061 \begin_inset LatexCommand \index{PIC16!stack}
22065 forces the code generator to initialize the stack & frame pointers at a
22067 This is an adhoc solution for cases where no STACK directive is available
22068 in the linker script or gplink is not instructed to create a stack section.
22071 stack pragma should be used only once in a project.
22072 Multiple pragmas may result in indeterminate behaviour of the program.
22077 The old format (ie.
22078 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22079 cross page boundaries (or even exceed the available data RAM) and crash
22081 Make sure that stack does not cross page boundaries when using the SMALL
22088 The format is as follows:
22091 #pragma stack bottom_address [stack_size]
22098 is the lower bound of the stack section.
22099 The stack pointer initially will point at address (bottom_address+stack_size-1).
22108 /* initializes stack of 100 bytes at RAM address 0x200 */
22111 #pragma stack 0x200 100
22114 If the stack_size field is omitted then a stack is created with the default
22116 This size might be enough for most programs, but its not enough for operations
22117 with deep function nesting or excessive stack usage.
22120 \labelwidthstring 00.00.0000
22122 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22126 place a function symbol at static FLASH address
22135 /* place function test_func at 0x4000 */
22138 #pragma code test_func 0x4000
22144 \labelwidthstring 00.00.0000
22145 library instructs the linker to use a library module.
22150 #pragma library module_name
22157 can be any library or object file (including its path).
22158 Note that there are four reserved keywords which have special meaning.
22163 \begin_inset Tabular
22164 <lyxtabular version="3" rows="6" columns="3">
22166 <column alignment="center" valignment="top" leftline="true" width="0">
22167 <column alignment="block" valignment="top" leftline="true" width="20page%">
22168 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22169 <row topline="true" bottomline="true">
22170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22195 <row topline="true">
22196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22210 ignore all library pragmas
22214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22225 <row topline="true">
22226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22257 <row topline="true">
22258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22272 link the Math libarary
22276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22289 <row topline="true">
22290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22304 link the I/O library
22308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22321 <row topline="true" bottomline="true">
22322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22336 link the debug library
22340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22359 * is the device number, i.e.
22360 452 for PIC18F452 MCU.
22363 This feature allows for linking with specific libraries withoug having to
22364 explicit name them in the command line.
22369 keyword will reject all modules specified by the library pragma.
22372 \labelwidthstring 00.00.0000
22373 udata pragma udata instructs the compiler to emit code so that linker will
22374 place a variable at a specific memory bank
22383 /* places variable foo at bank2 */
22386 #pragma udata bank2 foo
22392 In order for this pragma to work extra SECTION directives should be added
22393 in the .lkr script.
22394 In the following example a sample .lkr file is shown:
22400 // Sample linker script for the PIC18F452 processor
22406 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
22409 CODEPAGE NAME=page START=0x2A END=0x7FFF
22412 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
22415 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
22418 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
22421 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
22424 ACCESSBANK NAME=accessram START=0x0 END=0x7F
22430 DATABANK NAME=gpr0 START=0x80 END=0xFF
22433 DATABANK NAME=gpr1 START=0x100 END=0x1FF
22436 DATABANK NAME=gpr2 START=0x200 END=0x2FF
22439 DATABANK NAME=gpr3 START=0x300 END=0x3FF
22442 DATABANK NAME=gpr4 START=0x400 END=0x4FF
22445 DATABANK NAME=gpr5 START=0x500 END=0x5FF
22448 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
22454 SECTION NAME=CONFIG ROM=config
22460 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
22463 SECTION NAME=bank1 RAM=gpr1 # should be added to link
22466 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
22469 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
22472 SECTION NAME=bank4 RAM=gpr4
22475 SECTION NAME=bank5 RAM=gpr5
22478 The linker will recognise the section name set in the pragma statement and
22479 will position the variable at the memory bank set with the RAM field at
22480 the SECTION line in the linker script file.
22484 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
22491 There is one main header file
22492 \begin_inset LatexCommand \index{PIC16!Header files}
22496 that can be included to the source files using the pic16
22497 \begin_inset LatexCommand \index{PIC16}
22507 This header file contains the definitions for the processor special registers,
22508 so it is necessary if the source accesses them.
22509 It can be included by adding the following line in the beginning of the
22513 #include <pic18fregs.h>
22516 The specific microcontroller is selected within the pic18fregs.h automatically,
22517 so the same source can be used with a variety of devices.
22524 \begin_inset LatexCommand \index{PIC16!Libraries}
22529 \begin_inset LatexCommand \index{PIC16}
22533 port depends on are the microcontroller device libraries which contain
22534 the symbol definitions for the microcontroller special function registers.
22535 These libraries have the format pic18fxxxx.lib, where
22539 is the microcontroller identification number.
22540 The specific library is selected automatically by the compiler at link
22541 stage according to the selected device.
22544 Libraries are created with gplib which is part of the gputils package
22545 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22551 \layout Subsubsection*
22552 Building the libraries
22555 Before using SDCC/pic16 there are some libraries that need to be compiled.
22556 This process is not done automatically by SDCC since not all users use
22557 SDCC for pic16 projects.
22558 So each user should compile the libraries separately.
22561 The steps to compile the pic16 libraries under Linux are:
22564 cd device/lib/pic16
22579 su -c 'make install' # install the libraries, you need the root password
22582 If you need to install the headers too, do:
22588 su -c 'make install' # install the headers, you need the root password
22591 There exist a special target to build the I/O libraries.
22592 This target is not automatically build because it will build the I/O library
22598 This way building will take quite a lot of time.
22599 Users are advised to edit the
22601 device/lib/pic16/pics.build
22603 file and then execute:
22612 The following memory models are supported by the PIC16 port:
22621 Memory model affects the default size of pointers within the source.
22622 The sizes are shown in the next table:
22626 \begin_inset Tabular
22627 <lyxtabular version="3" rows="3" columns="3">
22629 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22630 <column alignment="center" valignment="top" leftline="true" width="0">
22631 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22632 <row topline="true" bottomline="true">
22633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22637 Pointer sizes according to memory model
22641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22658 <row topline="true" bottomline="true">
22659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22667 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22684 <row topline="true" bottomline="true">
22685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22693 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
22701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22717 It is advisable that all sources within a project are compiled with the
22719 If one wants to override the default memory model, this can be done by
22720 declaring a pointer as
22729 Far selects large memory model's pointers, while near selects small memory
22733 The standard device libraries (see
22734 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
22738 ) contain no reference to pointers, so they can be used with both memory
22746 \begin_inset LatexCommand \index{PIC16!stack}
22750 implementation for the PIC16 port uses two indirect registers, FSR1 and
22754 \labelwidthstring 00.00.0000
22755 FSR1 is assigned as stack pointer
22758 \labelwidthstring 00.00.0000
22759 FSR2 is assigned as frame pointer
22762 The following stack models are supported by the PIC16 port
22783 model means that only the FSRxL byte is used to access stack and frame,
22790 uses both FSRxL and FSRxH registers.
22791 The following table shows the stack/frame pointers sizes according to stack
22792 model and the maximum space they can address:
22796 \begin_inset Tabular
22797 <lyxtabular version="3" rows="3" columns="3">
22799 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22800 <column alignment="center" valignment="top" leftline="true" width="0">
22801 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22802 <row topline="true" bottomline="true">
22803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22807 Stack & Frame pointer sizes according to stack model
22811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22828 <row topline="true">
22829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22854 <row topline="true" bottomline="true">
22855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22891 stack model is currently not working properly throughout the code generator.
22892 So its use is not advised.
22893 Also there are some other points that need special care:
22898 Do not create stack sections with size more than one physical bank (that
22902 Stack sections should no cross physical bank limits (i.e.
22903 #pragma stack 0x50 0x100)
22906 These limitations are caused by the fact that only FSRxL is modified when
22907 using SMALL stack model, so no more than 256 bytes of stack can be used.
22908 This problem will disappear after LARGE model is fully implemented.
22914 In addition to the standard SDCC function keywords, PIC16
22915 \begin_inset LatexCommand \index{PIC16}
22919 port makes available two more:
22922 \labelwidthstring 00.00.0000
22924 \begin_inset LatexCommand \index{PIC16!wparam}
22928 Use the WREG to pass one byte of the first function argument.
22929 This improves speed but you may not use this for functions with arguments
22930 that are called via function pointers, otherwise the first byte of the
22931 first parameter will get lost.
22935 void func_wparam(int a) wparam
22941 /* WREG hold the lower part of a */
22944 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22954 \labelwidthstring 00.00.0000
22956 \begin_inset LatexCommand \index{PIC16!shadowregs}
22960 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22961 hardware shadow registers which hold the values of WREG, STATUS and BSR
22963 This can be done by adding the keyword
22971 keyword in the function's header.
22974 void isr_shadow(void) shadowregs interrupt 1
22990 instructs the code generator not to store/restore WREG, STATUS, BSR when
22991 entering/exiting the ISR.
22994 Function return values
22997 Return values from functions are placed to the appropriate registers following
22998 a modified Microchip policy optimized for SDCC.
22999 The following table shows these registers:
23003 \begin_inset Tabular
23004 <lyxtabular version="3" rows="6" columns="2">
23006 <column alignment="center" valignment="top" leftline="true" width="0">
23007 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23008 <row topline="true" bottomline="true">
23009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23021 destination register
23026 <row topline="true">
23027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23044 <row topline="true">
23045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23062 <row topline="true">
23063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23080 <row topline="true">
23081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23093 FSR0L:PRODH:PRODL:WREG
23098 <row topline="true" bottomline="true">
23099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23111 on stack, FSR0 points to the beginning
23127 \begin_inset LatexCommand \index{PIC16!interrupt}
23131 service routine (ISR) is declared using the
23138 void isr(void) interrupt
23156 is the interrupt number, which for PIC18F devices can be:
23160 \begin_inset Tabular
23161 <lyxtabular version="3" rows="4" columns="3">
23163 <column alignment="center" valignment="top" leftline="true" width="0">
23164 <column alignment="center" valignment="top" leftline="true" width="0">
23165 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23166 <row topline="true" bottomline="true">
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23189 Interrupt Vector Address
23194 <row topline="true">
23195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23220 <row topline="true">
23221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23251 HIGH priority interrupts
23255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23264 <row topline="true" bottomline="true">
23265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23277 LOW priority interrupts
23281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23297 When generating assembly code for ISR the code generator places a
23303 Interrupt Vector Address
23305 which points at the genetated ISR.
23306 This single GOTO instruction is part of an automatically generated
23308 interrupt entry point
23311 The actuall ISR code is placed as normally would in the code space.
23312 Upon interrupt request, the GOTO instruction is executed which jumps to
23314 When declaring interrupt functions as _naked this GOTO instruction is
23319 The whole interrupt functions is therefore placed at the Interrupt Vector
23320 Address of the specific interrupt.
23321 This is not a problem for the LOW priority interrupts, but it is a problem
23322 for the RESET and the HIGH priority interrupts because code may be written
23323 at the next interrupt´s vector address and cause undeterminate program
23324 behaviour if that interrupt is raised.
23329 This is not a problem when
23332 this is a HIGH interrupt ISR and LOW interrupts are
23339 when the ISR is small enough not to reach the next interrupt´s vector address.
23350 is possible to be omitted.
23351 This way a function is generated similar to an ISR, but it is not assigned
23355 When entering an interrupt, currently the PIC16
23356 \begin_inset LatexCommand \index{PIC16}
23360 port automatically saves the following registers:
23372 PROD (PRODL and PRODH)
23375 FSR0 (FSR0L and FSR0H)
23378 These registers are restored upon return from the interrupt routine.
23383 NOTE that when the _naked attribute is specified for an interrupt routine,
23384 then NO registers are stored or restored.
23394 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
23395 There are 3 types of generic pointers currently implemented data, code
23396 and eeprom pointers.
23397 They are differentiated by the value of the 7th and 6th bits of the upper
23402 \begin_inset Tabular
23403 <lyxtabular version="3" rows="5" columns="5">
23405 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23406 <column alignment="center" valignment="top" width="0">
23407 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23408 <column alignment="center" valignment="top" width="0">
23409 <column alignment="left" valignment="top" rightline="true" width="0">
23410 <row topline="true" bottomline="true">
23411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23439 rest of the pointer
23443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23452 <row topline="true" bottomline="true">
23453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23485 uuuuuu uuuuxxxx xxxxxxxx
23489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23493 a 12-bit data pointer in data RAM memory
23498 <row bottomline="true">
23499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23531 uxxxxx xxxxxxxx xxxxxxxx
23535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23539 a 21-bit code pointer in FLASH memory
23544 <row bottomline="true">
23545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23577 uuuuuu uuuuuuxx xxxxxxxx
23581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23585 a 10-bit eeprom pointer in EEPROM memory
23590 <row bottomline="true">
23591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23623 xxxxxx xxxxxxxx xxxxxxxx
23627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23631 unimplemented pointer type
23643 Generic pointer are read and written with a set of library functions which
23644 read/write 1, 2, 3, 4 bytes.
23649 \layout Subsubsection
23650 Standard I/O Streams
23657 the type FILE is defined as:
23660 typedef char * FILE;
23663 This type is the stream type implemented I/O in the PIC18F devices.
23664 Also the standard input and output streams are declared in stdio.h:
23667 extern FILE * stdin;
23670 extern FILE * stdout;
23673 The FILE type is actually a generic pointer which defines one more type
23674 of generic pointers, the
23679 This new type has the format:
23683 \begin_inset Tabular
23684 <lyxtabular version="3" rows="2" columns="7">
23686 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23687 <column alignment="center" valignment="top" width="0">
23688 <column alignment="center" valignment="top" leftline="true" width="0">
23689 <column alignment="center" valignment="top" leftline="true" width="0">
23690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23691 <column alignment="center" valignment="top" width="0">
23692 <column alignment="left" valignment="top" rightline="true" width="0">
23693 <row topline="true" bottomline="true">
23694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23738 rest of the pointer
23742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23751 <row topline="true" bottomline="true">
23752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23808 upper byte high nubble is 0x2n, the rest are zeroes
23820 Currently implemented there are 3 types of streams defined:
23824 \begin_inset Tabular
23825 <lyxtabular version="3" rows="4" columns="4">
23827 <column alignment="center" valignment="top" leftline="true" width="0">
23828 <column alignment="center" valignment="top" leftline="true" width="0">
23829 <column alignment="center" valignment="top" leftline="true" width="0">
23830 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23831 <row topline="true" bottomline="true">
23832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23865 <row topline="true">
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23896 Writes/Reads characters via the USART peripheral
23901 <row topline="true">
23902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23932 Writes/Reads characters via the MSSP peripheral
23937 <row topline="true" bottomline="true">
23938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23968 Writes/Reads characters via used defined functions
23980 The stream identifiers are declared as macros in the stdio.h header.
23983 In the libc library there exist the functions that are used to write to
23984 each of the above streams.
23988 \labelwidthstring 00.00.0000
24001 _stream_usart_putchar writes a character at the USART stream
24004 \labelwidthstring 00.00.0000
24017 _stream_mssp_putchar writes a character at the MSSP stream
24020 \labelwidthstring 00.00.0000
24021 putchar dummy function.
24022 This writes a character to a user specified manner.
24025 In order to increase performance
24029 is declared in stdio.h as having its parameter in WREG (it has the wparam
24031 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24032 in a user-friendly way.
24037 is the name of the variable that holds the character to print.
24038 An example follows:
24041 #include <pic18fregs.h>
24053 PORTA = c; /* dump character c to PORTA */
24066 stdout = STREAM_USER; /* this is not necessary, since stdout points
24069 * by default to STREAM_USER */
24072 printf (¨This is a printf test
24082 \layout Subsubsection
24086 PIC16 contains an implementation of the printf-family of functions.
24087 There exist the following functions:
24090 extern unsigned int sprintf(char *buf, char *fmt, ...);
24093 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
24099 extern unsigned int printf(char *fmt, ...);
24102 extern unsigned int vprintf(char *fmt, va_lista ap);
24108 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
24111 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
24114 For sprintf and vsprintf
24118 should normally be a data pointer where the resulting string will be placed.
24119 No range checking is done so the user should allocate the necessery buffer.
24120 For fprintf and vfprintf
24124 should be a stream pointer (i.e.
24125 stdout, STREAM_MSSP, etc...).
24127 \layout Subsubsection
24131 The PIC18F family of microcontrollers supports a number of interrupt sources.
24132 A list of these interrupts is shown in the following table:
24136 \begin_inset Tabular
24137 <lyxtabular version="3" rows="11" columns="4">
24139 <column alignment="left" valignment="top" leftline="true" width="0">
24140 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24141 <column alignment="left" valignment="top" leftline="true" width="0">
24142 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24143 <row topline="true" bottomline="true">
24144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24177 <row topline="true">
24178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24186 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24190 PORTB change interrupt
24194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24206 EEPROM/FLASH write complete interrupt
24211 <row topline="true">
24212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24224 INT0 external interrupt
24228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24240 Bus collision interrupt
24245 <row topline="true">
24246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24258 INT1 external interrupt
24262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24274 Low voltage detect interrupt
24279 <row topline="true">
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24292 INT2 external interrupt
24296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24308 Parallel slave port interrupt
24313 <row topline="true">
24314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24326 CCP1 module interrupt
24330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24342 AD convertion complete interrupt
24347 <row topline="true">
24348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24360 CCP2 module interrupt
24364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24376 USART receive interrupt
24381 <row topline="true">
24382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24394 TMR0 overflow interrupt
24398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24410 USART transmit interrupt
24415 <row topline="true">
24416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24428 TMR1 overflow interrupt
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24444 SSP receive/transmit interrupt
24449 <row topline="true">
24450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24462 TMR2 matches PR2 interrupt
24466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24483 <row topline="true" bottomline="true">
24484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24496 TMR3 overflow interrupt
24500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24524 The prototypes for these names are defined in the header file
24531 In order to simplify signal handling, a number of macros is provided:
24534 \labelwidthstring 00.00.0000
24535 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
24536 high priority interrupts.
24541 is the function name to use.
24544 \labelwidthstring 00.00.0000
24545 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
24546 low priority interrupt.
24551 is the function name to use.
24554 \labelwidthstring 00.00.0000
24555 DEF_HANDLER(sig,handler) define a handler for signal
24560 \labelwidthstring 00.00.0000
24561 END_DEF end the declaration of the dispatch table.
24564 Additionally there are two more macros to simplify the declaration of the
24568 \labelwidthstring 00.00.0000
24571 SIGHANDLER(handler)
24573 this declares the function prototype for the
24580 \labelwidthstring 00.00.0000
24581 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
24584 An example of using the macros above is shown below:
24587 #include <pic18fregs.h>
24590 #include <signal.h>
24594 DEF_INTHIGH(high_int)
24597 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
24600 DEF_HANDLER(SIG_BCOL, _bcol_handler)
24607 SIGHANDLER(_tmr0_handler)
24613 /* action to be taken when timer 0 overflows */
24620 SIGHANDLERNAKED(_bcol_handler)
24629 /* action to be taken when bus collision occurs */
24645 Special care should be taken when using the above scheme:
24648 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
24651 when declaring SIGHANDLERNAKED handler never forget to use
24655 for proper returning.
24661 Here you can find some general tips for compiling programs with SDCC/pic16.
24663 \layout Subsubsection
24668 \begin_inset LatexCommand \index{PIC16!stack}
24672 size (that is 64 bytes) probably is enough for many programs.
24673 One must take care that when there are many levels of function nesting,
24674 or there is excessive usage of stack, its size should be extended.
24675 An example of such a case is the printf/sprintf family of functions.
24676 If you encounter problems like not being able to print integers, then you
24677 need to set the stack size around the maximum (256 for small stack model).
24678 The following diagram shows what happens when calling printf to print an
24682 printf () --> ltoa () --> ultoa () --> divschar ()
24685 It is should be understood that stack is easily consumed when calling complicate
24687 Using command line arguments like -
24699 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
24701 Other ways to reduce stack usage may exist.
24707 The PIC16 Port currently does not pass SDCC's regression test
24708 \begin_inset LatexCommand \index{Regression test (PIC16)}
24713 \begin_inset LatexCommand \ref{sec:Quality-control}
24717 ) and thus the snapshot build regression tests for the PIC16 target are
24718 currently disabled for all hosts
24726 There are several approaches to debugging your code.
24727 This chapter is meant to show your options and to give detail on some of
24732 When writing your code:
24735 write your code with debugging in mind (avoid duplicating code, put conceptually
24736 similar variables into structs, use structured code, have strategic points
24737 within your code where all variables are consistent, ...)
24740 run a syntax-checking tool like splint
24741 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24746 \begin_inset LatexCommand \index{lint (syntax checking tool)}
24763 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24770 for the high level code use a C-compiler (like f.e.
24771 GCC) to compile run and debug the code on your host.
24785 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24789 ) on howto handle syntax extensions like __xdata, __at(), ...
24793 use another C-compiler to compile code for your target.
24794 Always an option but not recommended:) And not very likely to help you.
24795 If you seriously consider walking this path you should at least occasionally
24796 check portability of your code.
24797 Most commercial compiler vendors will offer an evaluation version so you
24798 can test compile your code or snippets of your code.
24801 Debugging on a simulator:
24804 there is a separate section about SDCDB (section
24805 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
24812 or (8051 specific) use a freeware/commercial simulator which interfaces
24814 \begin_inset LatexCommand \index{AOMF, AOMF51}
24819 \begin_inset LatexCommand \ref{OMF file}
24823 ) optionally generated by SDCC.
24826 Debugging On-target:
24829 use a MCU port pin to serially output debug data to the RS232 port of your
24831 You'll probably want some level shifting device typically involving a MAX232
24833 If the hardware serial port of the MCU is not available search for 'Software
24834 UART' in your favourite search machine.
24837 use an on-target monitor.
24838 In this context a monitor is a small program which usually accepts commands
24839 via a serial line and allows to set program counter, to single step through
24840 a program and read/write memory locations.
24841 For the 8051 good examples of monitors are paulmon and cmon51 (see section
24843 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
24850 toggle MCU port pins at strategic points within your code and use an oscilloscop
24854 digital oscilloscope
24857 \begin_inset LatexCommand \index{Oscilloscope}
24861 with deep trace memory is really helpful especially if you have to debug
24862 a realtime application.
24863 If you need to monitor more pins than your oscilloscope provides you can
24864 sometimes get away with a small R-2R network.
24865 On a single channel oscilloscope you could f.e.
24866 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24868 \begin_inset Formula $\Omega$
24871 resistor and the other one by a 5\SpecialChar ~
24873 \begin_inset Formula $\Omega$
24876 resistor to the oscilloscope probe (check output drive capability of the
24877 pins you want to monitor).
24878 If you need to monitor many more pins a
24898 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24903 Usually very expensive.
24904 And very nice to have too.
24905 And usually locks you (for years...) to the devices the ICE can emulate.
24909 use a remote debugger.
24910 In most 8-bit systems the symbol information is not available on the target,
24911 and a complete debugger is too bulky for the target system.
24912 Therefore usually a debugger on the host system connects to an on-target
24913 debugging stub which accepts only primitive commands.
24916 Terms to enter into your favourite search engine could be 'remote debugging',
24917 'gdb stub' or 'inferior debugger'.
24921 use an on target hardware debugger.
24922 Some of the more modern MCUs include hardware support for setting break
24923 points and monitoring/changing variables by using dedicated hardware pins.
24924 This facility doesn't require additional code to run on the target and
24929 doesn't affect runtime behaviour until a breakpoint is hit.
24930 For the mcs51 most hardware debuggers use the AOMF
24931 \begin_inset LatexCommand \index{AOMF, AOMF51}
24936 \begin_inset LatexCommand \ref{OMF file}
24947 if you are not familiar with any of the following terms you're likely to
24948 run into problems rather sooner than later:
24965 As an embedded programmer you
24969 to know them so why not look them up
24973 you have problems?)
24976 tell someone else about your problem (actually this is a surprisingly effective
24977 means to hunt down the bug even if the listener is not familiar with your
24979 As 'failure to communicate' is probably one of the job-induced deformations
24980 of an embedded programmer this is highly encouraged.
24983 Debugging with SDCDB
24984 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24989 \begin_inset LatexCommand \index{SDCDB (debugger)}
24996 SDCC is distributed with a source level debugger
24997 \begin_inset LatexCommand \index{Debugger}
25002 The debugger uses a command line interface, the command repertoire of the
25003 debugger has been kept as close to gdb
25004 \begin_inset LatexCommand \index{gdb}
25008 (the GNU debugger) as possible.
25009 The configuration and build process is part of the standard compiler installati
25010 on, which also builds and installs the debugger in the target directory
25011 specified during configuration.
25012 The debugger allows you debug BOTH at the C source and at the ASM source
25016 Compiling for Debugging
25032 \begin_inset LatexCommand \index{-\/-debug}
25036 option must be specified for all files for which debug information is to
25038 The compiler generates a .adb file for each of these files.
25039 The linker creates the .cdb
25040 \begin_inset LatexCommand \index{<file>.cdb}
25045 \begin_inset LatexCommand \index{<file>.adb}
25049 files and the address information.
25050 This .cdb is used by the debugger.
25053 How the Debugger Works
25068 -debug option is specified the compiler generates extra symbol information
25069 some of which are put into the assembler source and some are put into the
25071 Then the linker creates the .cdb file from the individual .adb files with
25072 the address information for the symbols.
25073 The debugger reads the symbolic information generated by the compiler &
25074 the address information generated by the linker.
25075 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
25076 execution is controlled by the debugger.
25077 When a command is issued for the debugger, it translates it into appropriate
25078 commands for the simulator.
25079 (Currently SDCDM only connects to the simulator but
25084 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
25088 is an effort to connect directly to the hardware.)
25091 Starting the Debugger SDCDB
25094 The debugger can be started using the following command line.
25095 (Assume the file you are debugging has the file name foo).
25109 The debugger will look for the following files.
25112 foo.c - the source file.
25115 foo.cdb - the debugger symbol information file.
25118 foo.ihx - the Intel hex format
25119 \begin_inset LatexCommand \index{Intel hex format}
25126 SDCDB Command Line Options
25141 -directory=<source file directory> this option can used to specify the directory
25143 The debugger will look into the directory list specified for source, cdb
25145 The items in the directory list must be separated by ':', e.g.
25146 if the source files can be in the directories /home/src1 and /home/src2,
25159 -directory option should be -
25171 -directory=/home/src1:/home/src2.
25172 Note there can be no spaces in the option.
25176 -cd <directory> - change to the <directory>.
25179 -fullname - used by GUI front ends.
25182 -cpu <cpu-type> - this argument is passed to the simulator please see the
25183 simulator docs for details.
25186 -X <Clock frequency > this options is passed to the simulator please see
25187 the simulator docs for details.
25190 -s <serial port file> passed to simulator see the simulator docs for details.
25193 -S <serial in,out> passed to simulator see the simulator docs for details.
25196 -k <port number> passed to simulator see the simulator docs for details.
25199 SDCDB Debugger Commands
25202 As mentioned earlier the command interface for the debugger has been deliberatel
25203 y kept as close the GNU debugger gdb, as possible.
25204 This will help the integration with existing graphical user interfaces
25205 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
25206 If you use a graphical user interface for the debugger you can skip this
25209 \layout Subsubsection*
25210 break [line | file:line | function | file:function]
25213 Set breakpoint at specified line or function:
25222 sdcdb>break foo.c:100
25224 sdcdb>break funcfoo
25226 sdcdb>break foo.c:funcfoo
25228 \layout Subsubsection*
25229 clear [line | file:line | function | file:function ]
25232 Clear breakpoint at specified line or function:
25241 sdcdb>clear foo.c:100
25243 sdcdb>clear funcfoo
25245 sdcdb>clear foo.c:funcfoo
25247 \layout Subsubsection*
25251 Continue program being debugged, after breakpoint.
25253 \layout Subsubsection*
25257 Execute till the end of the current function.
25259 \layout Subsubsection*
25263 Delete breakpoint number 'n'.
25264 If used without any option clear ALL user defined break points.
25266 \layout Subsubsection*
25267 info [break | stack | frame | registers ]
25270 info break - list all breakpoints
25273 info stack - show the function call stack.
25276 info frame - show information about the current execution frame.
25279 info registers - show content of all registers.
25281 \layout Subsubsection*
25285 Step program until it reaches a different source line.
25286 Note: pressing <return> repeats the last command.
25288 \layout Subsubsection*
25292 Step program, proceeding through subroutine calls.
25294 \layout Subsubsection*
25298 Start debugged program.
25300 \layout Subsubsection*
25304 Print type information of the variable.
25306 \layout Subsubsection*
25310 print value of variable.
25312 \layout Subsubsection*
25316 load the given file name.
25317 Note this is an alternate method of loading file for debugging.
25319 \layout Subsubsection*
25323 print information about current frame.
25325 \layout Subsubsection*
25329 Toggle between C source & assembly source.
25331 \layout Subsubsection*
25332 ! simulator command
25335 Send the string following '!' to the simulator, the simulator response is
25337 Note the debugger does not interpret the command being sent to the simulator,
25338 so if a command like 'go' is sent the debugger can loose its execution
25339 context and may display incorrect values.
25341 \layout Subsubsection*
25347 My name is Bobby Brown"
25350 Interfacing SDCDB with DDD
25357 The screenshot was converted from png to eps with:
25358 \begin_inset Quotes sld
25361 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
25362 \begin_inset Quotes srd
25365 which produces a pretty compact eps file which is free from compression
25369 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
25370 as this broke the build system on Sourceforge (pdf-file was broken.
25371 pdflatex does not accept eps files).
25393 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
25399 shows a screenshot of a debugging session with DDD
25400 \begin_inset LatexCommand \index{DDD (debugger)}
25404 (Unix only) on a simulated 8032.
25405 The debugging session might not run as smoothly as the screenshot suggests.
25406 The debugger allows setting of breakpoints, displaying and changing variables,
25407 single stepping through C and assembler code.
25410 The source was compiled with
25435 -debug ddd_example.c
25448 and DDD was invoked with
25455 ddd -debugger "sdcdb -cpu 8032 ddd_example"
25462 Check that the double quotes or an apostroph within the command line survive
25463 the LyX tool chain.
25464 Previously the apostrophs got slanted in the PDF output so a cut and paste
25472 Interfacing SDCDB with XEmacs
25473 \begin_inset LatexCommand \index{XEmacs}
25478 \begin_inset LatexCommand \index{Emacs}
25485 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
25486 sdcdb.el and sdcdbsrc.el.
25487 These two files can be found in the $(prefix)/bin directory after the installat
25489 These files need to be loaded into XEmacs for the interface to work.
25490 This can be done at XEmacs startup time by inserting the following into
25491 your '.xemacs' file (which can be found in your HOME directory):
25497 (load-file sdcdbsrc.el)
25503 .xemacs is a lisp file so the () around the command is REQUIRED.
25504 The files can also be loaded dynamically while XEmacs is running, set the
25505 environment variable 'EMACSLOADPATH' to the installation bin directory
25506 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
25507 To start the interface enter the following command:
25521 You will prompted to enter the file name to be debugged.
25526 The command line options that are passed to the simulator directly are
25527 bound to default values in the file sdcdbsrc.el.
25528 The variables are listed below, these values maybe changed as required.
25531 sdcdbsrc-cpu-type '51
25534 sdcdbsrc-frequency '11059200
25537 sdcdbsrc-serial nil
25540 The following is a list of key mapping for the debugger interface.
25552 ;;key\SpecialChar ~
25566 binding\SpecialChar ~
25590 ;;---\SpecialChar ~
25604 -------\SpecialChar ~
25647 m-src\SpecialChar ~
25675 sdcdb-back-from-src\SpecialChar ~
25704 rom-src\SpecialChar ~
25714 SDCDB continue command
25732 sdcdb-step-from-src\SpecialChar ~
25761 hatis-c-sexp\SpecialChar ~
25771 SDCDB ptypecommand for data at
25838 sdcdbsrc-delete\SpecialChar ~
25853 B Delete all breakpoints if no arg
25902 given or delete arg (C-u arg x)
25921 -frame\SpecialChar ~
25936 SDCDB Display current frame if no arg,
25985 given or display frame arg
26053 sdcdbsrc-goto-sdcdb\SpecialChar ~
26063 Goto the SDCDB output buffer
26082 t-c-sexp\SpecialChar ~
26093 SDCDB print command for data at
26160 sdcdbsrc-goto-sdcdb\SpecialChar ~
26171 o the SDCDB output buffer
26189 sdcdbsrc-mode\SpecialChar ~
26205 Toggles Sdcdbsrc mode (turns it
26221 sdcdb-finish-from-src\SpecialChar ~
26229 SDCDB finish command
26263 Set break for line with point
26278 sdcdbsrc-mode\SpecialChar ~
26294 Toggle Sdcdbsrc mode
26310 dbsrc-srcmode\SpecialChar ~
26336 Here are a few guidelines that will help the compiler generate more efficient
26337 code, some of the tips are specific to this compiler others are generally
26338 good programming practice.
26341 Use the smallest data type to represent your data-value.
26342 If it is known in advance that the value is going to be less than 256 then
26343 use an 'unsigned char' instead of a 'short' or 'int'.
26344 Please note, that ANSI C requires both signed and unsigned chars to be
26345 promoted to 'signed int'
26346 \begin_inset LatexCommand \index{promotion to signed int}
26351 \begin_inset Marginal
26362 before doing any operation.
26364 \begin_inset LatexCommand \index{type promotion}
26369 \begin_inset LatexCommand \label{type promotion}
26373 can be omitted, if the result is the same.
26374 The effect of the promotion rules together with the sign-extension is often
26381 unsigned char uc = 0xfe;
26383 if (uc * uc < 0) /* this is true! */
26402 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
26412 (unsigned char) -12 / (signed char) -3 = ...
26415 No, the result is not 4:
26420 (int) (unsigned char) -12 / (int) (signed char) -3 =
26422 (int) (unsigned char)
26423 0xf4 / (int) (signed char) 0xfd =
26425 (int) 0x00f4 / (int) 0xfffd =
26430 (int) 244 / (int) -3 =
26432 (int) -81 = (int) 0xffaf;
26435 Don't complain, that gcc gives you a different result.
26436 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
26437 Therefore the results are different.
26440 \begin_inset Quotes sld
26444 \begin_inset Quotes srd
26452 If well-defined overflow characteristics are important and negative values
26453 are not, or if you want to steer clear of sign-extension problems when
26454 manipulating bits or bytes, use one of the corresponding unsigned types.
26455 (Beware when mixing signed and unsigned values in expressions, though.)
26458 character types (especially unsigned char) can be used as "tiny" integers,
26459 doing so is sometimes more trouble than it's worth, due to unpredictable
26460 sign extension and increased code size.
26464 Use unsigned when it is known in advance that the value is not going to
26466 This helps especially if you are doing division or multiplication, bit-shifting
26467 or are using an array index.
26470 NEVER jump into a LOOP.
26473 Declare the variables to be local
26474 \begin_inset LatexCommand \index{local variables}
26478 whenever possible, especially loop control variables (induction).
26481 Have a look at the assembly listing to get a
26482 \begin_inset Quotes sld
26486 \begin_inset Quotes srd
26489 for the code generation.
26492 Porting code from or to other compilers
26493 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
26500 check whether endianness of the compilers differs and adapt where needed.
26503 check the device specific header files
26504 \begin_inset LatexCommand \index{Header files}
26509 \begin_inset LatexCommand \index{Include files}
26513 for compiler specific syntax.
26514 Eventually include the file <compiler.h
26515 \begin_inset LatexCommand \index{compiler.h (include file)}
26520 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
26524 to allow using common header files.
26527 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
26534 check whether the startup code contains the correct initialization (watchdog,
26538 check whether the sizes of short, int, long match.
26541 check if some 16 or 32 bit hardware registers require a specific addressing
26542 order (least significant or most significant byte first) and adapt if needed
26551 relate to time and not to lower/upper memory location here, so this is
26556 the same as endianness).
26559 check whether the keyword
26563 is used where needed.
26564 The compilers might differ in their optimization characteristics (as different
26565 versions of the same compiler might also use more clever optimizations
26566 this is good idea anyway).
26568 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
26575 check that the compilers are not told to supress warnings.
26578 check and convert compiler specific extensions (interrupts, memory areas,
26582 check for differences in type promotion.
26583 Especially check for math operations on
26592 For the sake of C99 compatibility SDCC will probably promote these to
26596 more often than other compilers.
26597 Eventually insert explicit casts to
26606 Also check that the ~\SpecialChar ~
26608 \begin_inset LatexCommand \index{\~\/ Operator}
26615 \begin_inset LatexCommand \index{bit}
26621 variables, use the !\SpecialChar ~
26624 \begin_inset LatexCommand \ref{type promotion}
26629 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26636 check the assembly code generated for interrupt routines (f.e.
26637 for calls to possibly non-reentrant library functions).
26640 check whether timing loops result in proper timing (or preferably consider
26641 a rewrite of the code with timer based delays instead).
26644 check for differences in printf parameters (some compilers push (va_arg
26645 \begin_inset LatexCommand \index{vararg, va\_arg}
26649 ) char variables as
26653 others push them as
26659 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26666 check the resulting memory map
26667 \begin_inset LatexCommand \index{Memory map}
26672 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
26673 ly idata, pdata, xdata).
26674 Eventually check if unexpected library functions are included.
26678 \begin_inset LatexCommand \index{Tools}
26682 included in the distribution
26686 \begin_inset Tabular
26687 <lyxtabular version="3" rows="12" columns="3">
26689 <column alignment="left" valignment="top" leftline="true" width="0pt">
26690 <column alignment="left" valignment="top" leftline="true" width="0pt">
26691 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26692 <row topline="true" bottomline="true">
26693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26724 <row topline="true">
26725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26730 \begin_inset LatexCommand \index{uCsim}
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26742 Simulator for various architectures
26746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26755 <row topline="true">
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26769 \begin_inset LatexCommand \index{Header files}
26774 \begin_inset LatexCommand \index{Include files}
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26786 sdcc/support/scripts
26791 <row topline="true">
26792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26804 header file conversion
26808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26812 sdcc/support/scripts
26817 <row topline="true">
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26852 <row topline="true">
26853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26887 <row topline="true">
26888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26922 <row topline="true">
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26957 <row topline="true">
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26992 <row topline="true">
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27027 <row topline="true">
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27062 <row topline="true" bottomline="true">
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27076 \begin_inset LatexCommand \index{packihx (tool)}
27084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27112 \begin_inset LatexCommand \index{Documentation}
27116 included in the distribution
27120 \begin_inset Tabular
27121 <lyxtabular version="3" rows="10" columns="2">
27123 <column alignment="block" valignment="top" leftline="true" width="40col%">
27124 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
27125 <row topline="true" bottomline="true" endhead="true">
27126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27142 Filename / Where to get
27147 <row topline="true">
27148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27152 SDCC Compiler User Guide
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27160 You're reading it right now
27172 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
27181 <row topline="true">
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27206 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
27215 <row topline="true">
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27221 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
27226 \begin_inset LatexCommand \index{Assembler documentation}
27233 \begin_inset LatexCommand \index{aslink}
27238 \begin_inset LatexCommand \index{Linker documentation}
27246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27250 sdcc/as/doc/asxhtm.html
27262 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
27271 <row topline="true">
27272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27276 SDCC regression test
27277 \begin_inset LatexCommand \index{Regression test}
27285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27289 sdcc/doc/test_suite_spec.pdf
27301 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
27310 <row topline="true">
27311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27335 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
27344 <row topline="true">
27345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27349 Notes on debugging with SDCDB
27350 \begin_inset LatexCommand \index{SDCDB (debugger)}
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27362 sdcc/debugger/README
27374 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
27383 <row topline="true">
27384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27389 \begin_inset LatexCommand \index{uCsim}
27393 Software simulator for microcontrollers
27397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27430 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
27439 <row topline="true">
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27444 Temporary notes on the pic16
27445 \begin_inset LatexCommand \index{PIC16}
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27457 sdcc/src/pic16/NOTES
27469 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
27478 <row topline="true" bottomline="true">
27479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27483 SDCC internal documentation (debugging file format)
27487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27520 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
27538 Related open source tools
27539 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
27544 \begin_inset LatexCommand \index{Related tools}
27552 \begin_inset Tabular
27553 <lyxtabular version="3" rows="14" columns="3">
27555 <column alignment="left" valignment="top" leftline="true" width="0pt">
27556 <column alignment="block" valignment="top" leftline="true" width="30line%">
27557 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27558 <row topline="true" bottomline="true">
27559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27590 <row topline="true">
27591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27596 \begin_inset LatexCommand \index{gpsim (pic simulator)}
27604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27616 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
27625 <row topline="true">
27626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27631 \begin_inset LatexCommand \index{gputils (pic tools)}
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27651 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
27660 <row topline="true">
27661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27681 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
27690 <row topline="true">
27691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27703 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27712 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
27721 <row topline="true">
27722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27727 \begin_inset LatexCommand \index{indent (source formatting tool)}
27735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27739 Formats C source - Master of the white spaces
27743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27747 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
27756 <row topline="true">
27757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27762 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
27770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27774 Object file conversion, checksumming, ...
27778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
27791 <row topline="true">
27792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27797 \begin_inset LatexCommand \index{objdump (tool)}
27805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27809 Object file conversion, ...
27813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27817 Part of binutils (should be there anyway)
27822 <row topline="true">
27823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27835 8051 monitor (hex up-/download, single step, disassemble)
27839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27843 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
27852 <row topline="true">
27853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27858 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27870 Source code documentation system
27874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27878 \begin_inset LatexCommand \url{http://www.doxygen.org}
27887 <row topline="true">
27888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27900 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27908 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27917 <row topline="true">
27918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27930 8051 monitor (hex up-/download, single step, disassemble)
27934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27938 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27947 <row topline="true">
27948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27953 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27965 Statically checks c sources (see
27966 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27978 \begin_inset LatexCommand \url{http://www.splint.org}
27987 <row topline="true" bottomline="true">
27988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27993 \begin_inset LatexCommand \index{DDD (debugger)}
28001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28005 Debugger, serves nicely as GUI to SDCDB
28006 \begin_inset LatexCommand \index{SDCDB (debugger)}
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28018 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
28036 Related documentation / recommended reading
28040 \begin_inset Tabular
28041 <lyxtabular version="3" rows="7" columns="3">
28043 <column alignment="left" valignment="top" leftline="true" width="0pt">
28044 <column alignment="left" valignment="top" leftline="true" width="0">
28045 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28046 <row topline="true" bottomline="true">
28047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28078 <row topline="true">
28079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28101 \begin_inset LatexCommand \index{C Reference card}
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28113 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
28122 <row topline="true">
28123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28136 \begin_inset LatexCommand \index{C FAQ}
28144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28148 \begin_inset LatexCommand \url{http://www.c-faq.com}
28157 <row topline="true">
28158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28170 \begin_inset Quotes sld
28174 \begin_inset Quotes srd
28181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28187 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
28196 <row topline="true">
28197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28209 \begin_inset Quotes sld
28212 Extensions for Embedded C
28213 \begin_inset Quotes srd
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28226 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
28235 <row topline="true">
28236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28248 Latest datasheet of target CPU
28252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28261 <row topline="true" bottomline="true">
28262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28274 Revision history of datasheet
28278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28296 Application notes specifically for SDCC
28299 SDCC makes no claims about the completeness of this list and about up-to-datenes
28300 s or correctness of the application notes
28301 \begin_inset LatexCommand \index{Application notes}
28311 \begin_inset Tabular
28312 <lyxtabular version="3" rows="7" columns="3">
28314 <column alignment="block" valignment="top" leftline="true" width="17col%">
28315 <column alignment="block" valignment="top" leftline="true" width="27col%">
28316 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
28317 <row topline="true" bottomline="true">
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28329 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
28340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28352 <row topline="true">
28353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28369 Using the SDCC Compiler for the DS80C400
28370 \begin_inset LatexCommand \index{DS80C400}
28378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28384 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
28393 <row topline="true">
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28404 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
28410 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
28411 \begin_inset LatexCommand \index{DS89C4x0}
28415 Family of Microcontrollers
28419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28425 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
28434 <row topline="true">
28435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28441 Silicon Laboratories / Cygnal
28445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28451 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
28452 \begin_inset LatexCommand \index{IDE}
28460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28466 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
28475 <row topline="true">
28476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28482 Ramtron / Goal Semiconductor
28486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28492 Interfacing SDCC to Syn and Textpad
28496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28502 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28511 <row topline="true">
28512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28518 Ramtron / Goal Semiconductor
28522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28528 Installing and Configuring SDCC and Crimson Editor
28532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28538 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28547 <row topline="true" bottomline="true">
28548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28564 MSC12xx Programming with SDCC
28568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28574 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
28593 Some questions answered, some pointers given - it might be time to in turn
28601 can you solve your project with the selected microcontroller? Would you
28602 find out early or rather late that your target is too small/slow/whatever?
28603 Can you switch to a slightly better device if it doesn't fit?
28606 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
28607 and/or another programming language be more adequate? Would an operating
28608 system on the target device help?
28611 if you solved the problem, will the marketing department be happy?
28614 if the marketing department is happy, will customers be happy?
28617 if you're the project manager, marketing department and maybe even the customer
28618 in one person, have you tried to see the project from the outside?
28621 is the project done if you think it is done? Or is just that other interface/pro
28622 tocol/feature/configuration/option missing? How about website, manual(s),
28623 internationali(z|s)ation, packaging, labels, 2nd source for components,
28624 electromagnetic compatability/interference, documentation for production,
28625 production test software, update mechanism, patent issues?
28628 is your project adequately positioned in that magic triangle: fame, fortune,
28632 Maybe not all answers to these questions are known and some answers may
28637 , nevertheless knowing these questions may help you to avoid burnout
28642 burnout is bad for electronic devices, programmers and motorcycle tyres
28647 Chances are you didn't want to hear some of them...
28651 \begin_inset LatexCommand \index{Support}
28658 SDCC has grown to be a large project.
28659 The compiler alone (without the preprocessor, assembler and linker) is
28660 well over 150,000 lines of code (blank stripped).
28661 The open source nature of this project is a key to its continued growth
28663 You gain the benefit and support of many active software developers and
28665 Is SDCC perfect? No, that's why we need your help.
28666 The developers take pride in fixing reported bugs.
28667 You can help by reporting the bugs and helping other SDCC users.
28668 There are lots of ways to contribute, and we encourage you to take part
28669 in making SDCC a great software package.
28673 The SDCC project is hosted on the SDCC sourceforge site at
28674 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
28679 You'll find the complete set of mailing lists
28680 \begin_inset LatexCommand \index{Mailing list(s)}
28684 , forums, bug reporting system, patch submission
28685 \begin_inset LatexCommand \index{Patch submission}
28690 \begin_inset LatexCommand \index{download}
28694 area and Subversion code repository
28695 \begin_inset LatexCommand \index{Subversion code repository}
28703 \begin_inset LatexCommand \index{Bug reporting}
28708 \begin_inset LatexCommand \index{Reporting bugs}
28715 The recommended way of reporting bugs is using the infrastructure of the
28717 You can follow the status of bug reports there and have an overview about
28721 Bug reports are automatically forwarded to the developer mailing list and
28722 will be fixed ASAP.
28723 When reporting a bug, it is very useful to include a small test program
28724 (the smaller the better) which reproduces the problem.
28725 If you can isolate the problem by looking at the generated assembly code,
28726 this can be very helpful.
28727 Compiling your program with the -
28740 \begin_inset LatexCommand \index{-\/-dumpall}
28744 option can sometimes be useful in locating optimization problems.
28745 When reporting a bug please make sure you:
28748 Attach the code you are compiling with SDCC.
28752 Specify the exact command you use to run SDCC, or attach your Makefile.
28756 Specify the SDCC version (type "
28762 "), your platform, and operating system.
28766 Provide an exact copy of any error message or incorrect output.
28770 Put something meaningful in the subject of your message.
28773 Please attempt to include these 5 important parts, as applicable, in all
28774 requests for support or when reporting any problems or bugs with SDCC.
28775 Though this will make your message lengthy, it will greatly improve your
28776 chance that SDCC users and developers will be able to help you.
28777 Some SDCC developers are frustrated by bug reports without code provided
28778 that they can use to reproduce and ultimately fix the problem, so please
28779 be sure to provide sample code if you are reporting a bug!
28782 Please have a short check that you are using a recent version of SDCC and
28783 the bug is not yet known.
28784 This is the link for reporting bugs:
28785 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
28790 With SDCC on average having more than 200 downloads
28791 \begin_inset LatexCommand \index{download}
28795 on sourceforge per day
28800 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
28801 between 2002 and 2005.
28802 This does not include other methods of distribution.
28806 there must be some users.
28807 So it's not exactly easy to find a new bug.
28808 If you find one we need it:
28810 reporting bugs is good
28815 Requesting Features
28816 \begin_inset LatexCommand \label{sub:Requesting-Features}
28821 \begin_inset LatexCommand \index{Feature request}
28826 \begin_inset LatexCommand \index{Requesting features}
28833 Like bug reports feature requests are forwarded to the developer mailing
28835 This is the link for requesting features:
28836 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28846 Like bug reports contributed patches are forwarded to the developer mailing
28848 This is the link for submitting patches
28849 \begin_inset LatexCommand \index{Patch submission}
28854 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28861 You need to specify some parameters to the
28865 command for the patches to be useful.
28866 If you modified more than one file a patch created f.e.
28871 \begin_inset Quotes sld
28874 diff -Naur unmodified_directory modified_directory >my_changes.patch
28875 \begin_inset Quotes srd
28881 will be fine, otherwise
28885 \begin_inset Quotes sld
28888 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28889 \begin_inset Quotes srd
28902 These links should take you directly to the
28903 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28912 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28913 automated messages (mid 2003)
28918 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28923 \begin_inset LatexCommand \index{Mailing list(s)}
28927 and forums are archived and searchable so if you are lucky someone already
28928 had a similar problem.
28929 While mails to the lists themselves are delivered promptly their web front
28930 end on sourceforge sometimes shows a severe time lag (up to several weeks),
28931 if you're seriously using SDCC please consider subscribing to the lists.
28937 You can follow the status of the Subversion version
28938 \begin_inset LatexCommand \index{version}
28942 of SDCC by watching the Changelog
28943 \begin_inset LatexCommand \index{Changelog}
28947 in the Subversion repository
28950 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28957 Subversion Source Code Repository
28966 or the filenames of the snapshot versions of SDCC include date and its
28968 \begin_inset LatexCommand \index{Subversion code repository}
28973 Subversion allows to download the source of recent or previous versions
28975 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28979 (by number or by date).
28980 An on-line source code browser and detailled instructions are also available
28982 SDCC versions starting from 1999 up to now are available (currently the
28983 versions prior to the conversion from cvs
28984 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28988 to Subversion (April 2006) are either by accessible by Subversion or by
28993 \begin_inset LatexCommand \index{Release policy}
29000 Historically there often were long delays between official releases and
29001 the sourceforge download area tends to get not updated at all.
29002 Excuses in the past might have referred to problems with live range analysis,
29003 but as this was fixed a while ago, the current problem is that another
29004 excuse has to be found.
29005 Kidding aside, we have to get better there! On the other hand there are
29006 daily snapshots available at
29007 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
29011 , and you can always build the very last version (hopefully with many bugs
29012 fixed, and features added) from the source code available at
29013 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
29019 \begin_inset LatexCommand \index{wiki}
29024 \begin_inset LatexCommand \index{Release wiki}
29029 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
29033 also holds some information about past and future releases.
29037 \begin_inset LatexCommand \index{Examples}
29044 You'll find some small examples in the directory
29046 sdcc/device/examples/.
29049 More examples and libraries are available at
29051 The SDCC Open Knowledge Resource
29052 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
29059 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
29070 I did insert a reference to Paul's web site here although it seems rather
29071 dedicated to a specific 8032 board (I think it's okay because it f.e.
29072 shows LCD/Harddisc interface and has a free 8051 monitor.
29073 Independent 8032 board vendors face hard competition of heavily subsidized
29074 development boards anyway).
29077 Maybe we should include some links to real world applications.
29078 Preferably pointer to pointers (one for each architecture) so this stays
29087 \begin_inset LatexCommand \label{sec:Quality-control}
29092 \begin_inset LatexCommand \index{Quality control}
29099 The compiler is passed through snaphot build compile and build checks.
29105 \begin_inset LatexCommand \index{Regression test}
29109 check that SDCC itself compiles flawlessly on several host platforms (i386,
29110 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
29111 the quality of the code generated by SDCC by running the code for several
29112 target platforms through simulators.
29113 The regression test suite comprises more than 100 files which expand to
29114 more than 500 test cases which include more than 4500 tests.
29115 The results of these tests are published daily on SDCC's snapshot page
29116 (click on the red or green symbols on the right side of
29117 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
29124 There is a separate document
29127 \begin_inset LatexCommand \index{Test suite}
29134 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
29138 about the regression test suite.
29141 You'll find the test code in the directory
29143 sdcc/support/regression
29146 You can run these tests manually by running
29150 in this directory (or f.e.
29155 \begin_inset Quotes sld
29159 \begin_inset Quotes srd
29165 if you don't want to run the complete tests).
29166 The test code might also be interesting if you want to look for examples
29167 \begin_inset LatexCommand \index{Examples}
29171 checking corner cases of SDCC or if you plan to submit patches
29172 \begin_inset LatexCommand \index{Patch submission}
29179 The 14bit pic port uses a different set of regression tests
29180 \begin_inset LatexCommand \index{Regression test (PIC14)}
29184 , you'll find them in the directory
29186 sdcc/src/regression
29191 Use of SDCC in Education
29203 the phrase "use in education" might evoke the association "
29207 fit for use in education".
29208 This connotation is not intended but nevertheless risked as the licensing
29209 of SDCC makes it difficult to offer educational discounts
29214 If your rationales are to:
29217 give students a chance to understand the
29221 steps of code generation
29224 have a curriculum that can be extended for years.
29225 Then you could use an fpga board as target and your curriculum will seamlessly
29226 extend from logic synthesis (
29227 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
29232 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
29236 ), over assembly programming, to C to FPGA compilers (
29237 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
29244 be able to insert excursions about skills like using a revision control
29245 system, submitting/applying patches, using a type-setting (as opposed to
29246 word-processing) engine LyX/LaTeX, using
29247 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
29252 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
29256 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
29257 Source Software, CPU simulation, compiler regression tests
29258 \begin_inset LatexCommand \index{Regression test}
29265 And if there should be a shortage of ideas then you can always point students
29266 to the ever-growing feature request list
29267 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
29274 not tie students to a specific host platform and instead allow them to use
29279 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
29281 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
29288 not encourage students to use illegal copies of educational software
29291 be immune to licensing/availability/price changes of the chosen tool chain
29294 be able to change to a new target platform without having to adopt a new
29298 have complete control over and insight into the tool chain
29301 make your students aware about the pros and cons of open source software
29305 give back to the public as you are probably at least partially publically
29309 give students a chance to publically prove their skills and to possibly
29310 see a world wide impact
29314 then SDCC is probably among the first choices.
29315 Well, probably SDCC might be the only choice.
29319 SDCC Technical Data
29323 \begin_inset LatexCommand \index{Optimizations}
29330 SDCC performs a host of standard optimizations in addition to some MCU specific
29335 Sub-expression Elimination
29336 \begin_inset LatexCommand \index{Subexpression elimination}
29343 The compiler does local and
29369 will be translated to
29381 Some subexpressions are not as obvious as the above example, e.g.:
29391 In this case the address arithmetic a->b[i] will be computed only once;
29392 the equivalent code in C would be.
29404 The compiler will try to keep these temporary variables in registers.
29407 Dead-Code Elimination
29408 \begin_inset LatexCommand \index{Dead-code elimination}
29429 i = 1; \SpecialChar ~
29438 global = 1;\SpecialChar ~
29452 global = 3;\SpecialChar ~
29477 \begin_inset LatexCommand \index{Copy propagation}
29533 Note: the dead stores created by this copy propagation will be eliminated
29534 by dead-code elimination.
29538 \begin_inset LatexCommand \index{Loop optimization}
29543 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
29550 Two types of loop optimizations are done by SDCC
29558 of loop induction variables.
29559 In addition to the strength reduction the optimizer marks the induction
29560 variables and the register allocator tries to keep the induction variables
29561 in registers for the duration of the loop.
29562 Because of this preference of the register allocator
29563 \begin_inset LatexCommand \index{Register allocation}
29567 , loop induction optimization causes an increase in register pressure, which
29568 may cause unwanted spilling of other temporary variables into the stack
29569 \begin_inset LatexCommand \index{stack}
29574 The compiler will generate a warning message when it is forced to allocate
29575 extra space either on the stack or data space.
29576 If this extra space allocation is undesirable then induction optimization
29577 can be eliminated either for the entire source file (with -
29589 -noinduction option) or for a given function only using #pragma\SpecialChar ~
29591 \begin_inset LatexCommand \index{\#pragma noinduction}
29604 for (i = 0 ; i < 100 ; i ++)
29620 for (i = 0; i < 100; i++)
29629 As mentioned previously some loop invariants are not as apparent, all static
29630 address computations are also moved out of the loop.
29635 \begin_inset LatexCommand \index{Strength reduction}
29639 , this optimization substitutes an expression by a cheaper expression:
29644 for (i=0;i < 100; i++)
29662 for (i=0;i< 100;i++) {
29668 ar[itemp1] = itemp2;
29686 The more expensive multiplication
29687 \begin_inset LatexCommand \index{Multiplication}
29691 is changed to a less expensive addition.
29695 \begin_inset LatexCommand \index{Loop reversing}
29702 This optimization is done to reduce the overhead of checking loop boundaries
29703 for every iteration.
29704 Some simple loops can be reversed and implemented using a
29705 \begin_inset Quotes eld
29708 decrement and jump if not zero
29709 \begin_inset Quotes erd
29713 SDCC checks for the following criterion to determine if a loop is reversible
29714 (note: more sophisticated compilers use data-dependency analysis to make
29715 this determination, SDCC uses a more simple minded analysis).
29718 The 'for' loop is of the form
29724 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
29734 The <for body> does not contain
29735 \begin_inset Quotes eld
29739 \begin_inset Quotes erd
29743 \begin_inset Quotes erd
29749 All goto's are contained within the loop.
29752 No function calls within the loop.
29755 The loop control variable <sym> is not assigned any value within the loop
29758 The loop control variable does NOT participate in any arithmetic operation
29762 There are NO switch statements in the loop.
29765 Algebraic Simplifications
29768 SDCC does numerous algebraic simplifications, the following is a small sub-set
29769 of these optimizations.
29774 i = j + 0;\SpecialChar ~
29778 /* changed to: */\SpecialChar ~
29784 i /= 2;\SpecialChar ~
29791 /* changed to: */\SpecialChar ~
29798 = j - j;\SpecialChar ~
29802 /* changed to: */\SpecialChar ~
29808 i = j / 1;\SpecialChar ~
29812 /* changed to: */\SpecialChar ~
29819 Note the subexpressions
29820 \begin_inset LatexCommand \index{Subexpression}
29824 given above are generally introduced by macro expansions or as a result
29825 of copy/constant propagation.
29828 'switch' Statements
29829 \begin_inset LatexCommand \label{sub:'switch'-Statements}
29834 \begin_inset LatexCommand \index{switch statement}
29841 SDCC can optimize switch statements to jump tables
29842 \begin_inset LatexCommand \index{jump tables}
29847 It makes the decision based on an estimate of the generated code size.
29848 SDCC is quite liberal in the requirements for jump table generation:
29851 The labels need not be in order, and the starting number need not be one
29852 or zero, the case labels are in numerical sequence or not too many case
29853 labels are missing.
29859 switch(i) {\SpecialChar ~
29890 case 4: ...\SpecialChar ~
29922 case 5: ...\SpecialChar ~
29954 case 3: ...\SpecialChar ~
29985 case 6: ...\SpecialChar ~
30017 case 7: ...\SpecialChar ~
30049 case 8: ...\SpecialChar ~
30081 case 9: ...\SpecialChar ~
30113 case 10: ...\SpecialChar ~
30144 case 11: ...\SpecialChar ~
30211 Both the above switch statements will be implemented using a jump-table.
30212 The example to the right side is slightly more efficient as the check for
30213 the lower boundary of the jump-table is not needed.
30217 The number of case labels is not larger than supported by the target architectur
30221 If the case labels are not in numerical sequence ('gaps' between cases)
30222 SDCC checks whether a jump table with additionally inserted dummy cases
30223 is still attractive.
30227 If the starting number is not zero and a check for the lower boundary of
30228 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
30233 Switch statements which have large gaps in the numeric sequence or those
30234 that have too many case labels can be split into more than one switch statement
30235 for efficient code generation, e.g.:
30315 If the above switch statement is broken down into two switch statements
30405 then both the switch statements will be implemented using jump-tables whereas
30406 the unmodified switch statement will not be.
30413 There might be reasons which SDCC cannot know about to either favour or
30414 not favour jump tables.
30415 If the target system has to be as quick for the last switch case as for
30416 the first (pro jump table), or if the switch argument is known to be zero
30417 in the majority of the cases (contra jump table).
30424 The pragma nojtbound
30425 \begin_inset LatexCommand \index{\#pragma nojtbound}
30429 can be used to turn off checking the
30442 It has no effect if a default label is supplied.
30443 Use of this pragma is dangerous: if the switch
30444 \begin_inset LatexCommand \index{switch statement}
30448 argument is not matched by a case statement the processor will happily
30452 Bit-shifting Operations
30453 \begin_inset LatexCommand \index{Bit shifting}
30460 Bit shifting is one of the most frequently used operation in embedded programmin
30462 SDCC tries to implement bit-shift operations in the most efficient way
30478 generates the following code:
30495 In general SDCC will never setup a loop if the shift count is known.
30538 \begin_inset LatexCommand \index{Bit rotation}
30545 A special case of the bit-shift operation is bit rotation
30546 \begin_inset LatexCommand \index{rotating bits}
30550 , SDCC recognizes the following expression to be a left bit-rotation:
30560 char i;\SpecialChar ~
30571 /* unsigned is needed for rotation */
30576 i = ((i << 1) | (i >> 7));
30585 will generate the following code:
30604 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
30605 ns of this case will also be recognized as bit-rotation, i.e.:
30610 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
30613 Nibble and Byte Swapping
30616 Other special cases of the bit-shift operations are nibble or byte swapping
30617 \begin_inset LatexCommand \index{swapping nibbles/bytes}
30621 , SDCC recognizes the following expressions:
30644 i = ((i << 4) | (i >> 4));
30650 j = ((j << 8) | (j >> 8));
30653 and generates a swap instruction for the nibble swapping
30654 \begin_inset LatexCommand \index{Nibble swapping}
30658 or move instructions for the byte swapping
30659 \begin_inset LatexCommand \index{Byte swapping}
30665 \begin_inset Quotes sld
30669 \begin_inset Quotes srd
30672 example can be used to convert from little to big-endian or vice versa.
30673 If you want to change the endianness of a
30677 integer you have to cast to
30684 Note that SDCC stores numbers in little-endian
30689 Usually 8-bit processors don't care much about endianness.
30690 This is not the case for the standard 8051 which only has an instruction
30696 \begin_inset LatexCommand \index{DPTR}
30704 so little-endian is the more efficient byte order.
30709 \begin_inset LatexCommand \index{little-endian}
30714 \begin_inset LatexCommand \index{Endianness}
30719 lowest order first).
30723 \begin_inset LatexCommand \index{Highest Order Bit}
30728 \begin_inset LatexCommand \index{Any Order Bit}
30735 It is frequently required to obtain the highest order bit of an integral
30736 type (long, int, short or char types).
30737 Also obtaining any other order bit is not uncommon.
30738 SDCC recognizes the following expressions to yield the highest order bit
30739 and generates optimized code for it, e.g.:
30752 unsigned char hob1, aob1;
30756 bit hob2, hob3, aob2,
30766 hob1 = (gint >> 15) & 1;
30770 hob2 = (gint >> 15) & 1;
30774 hob3 = gint & 0x8000;
30779 aob1 = (gint >> 9) & 1;
30783 aob2 = (gint >> 8) & 1;
30787 aob3 = gint & 0x0800;
30797 will generate the following code:
30830 000A E5*01\SpecialChar ~
30857 000C 23\SpecialChar ~
30888 000D 54 01\SpecialChar ~
30916 000F F5*02\SpecialChar ~
30971 0011 E5*01\SpecialChar ~
30999 0013 33\SpecialChar ~
31029 0014 92*00\SpecialChar ~
31085 0016 E5*01\SpecialChar ~
31112 0018 33\SpecialChar ~
31142 0019 92*01\SpecialChar ~
31198 001B E5*01\SpecialChar ~
31257 001E 54 01\SpecialChar ~
31284 0020 F5*03\SpecialChar ~
31340 0022 E5*01\SpecialChar ~
31367 0024 13\SpecialChar ~
31397 0025 92*02\SpecialChar ~
31453 0027 E5*01\SpecialChar ~
31481 A2 E3\SpecialChar ~
31508 002B 92*03\SpecialChar ~
31536 Other variations of these cases however will
31541 They are standard C expressions, so I heartily recommend these be the only
31542 way to get the highest order bit, (it is portable).
31543 Of course it will be recognized even if it is embedded in other expressions,
31549 xyz = gint + ((gint >> 15) & 1);
31552 will still be recognized.
31556 \begin_inset LatexCommand \index{Higher Order Byte}
31560 / Higher Order Word
31561 \begin_inset LatexCommand \index{Higher Order Word}
31568 It is also frequently required to obtain a higher order byte or word of
31569 a larger integral type (long, int or short types).
31570 SDCC recognizes the following expressions to yield the higher order byte
31571 or word and generates optimized code for it, e.g.:
31578 unsigned long int glong;
31586 unsigned char hob1,
31591 unsigned int how1, how2;
31600 hob1 = (gint >> 8) & 0xFF;
31604 hob2 = glong >> 24;
31608 how1 = (glong >> 16) & 0xFFFF;
31623 will generate the following code:
31656 0037 85*01*06\SpecialChar ~
31678 _foo_hob1_1_1,(_gint + 1)
31709 003A 85*05*07\SpecialChar ~
31731 _foo_hob2_1_1,(_glong + 3)
31761 003D 85*04*08\SpecialChar ~
31784 _foo_how1_1_1,(_glong + 2)
31786 0040 85*05*09\SpecialChar ~
31811 0043 85*03*0A\SpecialChar ~
31833 _foo_how2_1_1,(_glong + 1)
31835 0046 85*04*0B\SpecialChar ~
31858 (_foo_how2_1_1 + 1),(_glong + 2)
31861 Again, variations of these cases may
31866 They are standard C expressions, so I heartily recommend these be the only
31867 way to get the higher order byte/word, (it is portable).
31868 Of course it will be recognized even if it is embedded in other expressions,
31874 xyz = gint + ((gint >> 8) & 0xFF);
31877 will still be recognized.
31881 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31886 \begin_inset LatexCommand \index{Peephole optimizer}
31893 The compiler uses a rule based, pattern matching and re-writing mechanism
31894 for peep-hole optimization.
31899 a peep-hole optimizer by Christopher W.
31900 Fraser (cwfraser\SpecialChar ~
31903 A default set of rules are compiled into the compiler, additional rules
31904 may be added with the
31919 \begin_inset LatexCommand \index{-\/-peep-file}
31926 The rule language is best illustrated with examples.
31950 The above rule will change the following assembly
31951 \begin_inset LatexCommand \index{Assembler routines}
31973 Note: All occurrences of a
31977 (pattern variable) must denote the same string.
31978 With the above rule, the assembly sequence:
31988 will remain unmodified.
31992 Other special case optimizations may be added by the
32011 some variants of the 8051 MCU
32012 \begin_inset LatexCommand \index{MCS51 variants}
32025 The following two rules will change all
32044 replace { lcall %1 } by { acall %1 }
32046 replace { ljmp %1 } by { ajmp %1 }
32051 inline-assembler code
32053 is also passed through the peep hole optimizer, thus the peephole optimizer
32054 can also be used as an assembly level macro expander.
32055 The rules themselves are MCU dependent whereas the rule language infra-structur
32056 e is MCU independent.
32057 Peephole optimization rules for other MCU can be easily programmed using
32062 The syntax for a rule is as follows:
32067 rule := replace [ restart ] '{' <assembly sequence> '
32105 <assembly sequence> '
32123 '}' [if <functionName> ] '
32128 <assembly sequence> := assembly instruction (each instruction including
32129 labels must be on a separate line).
32133 The optimizer will apply to the rules
32134 one by one from the top in the sequence of their appearance, it will terminate
32135 when all rules are exhausted.
32136 If the 'restart' option is specified, then the optimizer will start matching
32137 the rules again from the top, this option for a rule is expensive (performance)
32138 , it is intended to be used in situations where a transformation will trigger
32139 the same rule again.
32140 An example of this (not a good one, it has side effects) is the following
32163 Note that the replace pattern cannot be a blank, but can be a comment line.
32164 Without the 'restart' option only the innermost 'pop' 'push' pair would
32165 be eliminated, i.e.:
32195 the restart option the rule will be applied again to the resulting code
32196 and then all the pop-push pairs will be eliminated to yield:
32206 A conditional function can be attached to a rule.
32207 Attaching rules are somewhat more involved, let me illustrate this with
32234 The optimizer does a look-up of a function name table defined in function
32239 in the source file SDCCpeeph.c, with the name
32244 If it finds a corresponding entry the function is called.
32245 Note there can be no parameters specified for these functions, in this
32250 is crucial, since the function
32254 expects to find the label in that particular variable (the hash table containin
32255 g the variable bindings is passed as a parameter).
32256 If you want to code more such functions, take a close look at the function
32257 labelInRange and the calling mechanism in source file SDCCpeeph.c.
32258 Currently implemented are
32260 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
32261 24bitMode, portIsDS390, 24bitModeAndPortDS390
32270 I know this whole thing is a little kludgey, but maybe some day we will
32271 have some better means.
32272 If you are looking at this file, you will see the default rules that are
32273 compiled into the compiler, you can add your own rules in the default set
32274 there if you get tired of specifying the -
32290 \begin_inset LatexCommand \index{ANSI-compliance}
32295 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
32302 The latest publically available version of the standard
32304 ISO/IEC 9899 - Programming languages - C
32306 should be available at:
32307 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32316 Deviations from the compliance:
32319 functions are not reentrant
32320 \begin_inset LatexCommand \index{reentrant}
32324 unless explicitly declared as such or the
32339 \begin_inset LatexCommand \index{-\/-stack-auto}
32345 command line option is specified.
32349 \begin_inset LatexCommand \index{struct}
32354 \begin_inset LatexCommand \index{union}
32358 cannot be assigned values directly, cannot be passed as function parameters
32359 or assigned to each other and cannot be a return value
32360 \begin_inset LatexCommand \index{return value}
32364 from a function, e.g.:
32390 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
32409 s parms) /* invalid in SDCC although allowed in ANSI */
32431 return rets; /* is invalid in SDCC although allowed in ANSI */
32437 initialization of structure arrays must be fully braced.
32443 struct s { char x } a[] = {1, 2};\SpecialChar ~
32448 /* invalid in SDCC */
32451 } a[] = {{1}, {2}}; /* OK */
32456 \begin_inset LatexCommand \index{long long (not supported)}
32461 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
32469 \begin_inset LatexCommand \index{double (not supported)}
32473 ' precision floating point
32474 \begin_inset LatexCommand \index{Floating point support}
32482 \begin_inset LatexCommand \index{K\&R style}
32486 function declarations are NOT allowed.
32492 foo(i,j) /* this old style of function declarations */
32494 int i,j; /* are valid
32495 in ANSI but not valid in SDCC */
32510 Most enhancements in C99 are not supported, f.e.:
32518 \begin_inset LatexCommand \index{inline (not supported)}
32524 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
32530 can be used as a work around */
32538 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
32542 Certain words that are valid identifiers in the standard may be reserved
32543 words in SDCC unless the
32558 \begin_inset LatexCommand \index{-\/-std-c89}
32575 \begin_inset LatexCommand \index{-\/-std-c99}
32581 command line options are used.
32582 These may include (depending on the selected processor): 'at', 'banked',
32583 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
32584 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
32585 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
32587 Compliant equivalents of these keywords are always available in a form
32588 that begin with two underscores
32589 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
32594 '__data' instead of 'data'.
32597 Cyclomatic Complexity
32598 \begin_inset LatexCommand \index{Cyclomatic complexity}
32605 Cyclomatic complexity of a function is defined as the number of independent
32606 paths the program can take during execution of the function.
32607 This is an important number since it defines the number test cases you
32608 have to generate to validate the function.
32609 The accepted industry standard for complexity number is 10, if the cyclomatic
32610 complexity reported by SDCC exceeds 10 you should think about simplification
32611 of the function logic.
32612 Note that the complexity level is not related to the number of lines of
32613 code in a function.
32614 Large functions can have low complexity, and small functions can have large
32620 SDCC uses the following formula to compute the complexity:
32625 complexity = (number of edges in control flow graph) - (number of nodes
32626 in control flow graph) + 2;
32630 Having said that the industry standard is 10,
32631 you should be aware that in some cases it be may unavoidable to have a
32632 complexity level of less than 10.
32633 For example if you have switch statement with more than 10 case labels,
32634 each case label adds one to the complexity level.
32635 The complexity level is by no means an absolute measure of the algorithmic
32636 complexity of the function, it does however provide a good starting point
32637 for which functions you might look at for further optimization.
32640 Retargetting for other Processors
32643 The issues for retargetting the compiler are far too numerous to be covered
32645 What follows is a brief description of each of the seven phases of the
32646 compiler and its MCU dependency.
32649 Parsing the source and building the annotated parse tree.
32650 This phase is largely MCU independent (except for the language extensions).
32651 Syntax & semantic checks are also done in this phase, along with some initial
32652 optimizations like back patching labels and the pattern matching optimizations
32653 like bit-rotation etc.
32656 The second phase involves generating an intermediate code which can be easy
32657 manipulated during the later phases.
32658 This phase is entirely MCU independent.
32659 The intermediate code generation assumes the target machine has unlimited
32660 number of registers, and designates them with the name iTemp.
32661 The compiler can be made to dump a human readable form of the code generated
32677 This phase does the bulk of the standard optimizations and is also MCU independe
32679 This phase can be broken down into several sub-phases:
32683 Break down intermediate
32684 code (iCode) into basic blocks.
32686 Do control flow & data flow analysis on the
32689 Do local common subexpression elimination, then global subexpressio
32692 Dead code elimination
32696 If loop optimizations
32697 caused any changes then do 'global subexpression elimination' and 'dead
32698 code elimination' again.
32701 This phase determines the live-ranges; by live range I mean those iTemp
32702 variables defined by the compiler that still survive after all the optimization
32704 Live range analysis
32705 \begin_inset LatexCommand \index{Live range analysis}
32709 is essential for register allocation, since these computation determines
32710 which of these iTemps will be assigned to registers, and for how long.
32713 Phase five is register allocation.
32714 There are two parts to this process.
32718 The first part I call 'register packing'
32719 (for lack of a better term).
32720 In this case several MCU specific expression folding is done to reduce
32725 The second part is more MCU independent and deals with
32726 allocating registers to the remaining live ranges.
32727 A lot of MCU specific code does creep into this phase because of the limited
32728 number of index registers available in the 8051.
32731 The Code generation phase is (unhappily), entirely MCU dependent and very
32732 little (if any at all) of this code can be reused for other MCU.
32733 However the scheme for allocating a homogenized assembler operand for each
32734 iCode operand may be reused.
32737 As mentioned in the optimization section the peep-hole optimizer is rule
32738 based system, which can reprogrammed for other MCUs.
32741 More information is available in a wiki
32742 \begin_inset LatexCommand \index{wiki}
32747 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
32751 ) and in the thread
32752 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
32760 \begin_inset LatexCommand \index{Compiler internals}
32767 The anatomy of the compiler
32768 \begin_inset LatexCommand \label{sub:The-anatomy-of}
32777 This is an excerpt from an article published in Circuit Cellar Magazine
32783 It's a little outdated (the compiler is much more efficient now and user/develo
32784 per friendly), but pretty well exposes the guts of it all.
32790 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
32791 It is fairly easy to retarget for other 8-bit MCU.
32792 Here we take a look at some of the internals of the compiler.
32797 \begin_inset LatexCommand \index{Parsing}
32804 Parsing the input source file and creating an AST (Annotated Syntax Tree
32805 \begin_inset LatexCommand \index{Annotated syntax tree}
32810 This phase also involves propagating types (annotating each node of the
32811 parse tree with type information) and semantic analysis.
32812 There are some MCU specific parsing rules.
32813 For example the storage classes, the extended storage classes are MCU specific
32814 while there may be a xdata storage class for 8051 there is no such storage
32815 class for z80 or Atmel AVR.
32816 SDCC allows MCU specific storage class extensions, i.e.
32817 xdata will be treated as a storage class specifier when parsing 8051 C
32818 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
32823 \begin_inset LatexCommand \index{iCode}
32830 Intermediate code generation.
32831 In this phase the AST is broken down into three-operand form (iCode).
32832 These three operand forms are represented as doubly linked lists.
32833 ICode is the term given to the intermediate form generated by the compiler.
32834 ICode example section shows some examples of iCode generated for some simple
32835 C source functions.
32839 \begin_inset LatexCommand \index{Optimizations}
32846 Bulk of the target independent optimizations is performed in this phase.
32847 The optimizations include constant propagation, common sub-expression eliminati
32848 on, loop invariant code movement, strength reduction of loop induction variables
32849 and dead-code elimination.
32852 Live range analysis
32853 \begin_inset LatexCommand \index{Live range analysis}
32860 During intermediate code generation phase, the compiler assumes the target
32861 machine has infinite number of registers and generates a lot of temporary
32863 The live range computation determines the lifetime of each of these compiler-ge
32864 nerated temporaries.
32865 A picture speaks a thousand words.
32866 ICode example sections show the live range annotations for each of the
32868 It is important to note here, each iCode is assigned a number in the order
32869 of its execution in the function.
32870 The live ranges are computed in terms of these numbers.
32871 The from number is the number of the iCode which first defines the operand
32872 and the to number signifies the iCode which uses this operand last.
32875 Register Allocation
32876 \begin_inset LatexCommand \index{Register allocation}
32883 The register allocation determines the type and number of registers needed
32885 In most MCUs only a few registers can be used for indirect addressing.
32886 In case of 8051 for example the registers R0 & R1 can be used to indirectly
32887 address the internal ram and DPTR to indirectly address the external ram.
32888 The compiler will try to allocate the appropriate register to pointer variables
32890 ICode example section shows the operands annotated with the registers assigned
32892 The compiler will try to keep operands in registers as much as possible;
32893 there are several schemes the compiler uses to do achieve this.
32894 When the compiler runs out of registers the compiler will check to see
32895 if there are any live operands which is not used or defined in the current
32896 basic block being processed, if there are any found then it will push that
32897 operand and use the registers in this block, the operand will then be popped
32898 at the end of the basic block.
32902 There are other MCU specific considerations in this phase.
32903 Some MCUs have an accumulator; very short-lived operands could be assigned
32904 to the accumulator instead of a general-purpose register.
32910 Figure II gives a table of iCode
32911 \begin_inset LatexCommand \index{iCode}
32915 operations supported by the compiler.
32916 The code generation involves translating these operations into corresponding
32917 assembly code for the processor.
32918 This sounds overly simple but that is the essence of code generation.
32919 Some of the iCode operations are generated on a MCU specific manner for
32920 example, the z80 port does not use registers to pass parameters so the
32921 SEND and RECV iCode operations will not be generated, and it also does
32922 not support JUMPTABLES.
32931 \begin_inset Tabular
32932 <lyxtabular version="3" rows="39" columns="4">
32933 <features islongtable="true" headBottomDL="true">
32934 <column alignment="block" valignment="top" leftline="true" width="13col%">
32935 <column alignment="left" valignment="top" leftline="true" width="13col%">
32936 <column alignment="block" valignment="top" leftline="true" width="22col%">
32937 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32938 <row topline="true" bottomline="true" endhead="true">
32939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32948 \begin_inset LatexCommand \index{iCode}
32956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32987 <row topline="true">
32988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33004 IC_LEFT() IC_RESULT()
33008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33024 IC_RESULT = ! IC_LEFT;
33029 <row topline="true">
33030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33046 IC_LEFT() IC_RESULT()
33050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33056 Bitwise complement of
33060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33066 IC_RESULT = ~IC_LEFT;
33071 <row topline="true">
33072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33088 IC_LEFT() IC_RESULT()
33092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33098 Rotate right with carry
33102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33108 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
33113 <row topline="true">
33114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33130 IC_LEFT() IC_RESULT()
33134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33140 Rotate left with carry
33144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33150 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
33155 <row topline="true">
33156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33172 IC_LEFT() IC_RESULT()
33176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33182 Get the highest order bit of IC_LEFT
33186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33192 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
33197 <row topline="true">
33198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33214 IC_LEFT() IC_RESULT()
33218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33234 IC_RESULT = - IC_LEFT;
33239 <row topline="true">
33240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33266 Push the operand into stack
33270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33281 <row topline="true">
33282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33308 Pop the operand from the stack
33312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33323 <row topline="true">
33324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33340 IC_LEFT() IC_RESULT()
33344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33350 Call the function represented by IC_LEFT
33354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33360 IC_RESULT = IC_LEFT();
33365 <row topline="true">
33366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33382 IC_LEFT() IC_RESULT()
33386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33392 Call via function pointer
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33402 IC_RESULT = (*IC_LEFT)();
33407 <row topline="true">
33408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33434 Return the value in operand IC_LEFT
33438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33449 <row topline="true">
33450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33491 <row topline="true">
33492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33533 <row topline="true">
33534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33550 IC_LEFT() IC_RIGHT() IC_RESULT()
33554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33570 IC_RESULT = IC_LEFT + IC_RIGHT
33575 <row topline="true">
33576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33592 IC_LEFT() IC_RIGHT() IC_RESULT()
33596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33612 IC_RESULT = IC_LEFT - IC_RIGHT
33617 <row topline="true">
33618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33634 IC_LEFT() IC_RIGHT() IC_RESULT()
33638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33654 IC_RESULT = IC_LEFT * IC_RIGHT;
33659 <row topline="true">
33660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33676 IC_LEFT() IC_RIGHT() IC_RESULT()
33680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33696 IC_RESULT = IC_LEFT / IC_RIGHT;
33701 <row topline="true">
33702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33718 IC_LEFT() IC_RIGHT() IC_RESULT()
33722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33738 IC_RESULT = IC_LEFT % IC_RIGHT;
33743 <row topline="true">
33744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33760 IC_LEFT() IC_RIGHT() IC_RESULT()
33764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33780 IC_RESULT = IC_LEFT < IC_RIGHT;
33785 <row topline="true">
33786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33802 IC_LEFT() IC_RIGHT() IC_RESULT()
33806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33822 IC_RESULT = IC_LEFT > IC_RIGHT;
33827 <row topline="true">
33828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33844 IC_LEFT() IC_RIGHT() IC_RESULT()
33848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33864 IC_RESULT = IC_LEFT == IC_RIGHT;
33869 <row topline="true">
33870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33886 IC_LEFT() IC_RIGHT() IC_RESULT()
33890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33896 Logical and operation
33900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33906 IC_RESULT = IC_LEFT && IC_RIGHT;
33911 <row topline="true">
33912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33928 IC_LEFT() IC_RIGHT() IC_RESULT()
33932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33938 Logical or operation
33942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33948 IC_RESULT = IC_LEFT || IC_RIGHT;
33953 <row topline="true">
33954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33970 IC_LEFT() IC_RIGHT() IC_RESULT()
33974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33990 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33995 <row topline="true">
33996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34012 IC_LEFT() IC_RIGHT() IC_RESULT()
34016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34032 IC_RESULT = IC_LEFT | IC_RIGHT;
34037 <row topline="true">
34038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34054 IC_LEFT() IC_RIGHT() IC_RESULT()
34058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34074 IC_RESULT = IC_LEFT & IC_RIGHT;
34079 <row topline="true">
34080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34096 IC_LEFT() IC_RIGHT() IC_RESULT()
34100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34116 IC_RESULT = IC_LEFT << IC_RIGHT
34121 <row topline="true">
34122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34138 IC_LEFT() IC_RIGHT() IC_RESULT()
34142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34158 IC_RESULT = IC_LEFT >> IC_RIGHT
34163 <row topline="true">
34164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34182 IC_LEFT() IC_RESULT()
34186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34202 IC_RESULT = (*IC_LEFT);
34207 <row topline="true">
34208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34224 IC_RIGHT() IC_RESULT()
34228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34244 (*IC_RESULT) = IC_RIGHT;
34249 <row topline="true">
34250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34266 IC_RIGHT() IC_RESULT()
34270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34286 IC_RESULT = IC_RIGHT;
34291 <row topline="true">
34292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34308 IC_COND IC_TRUE IC_LABEL
34312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34319 If true label is present then jump to true label if condition is true else
34320 jump to false label if condition is false
34324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34330 if (IC_COND) goto IC_TRUE;
34336 If (!IC_COND) goto IC_FALSE;
34341 <row topline="true">
34342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34358 IC_LEFT() IC_RESULT()
34362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34378 IC_RESULT = &IC_LEFT();
34383 <row topline="true">
34384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34400 IC_JTCOND IC_JTLABELS
34404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34410 Jump to list of labels depending on the value of JTCOND
34414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34425 <row topline="true">
34426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34442 IC_RIGHT() IC_LEFT() IC_RESULT()
34446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34462 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
34467 <row topline="true">
34468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34494 This is used for passing parameters in registers;
34496 move IC_LEFT to the next
34497 available parameter register.
34501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34512 <row topline="true">
34513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34539 This is used for receiving parameters passed in registers;
34542 in the next parameter register to IC_RESULT
34546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34557 <row topline="true" bottomline="true">
34558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34565 (some more have been added)
34569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34615 In the original article Figure II was announced to be downloadable on
34620 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
34628 \begin_inset LatexCommand \index{iCode}
34635 This section shows some details of iCode.
34636 The example C code does not do anything useful; it is used as an example
34637 to illustrate the intermediate code generated by the compiler.
34649 /* This function does nothing useful.
34656 for the purpose of explaining iCode */
34659 short function (data
34668 short i=10; \SpecialChar ~
34670 /* dead initialization eliminated */
34676 /* dead initialization eliminated */
34704 /* compiler detects i,j to be induction
34709 for (i = 0, j = 10 ; i < 10 ; i++, j
34737 mul += i * 3; \SpecialChar ~
34739 /* this multiplication remains */
34746 j * 3;\SpecialChar ~
34748 /* this multiplication changed to addition */
34762 In addition to the operands each iCode contains information about the filename
34763 and line it corresponds to in the source file.
34764 The first field in the listing should be interpreted as follows:
34769 Filename(linenumber: iCode Execution sequence number : ICode hash table
34770 key : loop depth of the iCode).
34775 Then follows the human readable form of the ICode operation.
34776 Each operand of this triplet form can be of three basic types a) compiler
34777 generated temporary b) user defined variable c) a constant value.
34778 Note that local variables and parameters are replaced by compiler generated
34781 \begin_inset LatexCommand \index{Live range analysis}
34785 are computed only for temporaries (i.e.
34786 live ranges are not computed for global variables).
34788 \begin_inset LatexCommand \index{Register allocation}
34792 are allocated for temporaries only.
34793 Operands are formatted in the following manner:
34798 Operand Name [lr live-from : live-to ] { type information } [ registers
34804 As mentioned earlier the live ranges are computed in terms of the execution
34805 sequence number of the iCodes, for example
34807 the iTemp0 is live from (i.e.
34808 first defined in iCode with execution sequence number 3, and is last used
34809 in the iCode with sequence number 5).
34810 For induction variables such as iTemp21 the live range computation extends
34811 the lifetime from the start to the end of the loop.
34813 The register allocator
34814 used the live range information to allocate registers, the same registers
34815 may be used for different temporaries if their live ranges do not overlap,
34816 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
34817 ranges do not overlap.
34818 In addition the allocator also takes into consideration the type and usage
34819 of a temporary, for example itemp6 is a pointer to near space and is used
34820 as to fetch data from (i.e.
34821 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
34822 Some short lived temporaries are allocated to special registers which have
34823 meaning to the code generator e.g.
34824 iTemp13 is allocated to a pseudo register CC which tells the back end that
34825 the temporary is used only for a conditional jump the code generation makes
34826 use of this information to optimize a compare and jump ICode.
34830 \begin_inset LatexCommand \index{Loop optimization}
34834 performed by the compiler.
34835 It can detect induction variables iTemp21(i) and iTemp23(j).
34836 Also note the compiler does selective strength reduction
34837 \begin_inset LatexCommand \index{Strength reduction}
34842 the multiplication of an induction variable in line 18 (gint = j * 3) is
34843 changed to addition, a new temporary iTemp17 is allocated and assigned
34844 a initial value, a constant 3 is then added for each iteration of the loop.
34845 The compiler does not change the multiplication
34846 \begin_inset LatexCommand \index{Multiplication}
34850 in line 17 however since the processor does support an 8 * 8 bit multiplication.
34853 Note the dead code elimination
34854 \begin_inset LatexCommand \index{Dead-code elimination}
34858 optimization eliminated the dead assignments in line 7 & 8 to I and sum
34866 Sample.c (5:1:0:0) _entry($9) :
34871 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34876 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
34881 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34886 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34892 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34897 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34903 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34908 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34914 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34920 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34926 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34932 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34933 * int}[r0] + 0x2 {short}
34938 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34943 Sample.c(11:17:21:0)_whilebreak_0($3) :
34948 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34953 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34958 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34963 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34968 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34973 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34978 Sample.c(15:24:26:1)_forcond_0($4) :
34983 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34989 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34994 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34995 + ITemp21 [lr21:38]{short}[r4]
35000 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
35006 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
35007 + iTemp15 [lr29:30]{short}[r1]
35012 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
35018 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
35024 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
35030 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
35036 Sample.c(19:38:47:1) goto _forcond_0($4)
35041 Sample.c(19:39:48:0)_forbreak_0($7) :
35046 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
35047 + ITemp11 [lr19:40]{short}[r3]
35052 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
35057 Sample.c(20:42:51:0)_return($8) :
35062 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
35068 Finally the code generated for this function:
35109 ; ----------------------------------------------
35114 ; function function
35119 ; ----------------------------------------------
35129 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
35141 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
35153 ;_whilecontinue_0($1) :
35163 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
35168 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
35227 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
35246 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
35293 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
35333 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
35359 ; iTemp6 [lr5:16]{_near * int}[r0] =
35364 ; iTemp6 [lr5:16]{_near * int}[r0] +
35381 ; goto _whilecontinue_0($1)
35393 ; _whilebreak_0($3) :
35403 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
35415 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
35427 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
35439 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
35458 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
35487 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
35492 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
35537 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
35542 ; iTemp21 [lr21:38]{short}[r4]
35568 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
35601 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
35606 ; iTemp15 [lr29:30]{short}[r1]
35625 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
35672 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
35719 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
35731 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
35745 cjne r5,#0xff,00104$
35757 ; goto _forcond_0($4)
35769 ; _forbreak_0($7) :
35779 ; ret iTemp24 [lr40:41]{short}
35822 A few words about basic block successors, predecessors and dominators
35825 Successors are basic blocks
35826 \begin_inset LatexCommand \index{Basic blocks}
35830 that might execute after this basic block.
35832 Predecessors are basic blocks
35833 that might execute before reaching this basic block.
35835 Dominators are basic
35836 blocks that WILL execute before reaching this basic block.
35869 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35872 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35875 c) domVect of [BB4] = BB1 ...
35876 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35883 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35893 Thanks to all the other volunteer developers who have helped with coding,
35894 testing, web-page creation, distribution sets, etc.
35895 You know who you are :-)
35903 Also thanks to Sourceforge
35904 \begin_inset LatexCommand \url{http://www.sf.net}
35908 which has hosted the project since 1999 and donates significant download
35909 bandwidth and probably more than
35919 CPU cycles per day.
35926 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35927 minutes for (configure+make+regression test), and there is (i386, amd64,
35928 alpha, ppc64, (mingw32), sparc, macosx).
35936 This document was initially written by Sandeep Dutta
35939 All product names mentioned herein may be trademarks
35940 \begin_inset LatexCommand \index{Trademarks}
35944 of their respective companies.
35951 To avoid confusion, the installation and building options for SDCC itself
35952 (chapter 2) are not part of the index.
35955 \begin_inset LatexCommand \printindex{}