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://svn.sourceforge.net/svnroot/sdcc
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 Sourceforge's compile farm.
1420 See the examples, how to pass the Win32 settings to 'configure'.
1421 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1422 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1433 \begin_inset Tabular
1434 <lyxtabular version="3" rows="9" columns="3">
1436 <column alignment="block" valignment="top" leftline="true" width="0in">
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1439 <row topline="true" bottomline="true">
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1465 <row topline="true">
1466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1495 <row topline="true">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1527 <row topline="true">
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1597 <row topline="true">
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1631 <row topline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1697 <row topline="true" bottomline="true">
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1735 'configure' also computes relative paths.
1736 This is needed for full relocatability of a binary package and to complete
1737 search paths (see section search paths below):
1743 \begin_inset Tabular
1744 <lyxtabular version="3" rows="4" columns="3">
1746 <column alignment="block" valignment="top" leftline="true" width="0in">
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1749 <row topline="true" bottomline="true">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1775 <row topline="true" bottomline="true">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1803 <row bottomline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1831 <row bottomline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1887 \begin_inset Quotes srd
1891 \begin_inset Quotes srd
1907 \begin_inset Quotes srd
1911 \begin_inset Quotes srd
1943 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1952 \begin_inset Quotes srd
1955 i586-mingw32msvc-gcc
1956 \begin_inset Quotes srd
1960 \begin_inset Quotes srd
1963 i586-mingw32msvc-g++
1964 \begin_inset Quotes srd
1972 \begin_inset Quotes srd
1975 i586-mingw32msvc-ranlib
1976 \begin_inset Quotes srd
1984 \begin_inset Quotes srd
1987 i586-mingw32msvc-strip
1988 \begin_inset Quotes srd
2008 \begin_inset Quotes srd
2012 \begin_inset Quotes srd
2032 \begin_inset Quotes srd
2036 \begin_inset Quotes srd
2044 \begin_inset Quotes srd
2050 \begin_inset Quotes srd
2058 \begin_inset Quotes srd
2062 \begin_inset Quotes srd
2070 \begin_inset Quotes srd
2074 \begin_inset Quotes srd
2081 sdccconf_h_dir_separator=
2082 \begin_inset Quotes srd
2094 \begin_inset Quotes srd
2129 -host=i586-mingw32msvc
2145 -build=unknown-unknown-linux-gnu
2149 \begin_inset Quotes sld
2153 \begin_inset Quotes srd
2156 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2177 \begin_inset Quotes srd
2181 \begin_inset Quotes srd
2201 \begin_inset Quotes srd
2205 \begin_inset Quotes srd
2213 \begin_inset Quotes srd
2219 \begin_inset Quotes srd
2227 \begin_inset Quotes srd
2231 \begin_inset Quotes srd
2239 \begin_inset Quotes srd
2243 \begin_inset Quotes srd
2250 sdccconf_h_dir_separator=
2251 \begin_inset Quotes srd
2263 \begin_inset Quotes srd
2271 \begin_inset Quotes srd
2275 \begin_inset Quotes srd
2283 \begin_inset Quotes srd
2287 \begin_inset Quotes srd
2293 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2306 -C' turns on caching, which gives a little bit extra speed.
2307 However if options are changed, it can be necessary to delete the config.cache
2312 \added_space_bottom medskip
2313 \begin_inset LatexCommand \label{sub:Install-paths}
2318 \begin_inset LatexCommand \index{Install paths}
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="5" columns="4">
2330 <column alignment="left" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
2334 <row topline="true" bottomline="true">
2335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2376 <row topline="true">
2377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2416 <row topline="true">
2417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2431 $DATADIR/ $INCLUDE_DIR_SUFFIX
2435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 /usr/local/share/sdcc/include
2443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2456 <row topline="true">
2457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2471 $DATADIR/$LIB_DIR_SUFFIX
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2479 /usr/local/share/sdcc/lib
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2496 <row topline="true" bottomline="true">
2497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2519 /usr/local/share/sdcc/doc
2523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2545 *compiler, preprocessor, assembler, and linker
2551 is auto-appended by the compiler, e.g.
2552 small, large, z80, ds390 etc
2556 The install paths can still be changed during `make install` with e.g.:
2559 make install prefix=$(HOME)/local/sdcc
2562 Of course this doesn't change the search paths compiled into the binaries.
2567 r the install path can be changed by defining DESTDIR
2568 \begin_inset LatexCommand \index{DESTDIR}
2575 make install DESTDIR=$(HOME)/sdcc.rpm/
2578 Please note that DESTDIR must have a trailing slash!
2582 \begin_inset LatexCommand \label{sub:Search-Paths}
2587 \begin_inset LatexCommand \index{Search path}
2594 Some search paths or parts of them are determined by configure variables
2599 , see section above).
2600 Further search paths are determined by environment variables during runtime.
2603 The paths searched when running the compiler are as follows (the first
2609 Binary files (preprocessor, assembler and linker)
2615 \begin_inset Tabular
2616 <lyxtabular version="3" rows="4" columns="3">
2618 <column alignment="block" valignment="top" leftline="true" width="0in">
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2621 <row topline="true" bottomline="true">
2622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2647 <row topline="true">
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2677 <row topline="true">
2678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 Path of argv[0] (if available)
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2703 <row topline="true" bottomline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2746 \begin_inset Tabular
2747 <lyxtabular version="3" rows="6" columns="3">
2749 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2752 <row topline="true" bottomline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2778 <row topline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2840 <row topline="true">
2841 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2866 <row topline="true">
2867 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2881 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2904 <row topline="true">
2905 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2986 <row topline="true" bottomline="true">
2987 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3003 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3007 /usr/local/share/sdcc/
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3044 -nostdinc disables the last two search paths.
3054 With the exception of
3055 \begin_inset Quotes sld
3071 \begin_inset Quotes srd
3078 is auto-appended by the compiler (e.g.
3079 small, large, z80, ds390 etc.).
3086 \begin_inset Tabular
3087 <lyxtabular version="3" rows="6" columns="3">
3089 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3090 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3091 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3092 <row topline="true" bottomline="true">
3093 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3118 <row topline="true">
3119 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 <row topline="true">
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3193 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3220 <row topline="true">
3221 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3231 $LIB_DIR_SUFFIX/<model>
3235 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3249 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3266 <row topline="true">
3267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3281 $LIB_DIR_SUFFIX/<model>
3285 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3394 <row topline="true" bottomline="true">
3395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3403 $LIB_DIR_SUFFIX/<model>
3407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3411 /usr/local/share/sdcc/
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3441 Don't delete any of the stray spaces in the table above without checking
3442 the HTML output (last line)!
3464 -nostdlib disables the last two search paths.
3468 \begin_inset LatexCommand \index{Building SDCC}
3475 Building SDCC on Linux
3476 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3485 Download the source package
3487 either from the SDCC Subversion repository or from the nightly snapshots
3489 , it will be named something like sdcc
3500 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3509 Bring up a command line terminal, such as xterm.
3514 Unpack the file using a command like:
3517 "tar -xvzf sdcc.src.tar.gz
3522 , this will create a sub-directory called sdcc with all of the sources.
3525 Change directory into the main SDCC directory, for example type:
3542 This configures the package for compilation on your system.
3558 All of the source packages will compile, this can take a while.
3574 This copies the binary executables, the include files, the libraries and
3575 the documentation to the install directories.
3576 Proceed with section
3577 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3584 Building SDCC on OSX 2.x
3587 Follow the instruction for Linux.
3591 On OSX 2.x it was reported, that the default
3592 gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3593 Fortunately there's also gcc 2.9.x installed, which works fine.
3594 This compiler can be selected by running 'configure' with:
3597 ./configure CC=gcc2 CXX=g++2
3600 Cross compiling SDCC on Linux for Windows
3603 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3604 See section 'Configure Options'.
3607 Building SDCC using Cygwin and Mingw32
3610 For building and installing a Cygwin executable follow the instructions
3616 \begin_inset Quotes sld
3620 \begin_inset Quotes srd
3623 Win32-binary can be built, which will not need the Cygwin-DLL.
3624 For the necessary 'configure' options see section 'configure options' or
3625 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3630 Cygwin on Windows download setup.exe from
3631 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3637 \begin_inset Quotes sld
3640 default text file type
3641 \begin_inset Quotes srd
3645 \begin_inset Quotes sld
3649 \begin_inset Quotes srd
3652 and download/install at least the following packages.
3653 Some packages are selected by default, others will be automatically selected
3654 because of dependencies with the manually selected packages.
3655 Never deselect these packages!
3664 gcc ; version 3.x is fine, no need to use the old 2.9x
3667 binutils ; selected with gcc
3673 rxvt ; a nice console, which makes life much easier under windoze (see below)
3676 man ; not really needed for building SDCC, but you'll miss it sooner or
3680 less ; not really needed for building SDCC, but you'll miss it sooner or
3684 svn ; only if you use Subversion access
3687 If you want to develop something you'll need:
3690 python ; for the regression tests
3693 gdb ; the gnu debugger, together with the nice GUI
3694 \begin_inset Quotes sld
3698 \begin_inset Quotes srd
3704 openssh ; to access the CF or commit changes
3707 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3708 use autoconf-stable!
3711 rxvt is a nice console with history.
3712 Replace in your cygwin.bat the line
3733 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3736 -bg black -fg white -geometry 100x65 -e bash -
3751 Text selected with the mouse is automatically copied to the clipboard, pasting
3752 works with shift-insert.
3756 The other good tip is to make sure you have no //c/-styl
3757 e paths anywhere, use /cygdrive/c/ instead.
3758 Using // invokes a network lookup which is very slow.
3760 \begin_inset Quotes sld
3764 \begin_inset Quotes srd
3767 is too long, you can change it with e.g.
3773 SDCC sources use the unix line ending LF.
3774 Life is much easier, if you store the source tree on a drive which is mounted
3776 And use an editor which can handle LF-only line endings.
3777 Make sure not to commit files with windows line endings.
3778 The tabulator spacing
3779 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3783 used in the project is 8.
3784 Although a tabulator spacing of 8 is a sensible choice for programmers
3785 (it's a power of 2 and allows to display 8/16 bit signed variables without
3786 loosing columns) the plan is to move towards using only spaces in the source.
3789 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3794 Download the source package
3796 either from the SDCC Subversion repository or from the
3797 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3803 , it will be named something like sdcc
3810 SDCC is distributed with all the projects, workspaces, and files you need
3811 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3812 The workspace name is 'sdcc.dsw'.
3813 Please note that as it is now, all the executables are created in a folder
3817 Once built you need to copy the executables from sdcc
3821 bin before running SDCC.
3826 WARNING: Visual studio is very picky with line terminations; it expects
3827 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3828 When using the Subversion repository it's easiest to configure the svn
3829 client to convert automatically for you.
3830 If however you are getting a message such as "This makefile was not generated
3831 by Developer Studio etc.
3833 \begin_inset Quotes srd
3836 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3837 need to convert the Unix style line endings to DOS style line endings.
3838 To do so you can use the
3839 \begin_inset Quotes sld
3843 \begin_inset Quotes srd
3846 utility freely available on the internet.
3847 Doug Hawkins reported in the sdcc-user list that this works:
3855 SDCC> unix2dos sdcc.dsw
3861 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3865 In order to build SDCC with MSVC
3866 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3867 One good place to get them is
3868 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3876 Download the file UnxUtils
3877 \begin_inset LatexCommand \index{UnxUtils}
3882 Now you have to install the utilities and setup MSVC so it can locate the
3884 Here there are two alternatives (choose one!):
3891 a) Extract UnxUtils.zip to your C:
3893 hard disk PRESERVING the original paths, otherwise bison won't work.
3894 (If you are using WinZip make certain that 'Use folder names' is selected)
3899 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3900 'Show directories for:' select 'Executable files', and in the directories
3901 window add a new path: 'C:
3911 (As a side effect, you get a bunch of Unix utilities that
3912 could be useful, such as diff and patch.)
3919 This one avoids extracting a bunch of files you may not
3920 use, but requires some extra work:
3924 a) Create a directory were to put the
3925 tools needed, or use a directory already present.
3932 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3933 gawk.exe to such directory WITHOUT preserving the original paths.
3934 (If you are using WinZip make certain that 'Use folder names' is not selected)
3939 ) Rename bison.exe to '_bison.exe'.
3943 d) Create a batch file 'bison.bat' in 'C:
3947 ' and add these lines:
3967 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3971 Steps 'c' and 'd' are needed
3972 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3973 reside in some weird Unix directory, '/usr/local/share/' I think.
3974 So it is necessary to tell bison where those files are located if they
3975 are not in such directory.
3976 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3981 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3982 in 'Show directories for:' select 'Executable files', and in the directories
3983 window add a new path: 'c:
3986 Note that you can use any other path instead of 'c:
3988 util', even the path where the Visual C++ tools are, probably: 'C:
3992 Microsoft Visual Studio
3997 So you don't have to execute step 'e' :)
4001 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4002 the executables from sdcc
4006 bin, and you can compile using SDCC.
4009 Building SDCC Using Borland
4012 From the sdcc directory, run the command "make -f Makefile.bcc".
4013 This should regenerate all the .exe files in the bin directory except for
4017 If you modify any source files and need to rebuild, be aware that the dependenci
4018 es may not be correctly calculated.
4019 The safest option is to delete all .obj files and run the build again.
4020 From a Cygwin BASH prompt, this can easily be done with the command (be
4021 sure you are in the sdcc directory):
4031 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4033 ) -print -exec rm {}
4042 or on Windows NT/2000/XP from the command prompt with the command:
4049 del /s *.obj *.lib *.rul
4052 from the sdcc directory.
4055 Windows Install Using a ZIP Package
4058 Download the binary zip package from
4059 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4063 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4064 This should unpack to a group of sub-directories.
4065 An example directory structure after unpacking the mingw32 package is:
4070 bin for the executables, c:
4078 lib for the include and libraries.
4081 Adjust your environment variable PATH to include the location of the bin
4082 directory or start sdcc using the full path.
4085 Windows Install Using the Setup Program
4086 \begin_inset LatexCommand \label{sub:Windows-Install}
4093 Download the setup program
4095 sdcc-x.y.z-setup.exe
4097 for an official release from
4100 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4104 or a setup program for one of the snapshots
4106 sdcc-yyyymmdd-xxxx-setup.exe
4109 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4114 A windows typical installer will guide you through the installation process.
4118 \begin_inset LatexCommand \index{VPATH}
4125 SDCC supports the VPATH feature provided by configure and make.
4126 It allows to separate the source and build trees.
4158 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4159 # extract source to directory sdcc
4164 mkdir sdcc.build\SpecialChar ~
4173 # put output in sdcc.build
4183 ../sdcc/configure\SpecialChar ~
4191 # configure is doing all the magic!
4204 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4205 It automagically computes the variables srcdir, top_srcdir and top_buildir
4211 the generated files will be in ~/sdcc.build, while the source files stay
4214 This is not only usefull for building different binaries, e.g.
4215 when cross compiling.
4216 It also gives you a much better overview in the source tree when all the
4217 generated files are not scattered between the source files.
4218 And the best thing is: if you want to change a file you can leave the original
4219 file untouched in the source directory.
4220 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4221 Makefile.dep` and `make`.
4226 will do the rest for you!
4229 Building the Documentation
4244 -enable-doc to the configure arguments to build the documentation together
4245 with all the other stuff.
4246 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4247 dvips and makeindex) to get the job done.
4248 Another possibility is to change to the doc directory and to type
4252 \begin_inset Quotes srd
4256 \begin_inset Quotes srd
4263 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4266 \begin_inset LatexCommand \url{http://www.lyx.org}
4270 as editor is straightforward.
4271 Prebuilt documentation in html and pdf format is available from
4272 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4279 Reading the Documentation
4280 \begin_inset LatexCommand \index{Documentation}
4287 Currently reading the document in pdf format is recommended, as for unknown
4288 reason the hyperlinks are working there whereas in the html version they
4294 If you should know why please drop us a note
4301 You'll find the pdf version
4302 \begin_inset LatexCommand \index{PDF version of this document}
4307 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4315 \begin_inset LatexCommand \index{HTML version of this document}
4320 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4326 This documentation is in some aspects different from a commercial documentation:
4330 It tries to document SDCC for several processor architectures in one document
4331 (commercially these probably would be separate documents/products).
4333 \begin_inset LatexCommand \index{Status of documentation}
4337 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4339 Z80, PIC14, PIC16 and HC08.
4342 There are many references pointing away from this documentation.
4343 Don't let this distract you.
4345 was a reference like
4346 \begin_inset LatexCommand \url{http://www.opencores.org}
4350 together with a statement
4351 \begin_inset Quotes sld
4354 some processors which are targetted by SDCC can be implemented in a
4371 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4376 \begin_inset Quotes srd
4380 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4385 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4390 \begin_inset Quotes sld
4393 have you ever heard of an open source compiler that compiles a subset of
4395 \begin_inset Quotes srd
4398 we expect you to have a quick look there and come back.
4399 If you read this you are on the right track.
4402 Some sections attribute more space to problems, restrictions and warnings
4403 than to the solution.
4406 The installation section and the section about the debugger is intimidating.
4409 There are still lots of typos and there are more different writing styles
4413 Testing the SDCC Compiler
4414 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4421 The first thing you should do after installing your SDCC compiler is to
4439 \begin_inset LatexCommand \index{version}
4446 at the prompt, and the program should run and output its version like:
4451 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4455 If it doesn't run, or gives a message about not finding sdcc program, then
4456 you need to check over your installation.
4457 Make sure that the sdcc bin directory is in your executable search path
4458 defined by the PATH environment setting (
4463 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4470 Install trouble-shooting for suggestions
4473 Make sure that the sdcc program is in the bin folder, if not perhaps something
4474 did not install correctly.
4482 is commonly installed as described in section
4483 \begin_inset Quotes sld
4486 Install and search paths
4487 \begin_inset Quotes srd
4496 Make sure the compiler works on a very simple example.
4497 Type in the following test.c program using your favorite
4523 Compile this using the following command:
4532 If all goes well, the compiler will generate a test.asm and test.rel file.
4533 Congratulations, you've just compiled your first program with SDCC.
4534 We used the -c option to tell SDCC not to link the generated code, just
4535 to keep things simple for this step.
4543 The next step is to try it with the linker.
4553 If all goes well the compiler will link with the libraries and produce
4554 a test.ihx output file.
4559 (no test.ihx, and the linker generates warnings), then the problem is most
4568 usr/local/share/sdcc/lib directory
4575 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4582 Install trouble-shooting for suggestions).
4590 The final test is to ensure
4598 header files and libraries.
4599 Edit test.c and change it to the following:
4616 strcpy(str1, "testing");
4623 Compile this by typing
4630 This should generate a test.ihx output file, and it should give no warnings
4631 such as not finding the string.h file.
4632 If it cannot find the string.h file, then the problem is that
4636 cannot find the /usr/local/share/sdcc/include directory
4643 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4650 Install trouble-shooting section for suggestions).
4670 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4674 to find exactly where SDCC is looking for the include and lib files.
4677 Install Trouble-shooting
4678 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4683 \begin_inset LatexCommand \index{Install trouble-shooting}
4690 If SDCC does not build correctly
4693 A thing to try is starting from scratch by unpacking the .tgz source package
4694 again in an empty directory.
4702 ./configure 2>&1 | tee configure.log
4716 make 2>&1 | tee make.log
4723 If anything goes wrong, you can review the log files to locate the problem.
4724 Or a relevant part of this can be attached to an email that could be helpful
4725 when requesting help from the mailing list.
4729 \begin_inset Quotes sld
4733 \begin_inset Quotes srd
4740 \begin_inset Quotes sld
4744 \begin_inset Quotes srd
4747 command is a script that analyzes your system and performs some configuration
4748 to ensure the source package compiles on your system.
4749 It will take a few minutes to run, and will compile a few tests to determine
4750 what compiler features are installed.
4754 \begin_inset Quotes sld
4758 \begin_inset Quotes srd
4764 This runs the GNU make tool, which automatically compiles all the source
4765 packages into the final installed binary executables.
4769 \begin_inset Quotes sld
4773 \begin_inset Quotes erd
4779 This will install the compiler, other executables libraries and include
4780 files into the appropriate directories.
4782 \begin_inset LatexCommand \ref{sub:Install-paths}
4788 \begin_inset LatexCommand \ref{sub:Search-Paths}
4793 about install and search paths.
4795 On most systems you will need super-user privilege
4802 SDCC is not just a compiler, but a collection of tools by various developers.
4803 These include linkers, assemblers, simulators and other components.
4804 Here is a summary of some of the components.
4805 Note that the included simulator and assembler have separate documentation
4806 which you can find in the source package in their respective directories.
4807 As SDCC grows to include support for other processors, other packages from
4808 various developers are included and may have their own sets of documentation.
4813 might want to look at the files which are installed in <installdir>.
4814 At the time of this writing, we find the following programs for gcc-builds:
4819 In <installdir>/bin:
4822 sdcc - The compiler.
4825 sdcpp - The C preprocessor.
4828 asx8051 - The assembler for 8051 type processors.
4835 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4838 aslink -The linker for 8051 type processors.
4845 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4848 s51 - The ucSim 8051 simulator.
4851 sdcdb - The source debugger.
4854 packihx - A tool to pack (compress) Intel hex files.
4857 In <installdir>/share/sdcc/include
4863 In <installdir>/share/sdcc/lib
4866 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4870 In <installdir>/share/sdcc/doc
4876 As development for other processors proceeds, this list will expand to include
4877 executables to support processors like AVR, PIC, etc.
4883 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4884 the assembler and linkage editor.
4887 sdcpp - The C-Preprocessor
4891 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4895 is a modified version of the GNU cpp
4896 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4901 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4906 The C preprocessor is used to pull in #include sources, process #ifdef
4907 statements, #defines and so on.
4918 - The Assemblers and Linkage Editors
4921 This is retargettable assembler & linkage editor, it was developed by Alan
4923 John Hartman created the version for 8051, and I (Sandeep) have made some
4924 enhancements and bug fixes for it to work properly with SDCC.
4931 \begin_inset LatexCommand \index{s51}
4935 is a freeware, opensource simulator developed by Daniel Drotos.
4936 The simulator is built as part of the build process.
4937 For more information visit Daniel's web site at:
4938 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4943 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4947 sdcdb - Source Level Debugger
4951 \begin_inset LatexCommand \index{SDCDB (debugger)}
4955 is the companion source level debugger.
4956 More about SDCDB in section
4957 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4962 The current version of the debugger uses Daniel's Simulator S51
4963 \begin_inset LatexCommand \index{s51}
4967 , but can be easily changed to use other simulators.
4976 Single Source File Projects
4979 For single source file 8051 projects the process is very simple.
4980 Compile your programs with the following command
4983 "sdcc sourcefile.c".
4987 This will compile, assemble and link your source file.
4988 Output files are as follows:
4992 \begin_inset LatexCommand \index{<file>.asm}
4997 \begin_inset LatexCommand \index{Assembler source}
5001 file created by the compiler
5005 \begin_inset LatexCommand \index{<file>.lst}
5010 \begin_inset LatexCommand \index{Assembler listing}
5014 file created by the Assembler
5018 \begin_inset LatexCommand \index{<file>.rst}
5023 \begin_inset LatexCommand \index{Assembler listing}
5027 file updated with linkedit information, created by linkage editor
5031 \begin_inset LatexCommand \index{<file>.sym}
5036 \begin_inset LatexCommand \index{Symbol listing}
5040 for the sourcefile, created by the assembler
5044 \begin_inset LatexCommand \index{<file>.rel}
5049 \begin_inset LatexCommand \index{<file>.o}
5054 \begin_inset LatexCommand \index{Object file}
5058 created by the assembler, input to Linkage editor
5062 \begin_inset LatexCommand \index{<file>.map}
5067 \begin_inset LatexCommand \index{Memory map}
5071 for the load module, created by the Linker
5075 \begin_inset LatexCommand \index{<file>.mem}
5079 - A file with a summary of the memory usage
5083 \begin_inset LatexCommand \index{<file>.ihx}
5087 - The load module in Intel hex format
5088 \begin_inset LatexCommand \index{Intel hex format}
5092 (you can select the Motorola S19 format
5093 \begin_inset LatexCommand \index{Motorola S19 format}
5110 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5115 If you need another format you might want to use
5122 \begin_inset LatexCommand \index{objdump (tool)}
5133 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5138 Both formats are documented in the documentation of srecord
5139 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5147 \begin_inset LatexCommand \index{<file>.adb}
5151 - An intermediate file containing debug information needed to create the
5165 \begin_inset LatexCommand \index{-\/-debug}
5173 \begin_inset LatexCommand \index{<file>.cdb}
5177 - An optional file (with -
5189 -debug) containing debug information.
5190 The format is documented in cdbfileformat.pdf
5195 \begin_inset LatexCommand \index{<file> (no extension)}
5199 An optional AOMF or AOMF51
5200 \begin_inset LatexCommand \index{AOMF, AOMF51}
5205 \begin_inset LatexCommand \label{OMF file}
5209 file containing debug information (generated with option -
5238 ormat is commonly used by third party tools (debuggers
5239 \begin_inset LatexCommand \index{Debugger}
5243 , simulators, emulators)
5247 \begin_inset LatexCommand \index{<file>.dump*}
5251 - Dump file to debug the compiler it self (generated with option -
5263 -dumpall) (see section
5264 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5270 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5276 \begin_inset Quotes sld
5279 Anatomy of the compiler
5280 \begin_inset Quotes srd
5286 Postprocessing the Intel Hex
5287 \begin_inset LatexCommand \index{Intel hex format}
5294 In most cases this won't be needed but the Intel Hex file
5295 \begin_inset LatexCommand \index{<file>.ihx}
5299 which is generated by SDCC might include lines of varying length and the
5300 addresses within the file are not guaranteed to be strictly ascending.
5301 If your toolchain or a bootloader does not like this you can use the tool
5307 \begin_inset LatexCommand \index{packihx (tool)}
5311 which is part of the SDCC distribution:
5318 packihx sourcefile.ihx >sourcefile.hex
5325 The separately available
5330 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5334 package additionally allows to set undefined locations to a predefined
5335 value, to insert checksums
5336 \begin_inset LatexCommand \index{checksum}
5340 of various flavours (crc, add, xor) and to perform other manipulations
5341 (convert, split, crop, offset, ...).
5349 srec_cat\SpecialChar ~
5351 sourcefile.ihx -intel\SpecialChar ~
5353 -o sourcefile.hex -intel
5360 An example for a more complex command line
5365 the command backfills
5366 \begin_inset LatexCommand \index{backfill unused memory}
5370 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5372 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5373 will be interpreted as an
5381 (where an emergency routine could sit).
5393 srec_cat\SpecialChar ~
5394 sourcefile.ihx -intel\SpecialChar ~
5396 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5397 -little-endian-checksum-nega
5398 tive 0xfffe 0x02 0x02\SpecialChar ~
5400 -o sourcefile.hex -intel
5409 The srecord package is available at
5410 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5417 Projects with Multiple Source Files
5420 SDCC can compile only ONE file at a time.
5421 Let us for example assume that you have a project containing the following
5426 foo1.c (contains some functions)
5428 foo2.c (contains some more functions)
5431 n.c (contains more functions and the function main)
5439 The first two files will need to be compiled separately with the commands:
5471 Then compile the source file containing the
5476 \begin_inset LatexCommand \index{Linker}
5480 the files together with the following command:
5488 foomain.c\SpecialChar ~
5489 foo1.rel\SpecialChar ~
5494 \begin_inset LatexCommand \index{<file>.rel}
5506 can be separately compiled as well:
5517 sdcc foomain.rel foo1.rel foo2.rel
5524 The file containing the
5539 file specified in the command line, since the linkage editor processes
5540 file in the order they are presented to it.
5541 The linker is invoked from SDCC using a script file with extension .lnk
5542 \begin_inset LatexCommand \index{<file>.lnk}
5547 You can view this file to troubleshoot linking problems such as those arising
5548 from missing libraries.
5551 Projects with Additional Libraries
5552 \begin_inset LatexCommand \index{Libraries}
5559 Some reusable routines may be compiled into a library, see the documentation
5560 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5564 \begin_inset LatexCommand \index{<file>.lib}
5571 Libraries created in this manner can be included in the command line.
5572 Make sure you include the -L <library-path> option to tell the linker where
5573 to look for these files if they are not in the current directory.
5574 Here is an example, assuming you have the source file
5586 (if that is not the same as your current project):
5593 sdcc foomain.c foolib.lib -L mylib
5604 must be an absolute path name.
5608 The most efficient way to use libraries is
5609 to keep separate modules in separate source files.
5610 The lib file now should name all the modules.rel
5611 \begin_inset LatexCommand \index{<file>.rel}
5616 For an example see the standard library file
5620 in the directory <installdir>/share/lib/small.
5623 Using sdcclib to Create and Manage Libraries
5624 \begin_inset LatexCommand \index{sdcclib}
5631 Alternatively, instead of having a .rel file for each entry on the library
5632 file as described in the preceding section, sdcclib can be used to embed
5633 all the modules belonging to such library in the library file itself.
5634 This results in a larger library file, but it greatly reduces the number
5635 of disk files accessed by the linker.
5636 Additionally, the packed library file contains an index of all include
5637 modules and symbols that significantly speeds up the linking process.
5638 To display a list of options supported by sdcclib type:
5647 \begin_inset LatexCommand \index{sdcclib}
5658 To create a new library file, start by compiling all the required modules.
5696 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5698 The next step is to add the .rel files to the library file:
5706 sdcclib libint.lib _divsint.rel
5709 \begin_inset LatexCommand \index{sdcclib}
5719 sdcclib libint.lib _divuint.rel
5725 sdcclib libint.lib _modsint.rel
5731 sdcclib libint.lib _moduint.rel
5737 sdcclib libint.lib _mulint.rel
5744 If the file already exists in the library, it will be replaced.
5745 To see what modules and symbols are included in the library, options -s
5746 and -m are available.
5754 sdcclib -s libint.lib
5757 \begin_inset LatexCommand \index{sdcclib}
5867 \added_space_bottom bigskip
5868 If the source files are compiled using -
5881 \begin_inset LatexCommand \index{-\/-debug}
5885 , the corresponding debug information file .adb will be include in the library
5887 The library files created with sdcclib are plain text files, so they can
5888 be viewed with a text editor.
5889 It is not recomended to modify a library file created with sdcclib using
5890 a text editor, as there are file indexes numbers located accross the file
5891 used by the linker to quickly locate the required module to link.
5892 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5893 it can be safely deleted, since all the information required for linking
5894 is embedded in the library file itself.
5895 Library files created using sdcclib are used as described in the preceding
5901 Command Line Options
5902 \begin_inset LatexCommand \index{Command Line Options}
5909 Processor Selection Options
5910 \begin_inset LatexCommand \index{Options processor selection}
5915 \begin_inset LatexCommand \index{Processor selection options}
5922 \labelwidthstring 00.00.0000
5926 \begin_inset LatexCommand \index{-mmcs51}
5932 Generate code for the Intel MCS51
5933 \begin_inset LatexCommand \index{MCS51}
5937 family of processors.
5938 This is the default processor target.
5941 \labelwidthstring 00.00.0000
5945 \begin_inset LatexCommand \index{-mds390}
5951 Generate code for the Dallas DS80C390
5952 \begin_inset LatexCommand \index{DS80C390}
5959 \labelwidthstring 00.00.0000
5963 \begin_inset LatexCommand \index{-mds400}
5969 Generate code for the Dallas DS80C400
5970 \begin_inset LatexCommand \index{DS80C400}
5977 \labelwidthstring 00.00.0000
5981 \begin_inset LatexCommand \index{-mhc08}
5987 Generate code for the Freescale/Motorola HC08
5988 \begin_inset LatexCommand \index{HC08}
5992 family of processors.
5995 \labelwidthstring 00.00.0000
5999 \begin_inset LatexCommand \index{-mz80}
6005 Generate code for the Zilog Z80
6006 \begin_inset LatexCommand \index{Z80}
6010 family of processors.
6013 \labelwidthstring 00.00.0000
6017 \begin_inset LatexCommand \index{-mgbz80}
6023 Generate code for the GameBoy Z80
6024 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6028 processor (Not actively maintained).
6031 \labelwidthstring 00.00.0000
6035 \begin_inset LatexCommand \index{-mavr}
6041 Generate code for the Atmel AVR
6042 \begin_inset LatexCommand \index{AVR}
6046 processor (Not maintained, not complete).
6047 AVR users should probably have a look at winavr
6048 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6053 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6064 I think it is fair to direct users there for now.
6065 Open source is also about avoiding unnecessary work .
6066 But I didn't find the 'official' link.
6073 \labelwidthstring 00.00.0000
6077 \begin_inset LatexCommand \index{-mpic14}
6083 Generate code for the Microchip PIC 14
6084 \begin_inset LatexCommand \index{PIC14}
6088 -bit processors (p16f84 and variants.
6089 In development, not complete).
6096 p16f627 p16f628 p16f84 p16f873 p16f877?
6103 \labelwidthstring 00.00.0000
6107 \begin_inset LatexCommand \index{-mpic16}
6113 Generate code for the Microchip PIC 16
6114 \begin_inset LatexCommand \index{PIC16}
6118 -bit processors (p18f452 and variants.
6119 In development, not complete).
6122 \labelwidthstring 00.00.0000
6127 Generate code for the Toshiba TLCS-900H
6128 \begin_inset LatexCommand \index{TLCS-900H}
6132 processor (Not maintained, not complete).
6135 \labelwidthstring 00.00.0000
6136 \added_space_bottom bigskip
6140 \begin_inset LatexCommand \index{-mxa51}
6146 Generate code for the Phillips XA51
6147 \begin_inset LatexCommand \index{XA51}
6151 processor (Not maintained, not complete).
6155 Preprocessor Options
6156 \begin_inset LatexCommand \index{Options preprocessor}
6161 \begin_inset LatexCommand \index{Preprocessor options}
6166 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6173 \labelwidthstring 00.00.0000
6177 \begin_inset LatexCommand \index{-I<path>}
6183 The additional location where the pre processor will look for <..h> or
6184 \begin_inset Quotes eld
6188 \begin_inset Quotes erd
6194 \labelwidthstring 00.00.0000
6198 \begin_inset LatexCommand \index{-D<macro[=value]>}
6204 Command line definition of macros.
6205 Passed to the preprocessor.
6208 \labelwidthstring 00.00.0000
6212 \begin_inset LatexCommand \index{-M}
6218 Tell the preprocessor to output a rule suitable for make describing the
6219 dependencies of each object file.
6220 For each source file, the preprocessor outputs one make-rule whose target
6221 is the object file name for that source file and whose dependencies are
6222 all the files `#include'd in it.
6223 This rule may be a single line or may be continued with `
6225 '-newline if it is long.
6226 The list of rules is printed on standard output instead of the preprocessed
6229 \begin_inset LatexCommand \index{-E}
6236 \labelwidthstring 00.00.0000
6240 \begin_inset LatexCommand \index{-C}
6246 Tell the preprocessor not to discard comments.
6247 Used with the `-E' option.
6250 \labelwidthstring 00.00.0000
6254 \begin_inset LatexCommand \index{-MM}
6265 Like `-M' but the output mentions only the user header files included with
6267 \begin_inset Quotes eld
6271 System header files included with `#include <file>' are omitted.
6274 \labelwidthstring 00.00.0000
6278 \begin_inset LatexCommand \index{-Aquestion(answer)}
6284 Assert the answer answer for question, in case it is tested with a preprocessor
6285 conditional such as `#if #question(answer)'.
6286 `-A-' disables the standard assertions that normally describe the target
6290 \labelwidthstring 00.00.0000
6294 \begin_inset LatexCommand \index{-Umacro}
6300 Undefine macro macro.
6301 `-U' options are evaluated after all `-D' options, but before any `-include'
6302 and `-imacros' options.
6305 \labelwidthstring 00.00.0000
6309 \begin_inset LatexCommand \index{-dM}
6315 Tell the preprocessor to output only a list of the macro definitions that
6316 are in effect at the end of preprocessing.
6317 Used with the `-E' option.
6320 \labelwidthstring 00.00.0000
6324 \begin_inset LatexCommand \index{-dD}
6330 Tell the preprocessor to pass all macro definitions into the output, in
6331 their proper sequence in the rest of the output.
6334 \labelwidthstring 00.00.0000
6338 \begin_inset LatexCommand \index{-dN}
6349 Like `-dD' except that the macro arguments and contents are omitted.
6350 Only `#define name' is included in the output.
6353 \labelwidthstring 00.00.0000
6356 -pedantic-parse-number
6357 \begin_inset LatexCommand \index{-pedantic-parse-number}
6368 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6369 and the macro LO_B(3) gets expanded.
6370 See also #pragma pedantic_parse_number in section
6371 \begin_inset LatexCommand \ref{sec:Pragmas}
6377 Note: this functionality is not in conformance with standard!
6380 \labelwidthstring 00.00.0000
6381 \added_space_bottom bigskip
6385 preprocessorOption[,preprocessorOption]
6388 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6393 Pass the preprocessorOption to the preprocessor
6398 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6403 SDCC uses an adapted version of the preprocessor
6407 of the GNU Compiler Collection
6408 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6417 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6421 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6426 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6435 \begin_inset LatexCommand \index{Options linker}
6440 \begin_inset LatexCommand \index{Linker options}
6447 \labelwidthstring 00.00.0000
6468 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6473 \begin_inset LatexCommand \index{-L -\/-lib-path}
6480 <absolute path to additional libraries> This option is passed to the linkage
6481 editor's additional libraries
6482 \begin_inset LatexCommand \index{Libraries}
6487 The path name must be absolute.
6488 Additional library files may be specified in the command line.
6489 See section Compiling programs for more details.
6492 \labelwidthstring 00.00.0000
6510 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6515 <Value> The start location of the external ram
6516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6520 , default value is 0.
6521 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6533 -xram-loc 0x8000 or -
6548 \labelwidthstring 00.00.0000
6566 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6571 <Value> The start location of the code
6572 \begin_inset LatexCommand \index{code}
6576 segment, default value 0.
6577 Note when this option is used the interrupt vector table
6578 \begin_inset LatexCommand \index{interrupt vector table}
6582 is also relocated to the given address.
6583 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6595 -code-loc 0x8000 or -
6610 \labelwidthstring 00.00.0000
6628 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6633 <Value> By default the stack
6634 \begin_inset LatexCommand \index{stack}
6638 is placed after the data segment.
6639 Using this option the stack can be placed anywhere in the internal memory
6641 The value entered can be in Hexadecimal or Decimal format, e.g.
6654 -stack-loc 0x20 or -
6667 Since the sp register is incremented before a push or call, the initial
6668 sp will be set to one byte prior the provided value.
6669 The provided value should not overlap any other memory areas such as used
6670 register banks or the data segment and with enough space for the current
6690 \begin_inset LatexCommand \index{-\/-pack-iram}
6694 option (which is now a default setting) will override this setting, so
6695 you should also specify the
6713 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6717 option if you need to manually place the stack.
6720 \labelwidthstring 00.00.0000
6738 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6743 <Value> By default the external stack
6744 \begin_inset LatexCommand \index{xstack}
6748 is placed after the pdata
6749 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6754 Using this option the xstack can be placed anywhere in the external memory
6756 The value entered can be in Hexadecimal or Decimal format, e.g.
6769 -xstack-loc 0x8000 or -
6782 The provided value should not overlap any other memory areas such as the
6783 pdata or xdata segment and with enough space for the current application.
6786 \labelwidthstring 00.00.0000
6804 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6809 <Value> The start location of the internal ram data
6810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6815 The value entered can be in Hexadecimal or Decimal format, eg.
6841 (By default, the start location of the internal ram data segment is set
6842 as low as possible in memory, taking into account the used register banks
6843 and the bit segment at address 0x20.
6844 For example if register banks 0 and 1 are used without bit variables, the
6845 data segment will be set, if -
6857 -data-loc is not used, to location 0x10.)
6860 \labelwidthstring 00.00.0000
6878 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6883 <Value> The start location of the indirectly addressable internal ram
6884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6888 of the 8051, default value is 0x80.
6889 The value entered can be in Hexadecimal or Decimal format, eg.
6902 -idata-loc 0x88 or -
6917 \labelwidthstring 00.00.0000
6935 <Value> The start location of the bit
6936 \begin_inset LatexCommand \index{bit}
6940 addressable internal ram of the 8051.
6946 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6950 \labelwidthstring 00.00.0000
6966 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6975 The linker output (final object code) is in Intel Hex format.
6976 \begin_inset LatexCommand \index{Intel hex format}
6980 This is the default option.
6981 The format itself is documented in the documentation of srecord
6982 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6989 \labelwidthstring 00.00.0000
7005 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7014 The linker output (final object code) is in Motorola S19 format
7015 \begin_inset LatexCommand \index{Motorola S19 format}
7020 The format itself is documented in the documentation of srecord.
7023 \labelwidthstring 00.00.0000
7039 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7044 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7053 The linker output (final object code) is in ELF format
7054 \begin_inset LatexCommand \index{ELF format}
7059 (Currently only supported for the HC08
7060 \begin_inset LatexCommand \index{HC08}
7067 \labelwidthstring 00.00.0000
7068 \added_space_bottom bigskip
7072 linkOption[,linkOption]
7075 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7080 Pass the linkOption to the linker.
7081 If a bootloader is used an option like
7082 \begin_inset Quotes sld
7087 \begin_inset Quotes srd
7090 would be typical to set the start of the code segment.
7091 See also #pragma constseg and #pragma codeseg in section
7092 \begin_inset LatexCommand \ref{sec:Pragmas}
7097 File sdcc/as/doc/asxhtm.html has more on linker options.
7102 \begin_inset LatexCommand \index{Options MCS51}
7107 \begin_inset LatexCommand \index{MCS51 options}
7114 \labelwidthstring 00.00.0000
7130 \begin_inset LatexCommand \index{-\/-model-small}
7141 Generate code for Small Model programs, see section Memory Models for more
7143 This is the default model.
7146 \labelwidthstring 00.00.0000
7162 \begin_inset LatexCommand \index{-\/-model-medium}
7168 Generate code for Medium model programs, see section Memory Models for
7170 If this option is used all source files in the project have to be compiled
7172 It must also be used when invoking the linker.
7175 \labelwidthstring 00.00.0000
7191 \begin_inset LatexCommand \index{-\/-model-large}
7197 Generate code for Large model programs, see section Memory Models for more
7199 If this option is used all source files in the project have to be compiled
7201 It must also be used when invoking the linker.
7204 \labelwidthstring 00.00.0000
7220 \begin_inset LatexCommand \index{-\/-xstack}
7226 Uses a pseudo stack in the pdata
7227 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7231 area (usually the first 256 bytes in the external ram) for allocating variables
7232 and passing parameters.
7234 \begin_inset LatexCommand \ref{sub:External-Stack}
7239 External Stack for more details.
7242 \labelwidthstring 00.00.0000
7261 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7265 Causes the linker to check if the internal ram usage is within limits of
7269 \labelwidthstring 00.00.0000
7288 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7292 Causes the linker to check if the external ram usage is within limits of
7296 \labelwidthstring 00.00.0000
7315 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7319 Causes the linker to check if the code memory usage is within limits of
7323 \labelwidthstring 00.00.0000
7342 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7346 Causes the linker to check if there is at minimum <Value> bytes for stack.
7349 \labelwidthstring 00.00.0000
7368 \begin_inset LatexCommand \index{-\/-pack-iram}
7372 Causes the linker to use unused register banks for data variables and pack
7373 data, idata and stack together.
7374 This is the default now.
7377 \labelwidthstring 00.00.0000
7378 \added_space_bottom bigskip
7397 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7401 Causes the linker to use old style for allocating memory areas.
7405 DS390 / DS400 Options
7406 \begin_inset LatexCommand \index{Options DS390}
7411 \begin_inset LatexCommand \index{DS390}
7418 \labelwidthstring 00.00.0000
7436 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7446 Generate 24-bit flat mode code.
7447 This is the one and only that the ds390 code generator supports right now
7448 and is default when using
7453 See section Memory Models for more details.
7456 \labelwidthstring 00.00.0000
7472 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7478 disable interrupts during ESP:SP updates.
7481 \labelwidthstring 00.00.0000
7499 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7503 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7504 This is the one and only that the ds390 code generator supports right now
7505 and is default when using
7510 In this mode, the stack is located in the lower 1K of the internal RAM,
7511 which is mapped to 0x400000.
7512 Note that the support is incomplete, since it still uses a single byte
7513 as the stack pointer.
7514 This means that only the lower 256 bytes of the potential 1K stack space
7515 will actually be used.
7516 However, this does allow you to reclaim the precious 256 bytes of low RAM
7517 for use for the DATA and IDATA segments.
7518 The compiler will not generate any code to put the processor into 10 bit
7520 It is important to ensure that the processor is in this mode before calling
7521 any re-entrant functions compiled with this option.
7522 In principle, this should work with the
7537 \begin_inset LatexCommand \index{-\/-stack-auto}
7543 option, but that has not been tested.
7544 It is incompatible with the
7559 \begin_inset LatexCommand \index{-\/-xstack}
7566 It also only makes sense if the processor is in 24 bit contiguous addressing
7581 -model-flat24 option
7586 \labelwidthstring 00.00.0000
7602 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7608 insert call to function __stack_probe at each function prologue.
7611 \labelwidthstring 00.00.0000
7627 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7633 <nnnn> LibraryID used in -mTININative.
7637 \labelwidthstring 00.00.0000
7638 \added_space_bottom bigskip
7654 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7660 generate code for DS390 Arithmetic Accelerator.
7666 \begin_inset LatexCommand \index{Options Z80}
7671 \begin_inset LatexCommand \index{Z80}
7678 \labelwidthstring 00.00.0000
7696 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7706 Force a called function to always save BC.
7709 \labelwidthstring 00.00.0000
7710 \added_space_bottom bigskip
7728 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7732 When linking, skip the standard crt0.o object file.
7733 You must provide your own crt0.o for your system when linking.
7738 Optimization Options
7739 \begin_inset LatexCommand \index{Options optimization}
7744 \begin_inset LatexCommand \index{Optimization options}
7751 \labelwidthstring 00.00.0000
7767 \begin_inset LatexCommand \index{-\/-nogcse}
7773 Will not do global subexpression elimination, this option may be used when
7774 the compiler creates undesirably large stack/data spaces to store compiler
7784 \begin_inset LatexCommand \index{sloc (spill location)}
7789 A warning message will be generated when this happens and the compiler
7790 will indicate the number of extra bytes it allocated.
7791 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7793 \begin_inset LatexCommand \index{\#pragma nogcse}
7797 can be used to turn off global subexpression elimination
7798 \begin_inset LatexCommand \index{Subexpression elimination}
7802 for a given function only.
7805 \labelwidthstring 00.00.0000
7821 \begin_inset LatexCommand \index{-\/-noinvariant}
7827 Will not do loop invariant optimizations, this may be turned off for reasons
7828 explained for the previous option.
7829 For more details of loop optimizations performed see Loop Invariants in
7831 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7836 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7838 \begin_inset LatexCommand \index{\#pragma noinvariant}
7842 can be used to turn off invariant optimizations for a given function only.
7845 \labelwidthstring 00.00.0000
7861 \begin_inset LatexCommand \index{-\/-noinduction}
7867 Will not do loop induction optimizations, see section strength reduction
7869 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7871 \begin_inset LatexCommand \index{\#pragma noinduction}
7875 can be used to turn off induction optimizations for a given function only.
7878 \labelwidthstring 00.00.0000
7894 \begin_inset LatexCommand \index{-\/-nojtbound}
7905 Will not generate boundary condition check when switch statements
7906 \begin_inset LatexCommand \index{switch statement}
7910 are implemented using jump-tables.
7912 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7917 Switch Statements for more details.
7918 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7920 \begin_inset LatexCommand \index{\#pragma nojtbound}
7924 can be used to turn off boundary checking for jump tables for a given function
7928 \labelwidthstring 00.00.0000
7944 \begin_inset LatexCommand \index{-\/-noloopreverse}
7953 Will not do loop reversal
7954 \begin_inset LatexCommand \index{Loop reversing}
7961 \labelwidthstring 00.00.0000
7979 \begin_inset LatexCommand \index{-\/-nolabelopt }
7983 Will not optimize labels (makes the dumpfiles more readable).
7986 \labelwidthstring 00.00.0000
8002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8008 Will not memcpy initialized data from code space into xdata space.
8009 This saves a few bytes in code space if you don't have initialized data
8010 \begin_inset LatexCommand \index{Variable initialization}
8017 \labelwidthstring 00.00.0000
8033 \begin_inset LatexCommand \index{-\/-nooverlay}
8039 The compiler will not overlay parameters and local variables of any function,
8040 see section Parameters and local variables for more details.
8043 \labelwidthstring 00.00.0000
8059 \begin_inset LatexCommand \index{-\/-no-peep}
8065 Disable peep-hole optimization with built-in rules.
8068 \labelwidthstring 00.00.0000
8086 \begin_inset LatexCommand \index{-\/-peep-file}
8091 <filename> This option can be used to use additional rules to be used by
8092 the peep hole optimizer.
8094 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8099 Peep Hole optimizations for details on how to write these rules.
8102 \labelwidthstring 00.00.0000
8118 \begin_inset LatexCommand \index{-\/-peep-asm}
8124 Pass the inline assembler code through the peep hole optimizer.
8125 This can cause unexpected changes to inline assembler code, please go through
8126 the peephole optimizer
8127 \begin_inset LatexCommand \index{Peephole optimizer}
8131 rules defined in the source file tree '<target>/peeph.def' before using
8135 \labelwidthstring 00.00.0000
8151 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8157 The compiler will optimize code generation towards fast code, possibly
8158 at the expense of code size.
8161 \labelwidthstring 00.00.0000
8162 \added_space_bottom bigskip
8178 \begin_inset LatexCommand \index{-\/-opt-code-size}
8184 The compiler will optimize code generation towards compact code, possibly
8185 at the expense of code speed.
8190 \begin_inset LatexCommand \index{Options other}
8197 \labelwidthstring 00.00.0000
8214 \begin_inset LatexCommand \index{-\/-compile-only}
8219 \begin_inset LatexCommand \index{-c -\/-compile-only}
8225 will compile and assemble the source, but will not call the linkage editor.
8228 \labelwidthstring 00.00.0000
8248 \begin_inset LatexCommand \index{-\/-c1mode}
8254 reads the preprocessed source from standard input and compiles it.
8255 The file name for the assembler output must be specified using the -o option.
8258 \labelwidthstring 00.00.0000
8262 \begin_inset LatexCommand \index{-E}
8268 Run only the C preprocessor.
8269 Preprocess all the C source files specified and output the results to standard
8273 \labelwidthstring 00.00.0000
8278 \begin_inset LatexCommand \index{-o <path/file>}
8284 The output path resp.
8285 file where everything will be placed.
8286 If the parameter is a path, it must have a trailing slash (or backslash
8287 for the Windows binaries) to be recognized as a path.
8291 \labelwidthstring 00.00.0000
8307 \begin_inset LatexCommand \index{-\/-stack-auto}
8318 All functions in the source file will be compiled as
8323 \begin_inset LatexCommand \index{reentrant}
8328 the parameters and local variables will be allocated on the stack
8329 \begin_inset LatexCommand \index{stack}
8335 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8339 Parameters and Local Variables for more details.
8340 If this option is used all source files in the project should be compiled
8342 It automatically implies --int-long-reent and --float-reent.
8346 \labelwidthstring 00.00.0000
8362 \begin_inset LatexCommand \index{-\/-callee-saves}
8366 function1[,function2][,function3]....
8369 The compiler by default uses a caller saves convention for register saving
8370 across function calls, however this can cause unnecessary register pushing
8371 & popping when calling small functions from larger functions.
8372 This option can be used to switch the register saving convention for the
8373 function names specified.
8374 The compiler will not save registers when calling these functions, no extra
8375 code will be generated at the entry & exit (function prologue
8378 \begin_inset LatexCommand \index{function prologue}
8387 \begin_inset LatexCommand \index{function epilogue}
8393 ) for these functions to save & restore the registers used by these functions,
8394 this can SUBSTANTIALLY reduce code & improve run time performance of the
8396 In the future the compiler (with inter procedural analysis) will be able
8397 to determine the appropriate scheme to use for each function call.
8398 DO NOT use this option for built-in functions such as _mulint..., if this
8399 option is used for a library function the appropriate library function
8400 needs to be recompiled with the same option.
8401 If the project consists of multiple source files then all the source file
8402 should be compiled with the same -
8414 -callee-saves option string.
8415 Also see #pragma\SpecialChar ~
8417 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8424 \labelwidthstring 00.00.0000
8440 \begin_inset LatexCommand \index{-\/-debug}
8449 When this option is used the compiler will generate debug information.
8450 The debug information collected in a file with .cdb extension can be used
8452 For more information see documentation for SDCDB.
8453 Another file with no extension contains debug information in AOMF or AOMF51
8454 \begin_inset LatexCommand \index{AOMF, AOMF51}
8458 format which is commonly used by third party tools.
8461 \labelwidthstring 00.00.0000
8465 \begin_inset LatexCommand \index{-S}
8476 Stop after the stage of compilation proper; do not assemble.
8477 The output is an assembler code file for the input file specified.
8480 \labelwidthstring 00.00.0000
8496 \begin_inset LatexCommand \index{-\/-int-long-reent}
8502 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8503 Note by default these libraries are compiled as non-reentrant.
8504 See section Installation for more details.
8507 \labelwidthstring 00.00.0000
8523 \begin_inset LatexCommand \index{-\/-cyclomatic}
8532 This option will cause the compiler to generate an information message for
8533 each function in the source file.
8534 The message contains some
8538 information about the function.
8539 The number of edges and nodes the compiler detected in the control flow
8540 graph of the function, and most importantly the
8542 cyclomatic complexity
8543 \begin_inset LatexCommand \index{Cyclomatic complexity}
8549 see section on Cyclomatic Complexity for more details.
8552 \labelwidthstring 00.00.0000
8568 \begin_inset LatexCommand \index{-\/-float-reent}
8574 Floating point library is compiled as reentrant
8575 \begin_inset LatexCommand \index{reentrant}
8580 See section Installation for more details.
8583 \labelwidthstring 00.00.0000
8599 \begin_inset LatexCommand \index{-\/-funsigned-char}
8605 The default signedness for every type is
8609 . In some embedded enviornments the default signedness of
8617 . To set the signess for characters to unsigned, use the option --funsigned-char.
8618 If this option is set and no signedness keyword (unsigned/signed) is given, a char will be signed.
8619 All other types are unaffected.
8622 \labelwidthstring 00.00.0000
8638 \begin_inset LatexCommand \index{-\/-main-return}
8644 This option can be used if the code generated is called by a monitor program
8645 or if the main routine includes an endless loop.
8646 This option results in slightly smaller code and saves two bytes of stack
8648 The return from the 'main'
8649 \begin_inset LatexCommand \index{main return}
8653 function will return to the function calling main.
8654 The default setting is to lock up i.e.
8662 \labelwidthstring 00.00.0000
8678 \begin_inset LatexCommand \index{-\/-nostdinc}
8684 This will prevent the compiler from passing on the default include path
8685 to the preprocessor.
8688 \labelwidthstring 00.00.0000
8704 \begin_inset LatexCommand \index{-\/-nostdlib}
8710 This will prevent the compiler from passing on the default library
8711 \begin_inset LatexCommand \index{Libraries}
8718 \labelwidthstring 00.00.0000
8734 \begin_inset LatexCommand \index{-\/-verbose}
8740 Shows the various actions the compiler is performing.
8743 \labelwidthstring 00.00.0000
8747 \begin_inset LatexCommand \index{-V}
8753 Shows the actual commands the compiler is executing.
8756 \labelwidthstring 00.00.0000
8772 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8778 Hides your ugly and inefficient c-code from the asm file, so you can always
8779 blame the compiler :)
8782 \labelwidthstring 00.00.0000
8798 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8804 Will not include peep-hole comments in the generated files.
8807 \labelwidthstring 00.00.0000
8823 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8829 Include i-codes in the asm file.
8830 Sounds like noise but is most helpful for debugging the compiler itself.
8833 \labelwidthstring 00.00.0000
8849 \begin_inset LatexCommand \index{-\/-less-pedantic}
8855 Disable some of the more pedantic warnings
8856 \begin_inset LatexCommand \index{Warnings}
8860 (jwk burps: please be more specific here, please!).
8863 \labelwidthstring 00.00.0000
8878 -disable-warning\SpecialChar ~
8880 \begin_inset LatexCommand \index{-\/-disable-warning}
8886 Disable specific warning with number <nnnn>.
8889 \labelwidthstring 00.00.0000
8905 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8911 Display the directories in the compiler's search path
8914 \labelwidthstring 00.00.0000
8930 \begin_inset LatexCommand \index{-\/-vc}
8936 Display errors and warnings using MSVC style, so you can use SDCC with
8937 the visual studio IDE
8938 \begin_inset LatexCommand \index{IDE}
8943 With SDCC both offering a GCC-like (the default) and a MSVC-like
8944 \begin_inset LatexCommand \index{MSVC output style}
8948 output style, integration into most programming editors should be straightforwa
8952 \labelwidthstring 00.00.0000
8968 \begin_inset LatexCommand \index{-\/-use-stdout}
8974 Send errors and warnings to stdout instead of stderr.
8977 \labelwidthstring 00.00.0000
8981 asmOption[,asmOption]
8984 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8989 Pass the asmOption to the assembler
8990 \begin_inset LatexCommand \index{Options assembler}
8995 \begin_inset LatexCommand \index{Assembler options}
9000 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9003 \labelwidthstring 00.00.0000
9019 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9025 Generally follow the C89 standard, but allow SDCC features that conflict
9026 with the standard (default).
9029 \labelwidthstring 00.00.0000
9045 \begin_inset LatexCommand \index{-\/-std-c89}
9051 Follow the C89 standard and disable SDCC features that conflict with the
9055 \labelwidthstring 00.00.0000
9071 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9077 Generally follow the C99 standard, but allow SDCC features that conflict
9078 with the standard (incomplete support).
9081 \labelwidthstring 00.00.0000
9097 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9103 Follow the C99 standard and disable SDCC features that conflict with the
9104 standard (incomplete support).
9107 \labelwidthstring 00.00.0000
9125 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9130 <Name> The name to be used for the code
9131 \begin_inset LatexCommand \index{code}
9135 segment, default CSEG.
9136 This is useful if you need to tell the compiler to put the code in a special
9137 segment so you can later on tell the linker to put this segment in a special
9139 Can be used for instance when using bank switching to put the code in a
9143 \labelwidthstring 00.00.0000
9161 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9166 <Name> The name to be used for the const
9167 \begin_inset LatexCommand \index{code}
9171 segment, default CONST.
9172 This is useful if you need to tell the compiler to put the const data in
9173 a special segment so you can later on tell the linker to put this segment
9174 in a special place in memory.
9175 Can be used for instance when using bank switching to put the const data
9179 \labelwidthstring 00.00.0000
9194 -fdollars-in-identifiers
9195 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9201 Permit '$' as an identifier character
9204 \labelwidthstring 00.00.0000
9205 \added_space_bottom bigskip
9216 a SDCC compiler option but if you want
9220 warnings you can use a separate tool dedicated to syntax checking like
9222 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9227 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9232 \begin_inset LatexCommand \url{http://www.splint.org}
9237 To make your source files parseable by splint you will have to include
9243 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9247 in your source file and add brackets around extended keywords (like
9250 \begin_inset Quotes sld
9263 \begin_inset Quotes srd
9271 \begin_inset Quotes sld
9274 __interrupt\SpecialChar ~
9276 \begin_inset Quotes srd
9284 Splint has an excellent on line manual at
9285 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9289 and it's capabilities go beyond pure syntax checking.
9290 You'll need to tell splint the location of SDCC's include files so a typical
9291 command line could look like this:
9295 splint\SpecialChar ~
9297 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9303 Intermediate Dump Options
9304 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9309 \begin_inset LatexCommand \index{Options intermediate dump}
9314 \begin_inset LatexCommand \index{Intermediate dump options}
9321 The following options are provided for the purpose of retargetting and debugging
9323 They provide a means to dump the intermediate code (iCode
9324 \begin_inset LatexCommand \index{iCode}
9328 ) generated by the compiler in human readable form at various stages of
9329 the compilation process.
9330 More on iCodes see chapter
9331 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9336 \begin_inset Quotes srd
9339 The anatomy of the compiler
9340 \begin_inset Quotes srd
9346 \labelwidthstring 00.00.0000
9362 \begin_inset LatexCommand \index{-\/-dumpraw}
9368 This option will cause the compiler to dump the intermediate code into
9371 <source filename>.dumpraw
9373 just after the intermediate code has been generated for a function, i.e.
9374 before any optimizations are done.
9376 \begin_inset LatexCommand \index{Basic blocks}
9380 at this stage ordered in the depth first number, so they may not be in
9381 sequence of execution.
9384 \labelwidthstring 00.00.0000
9400 \begin_inset LatexCommand \index{-\/-dumpgcse}
9406 Will create a dump of iCode's, after global subexpression elimination
9407 \begin_inset LatexCommand \index{Global subexpression elimination}
9413 <source filename>.dumpgcse.
9416 \labelwidthstring 00.00.0000
9432 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9438 Will create a dump of iCode's, after deadcode elimination
9439 \begin_inset LatexCommand \index{Dead-code elimination}
9445 <source filename>.dumpdeadcode.
9448 \labelwidthstring 00.00.0000
9464 \begin_inset LatexCommand \index{-\/-dumploop}
9473 Will create a dump of iCode's, after loop optimizations
9474 \begin_inset LatexCommand \index{Loop optimization}
9480 <source filename>.dumploop.
9483 \labelwidthstring 00.00.0000
9499 \begin_inset LatexCommand \index{-\/-dumprange}
9508 Will create a dump of iCode's, after live range analysis
9509 \begin_inset LatexCommand \index{Live range analysis}
9515 <source filename>.dumprange.
9518 \labelwidthstring 00.00.0000
9534 \begin_inset LatexCommand \index{-\/-dumlrange}
9540 Will dump the life ranges
9541 \begin_inset LatexCommand \index{Live range analysis}
9548 \labelwidthstring 00.00.0000
9564 \begin_inset LatexCommand \index{-\/-dumpregassign}
9573 Will create a dump of iCode's, after register assignment
9574 \begin_inset LatexCommand \index{Register assignment}
9580 <source filename>.dumprassgn.
9583 \labelwidthstring 00.00.0000
9599 \begin_inset LatexCommand \index{-\/-dumplrange}
9605 Will create a dump of the live ranges of iTemp's
9608 \labelwidthstring 00.00.0000
9609 \added_space_bottom bigskip
9625 \begin_inset LatexCommand \index{-\/-dumpall}
9636 Will cause all the above mentioned dumps to be created.
9640 Redirecting output on Windows Shells
9643 \added_space_bottom bigskip
9644 By default SDCC writes it's error messages to
9645 \begin_inset Quotes sld
9649 \begin_inset Quotes srd
9653 To force all messages to
9654 \begin_inset Quotes sld
9658 \begin_inset Quotes srd
9684 \begin_inset LatexCommand \index{-\/-use-stdout}
9689 Additionally, if you happen to have visual studio installed in your windows
9690 machine, you can use it to compile your sources using a custom build and
9708 \begin_inset LatexCommand \index{-\/-vc}
9713 Something like this should work:
9761 -model-large -c $(InputPath)
9768 Environment variables
9769 \begin_inset LatexCommand \index{Environment variables}
9776 SDCC recognizes the following environment variables:
9779 \labelwidthstring 00.00.0000
9783 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9789 SDCC installs a signal handler
9790 \begin_inset LatexCommand \index{signal handler}
9794 to be able to delete temporary files after an user break (^C) or an exception.
9795 If this environment variable is set, SDCC won't install the signal handler
9796 in order to be able to debug SDCC.
9799 \labelwidthstring 00.00.0000
9805 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9811 Path, where temporary files will be created.
9812 The order of the variables is the search order.
9813 In a standard *nix environment these variables are not set, and there's
9814 no need to set them.
9815 On Windows it's recommended to set one of them.
9818 \labelwidthstring 00.00.0000
9822 \begin_inset LatexCommand \index{SDCC\_HOME}
9829 \begin_inset LatexCommand \ref{sub:Install-paths}
9835 \begin_inset Quotes sld
9839 \begin_inset Quotes srd
9845 \labelwidthstring 00.00.0000
9849 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9856 \begin_inset LatexCommand \ref{sub:Search-Paths}
9862 \begin_inset Quotes sld
9866 \begin_inset Quotes srd
9872 \labelwidthstring 00.00.0000
9876 \begin_inset LatexCommand \index{SDCC\_LIB}
9883 \begin_inset LatexCommand \ref{sub:Search-Paths}
9889 \begin_inset Quotes sld
9893 \begin_inset Quotes srd
9899 \added_space_bottom bigskip
9900 There are some more environment variables recognized by SDCC, but these
9901 are solely used for debugging purposes.
9902 They can change or disappear very quickly, and will never be documented.
9907 Storage Class Language Extensions
9910 MCS51/DS390 Storage Class
9911 \begin_inset LatexCommand \index{Storage class}
9918 In addition to the ANSI storage classes SDCC allows the following MCS51
9919 specific storage classes:
9921 \layout Subsubsection
9923 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9928 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9933 \begin_inset LatexCommand \index{near (storage class)}
9938 \begin_inset LatexCommand \index{\_\_near (storage class)}
9949 storage class for the Small Memory model (
9957 or the more ANSI-C compliant forms
9965 can be used synonymously).
9966 Variables declared with this storage class will be allocated in the directly
9967 addressable portion of the internal RAM of a 8051, e.g.:
9972 __data unsigned char test_data;
9975 Writing 0x01 to this variable generates the assembly code:
9980 75*00 01\SpecialChar ~
9987 \layout Subsubsection
9989 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9994 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9999 \begin_inset LatexCommand \index{far (storage class)}
10004 \begin_inset LatexCommand \index{\_\_far (storage class)}
10011 Variables declared with this storage class will be placed in the external
10017 storage class for the Large Memory model, e.g.:
10022 __xdata unsigned char test_xdata;
10025 Writing 0x01 to this variable generates the assembly code:
10030 90s00r00\SpecialChar ~
10060 \layout Subsubsection
10062 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10067 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10074 Variables declared with this storage class will be allocated into the indirectly
10075 addressable portion of the internal ram of a 8051, e.g.:
10080 __idata unsigned char test_idata;
10083 Writing 0x01 to this variable generates the assembly code:
10088 78r00\SpecialChar ~
10112 Please note, the first 128 byte of idata physically access the same RAM
10113 as the data memory.
10114 The original 8051 had 128 byte idata memory, nowadays most devices have
10115 256 byte idata memory.
10117 \begin_inset LatexCommand \index{stack}
10121 is located in idata memory.
10123 \layout Subsubsection
10125 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10130 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10137 Paged xdata access is just as straightforward as using the other addressing
10139 It is typically located at the start of xdata and has a maximum size of
10141 The following example writes 0x01 to the pdata variable.
10142 Please note, pdata access physically accesses xdata memory.
10143 The high byte of the address is determined by port P2
10144 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10148 (or in case of some 8051 variants by a separate Special Function Register,
10150 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10159 storage class for the Medium Memory model, e.g.:
10164 __pdata unsigned char test_pdata;
10167 Writing 0x01 to this variable generates the assembly code:
10172 78r00\SpecialChar ~
10178 mov r0,#_test_pdata
10180 74 01\SpecialChar ~
10213 \begin_inset LatexCommand \index{-\/-xstack}
10217 option is used the pdata memory area is followed by the xstack memory area
10218 and the sum of their sizes is limited to 256 bytes.
10220 \layout Subsubsection
10222 \begin_inset LatexCommand \index{code}
10227 \begin_inset LatexCommand \index{\_\_code}
10234 'Variables' declared with this storage class will be placed in the code
10240 __code unsigned char test_code;
10243 Read access to this variable generates the assembly code:
10248 90s00r6F\SpecialChar ~
10251 mov dptr,#_test_code
10280 indexed arrays of characters in code memory can be accessed efficiently:
10285 __code char test_array[] = {'c','h','e','a','p'};
10288 Read access to this array using an 8-bit unsigned index generates the assembly
10294 E5*00\SpecialChar ~
10305 90s00r41\SpecialChar ~
10308 mov dptr,#_test_array
10324 \layout Subsubsection
10326 \begin_inset LatexCommand \index{bit}
10331 \begin_inset LatexCommand \index{\_\_bit}
10338 This is a data-type and a storage class specifier.
10339 When a variable is declared as a bit, it is allocated into the bit addressable
10340 memory of 8051, e.g.:
10348 Writing 1 to this variable generates the assembly code:
10353 D2*00\SpecialChar ~
10364 The bit addressable memory consists of 128 bits which are located from 0x20
10365 to 0x2f in data memory.
10368 Apart from this 8051 specific storage class most architectures support
10370 \begin_inset LatexCommand \index{bitfields}
10379 Not really meant as examples, but nevertheless showing what bitfields are
10380 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10385 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10386 signed modifier are implemented as unsigned.
10388 \layout Subsubsection
10390 \begin_inset LatexCommand \index{sfr}
10395 \begin_inset LatexCommand \index{\_\_sfr}
10400 \begin_inset LatexCommand \index{sfr16}
10405 \begin_inset LatexCommand \index{\_\_sfr16}
10410 \begin_inset LatexCommand \index{sfr32}
10415 \begin_inset LatexCommand \index{\_\_sfr32}
10420 \begin_inset LatexCommand \index{\_\_sbit}
10425 \begin_inset LatexCommand \index{sbit}
10432 Like the bit keyword,
10434 sfr / sfr16 / sfr32 / sbit
10436 signify both a data-type and storage class, they are used to describe the
10457 variables of a 8051, eg:
10463 \begin_inset LatexCommand \index{at}
10468 \begin_inset LatexCommand \index{\_\_at}
10472 (0x80) P0;\SpecialChar ~
10473 /* special function register P0 at location 0x80 */
10478 special function register combination for timer 0
10482 with the high byte at
10483 location 0x8C and the low byte at location 0x8A */
10485 __sfr16 __at (0x8C8A)
10491 \begin_inset LatexCommand \index{at}
10496 \begin_inset LatexCommand \index{\_\_at}
10500 (0xd7) CY;\SpecialChar ~
10502 \begin_inset LatexCommand \index{Flags}
10507 \begin_inset LatexCommand \index{Carry flag}
10514 Special function registers which are located on an address dividable by
10515 8 are bit-addressable, an
10519 addresses a specific bit within these sfr.
10521 16 Bit and 32 bit special function
10522 register combinations which require a certain access order are better not
10532 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10533 this is not guaranteed.
10538 Please note, if you use a header file which was written for another compiler
10539 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10545 Specifically the syntax
10548 sfr P0 = 0x80;\SpecialChar ~
10555 by SDCC to an assignment of 0x80 to a variable called P0
10558 \begin_inset Marginal
10572 Nevertheless it is possible to write header files
10573 \begin_inset LatexCommand \index{Header files}
10578 \begin_inset LatexCommand \index{Include files}
10582 which can be shared among different compilers (see section
10583 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10590 \layout Subsubsection
10592 \begin_inset LatexCommand \index{Pointer}
10596 to MCS51/DS390 specific memory spaces
10599 SDCC allows (via language extensions) pointers to explicitly point to any
10600 of the memory spaces
10601 \begin_inset LatexCommand \index{Memory model}
10606 In addition to the explicit pointers, the compiler uses (by default) generic
10607 pointers which can be used to point to any of the memory spaces.
10612 declaration examples:
10617 /* pointer physically in internal ram pointing to object in external ram
10620 __xdata unsigned char * __data p;
10624 /* pointer physically in external ram
10625 pointing to object in internal ram */
10627 __data unsigned char * __xdata p;
10632 pointer physically in code rom pointing to data in xdata space */
10635 unsigned char * __code p;
10639 /* pointer physically in code space pointing to
10640 data in code space */
10642 __code unsigned char * __code p;
10647 physically located in xdata space */
10649 unsigned char * __xdata p;
10654 pointer physically located in default memory space */
10661 the following is a function pointer
10662 \begin_inset LatexCommand \index{function pointer}
10666 physically located in data space */
10668 char (* __data fp)(void);
10671 Well you get the idea.
10676 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10689 The highest order byte of the
10693 pointers contains the data space information.
10694 Assembler support routines are called whenever data is stored or retrieved
10700 These are useful for developing reusable library
10701 \begin_inset LatexCommand \index{Libraries}
10706 Explicitly specifying the pointer
10707 \begin_inset LatexCommand \index{pointer}
10711 type will generate the most efficient code.
10713 \layout Subsubsection
10714 Notes on MCS51 memory
10715 \begin_inset LatexCommand \index{MCS51 memory}
10722 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10723 RAM memory which is structured as follows:
10727 - Bytes 00-1F - 32 bytes to hold
10728 up to 4 banks of the registers R0 to R7,
10730 - Bytes 20-2F - 16 bytes to hold
10732 \begin_inset LatexCommand \index{bit}
10738 - Bytes 30-7F - 80 bytes for general purpose use.
10743 Additionally some members of the MCS51 family may have up to 128 bytes of
10744 additional, indirectly addressable, internal RAM memory (
10749 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10754 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10759 Furthermore, some chips may have some built in external memory (
10764 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10769 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10773 ) which should not be confused with the internal, directly addressable RAM
10779 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10784 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10789 Sometimes this built in
10793 memory has to be activated before using it (you can probably find this
10794 information on the datasheet of the microcontroller your are using, see
10796 \begin_inset LatexCommand \ref{sub:Startup-Code}
10804 Normally SDCC will only use the first bank
10805 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10809 of registers (register bank 0), but it is possible to specify that other
10810 banks of registers (keyword
10817 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10822 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10828 ) should be used in interrupt
10829 \begin_inset LatexCommand \index{interrupt}
10834 \begin_inset LatexCommand \index{\_\_interrupt}
10839 By default, the compiler will place the stack after the last byte of allocated
10840 memory for variables.
10841 For example, if the first 2 banks of registers are used, and only four
10846 variables, it will position the base of the internal stack at address 20
10848 This implies that as the stack
10849 \begin_inset LatexCommand \index{stack}
10853 grows, it will use up the remaining register banks, and the 16 bytes used
10854 by the 128 bit variables, and 80 bytes for general purpose use.
10855 If any bit variables are used, the data variables will be placed in unused
10856 register banks and after the byte holding the last bit variable.
10857 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10862 variables will be placed starting from address 0x10 to 0x20 and continue
10877 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10881 to specify the start address of the
10898 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10902 to specify the size of the total internal RAM (
10916 By default the 8051 linker will place the stack after the last byte of (i)data
10931 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10935 allows you to specify the start of the stack, i.e.
10936 you could start it after any data in the general purpose area.
10937 If your microcontroller has additional indirectly addressable internal
10942 ) you can place the stack on it.
10943 You may also need to use -
10956 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10960 to set the start address of the external RAM (
10977 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10981 to specify its size.
10982 Same goes for the code memory, using -
10995 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11012 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11017 If in doubt, don't specify any options and see if the resulting memory
11018 layout is appropriate, then you can adjust it.
11021 \added_space_bottom bigskip
11022 The linker generates two files with memory allocation information.
11023 The first, with extension .map
11024 \begin_inset LatexCommand \index{<file>.map}
11028 shows all the variables and segments.
11029 The second with extension .mem
11030 \begin_inset LatexCommand \index{<file>.mem}
11034 shows the final memory layout.
11035 The linker will complain either if memory segments overlap, there is not
11036 enough memory, or there is not enough space for stack.
11037 If you get any linking warnings and/or errors related to stack or segments
11038 allocation, take a look at either the .map or .mem files to find out what
11040 The .mem file may even suggest a solution to the problem.
11045 Z80/Z180 Storage Class
11046 \begin_inset LatexCommand \index{Z80!Storage class}
11050 Language Extensions
11052 \layout Subsubsection
11054 \begin_inset LatexCommand \index{sfr}
11059 \begin_inset LatexCommand \index{\_\_sfr}
11063 (in/out to 8-bit addresses)
11067 \begin_inset LatexCommand \index{Z80}
11071 family has separate address spaces for memory and
11081 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11086 \begin_inset LatexCommand \index{Z80!I/O memory}
11091 \begin_inset LatexCommand \index{Z180!I/O memory}
11095 is accessed with special instructions, e.g.:
11100 sfr at 0x78 IoPort;\SpecialChar ~
11102 /* define a var in I/O space at 78h called IoPort */
11106 Writing 0x01 to this variable generates the assembly code:
11111 3E 01\SpecialChar ~
11119 D3 78\SpecialChar ~
11127 \layout Subsubsection
11129 \begin_inset LatexCommand \index{sfr}
11134 \begin_inset LatexCommand \index{\_\_sfr}
11138 (in/out to 16-bit addresses)
11145 is used to support 16 bit addresses in I/O memory e.g.:
11151 \begin_inset LatexCommand \index{at}
11156 \begin_inset LatexCommand \index{\_\_at}
11163 Writing 0x01 to this variable generates the assembly code:
11168 01 23 01\SpecialChar ~
11173 3E 01\SpecialChar ~
11181 ED 79\SpecialChar ~
11189 \layout Subsubsection
11191 \begin_inset LatexCommand \index{sfr}
11196 \begin_inset LatexCommand \index{\_\_sfr}
11200 (in0/out0 to 8 bit addresses on Z180
11201 \begin_inset LatexCommand \index{Z180}
11206 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11213 \added_space_bottom bigskip
11214 The compiler option -
11227 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11231 =180 (80) and a compiler #pragma\SpecialChar ~
11233 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11237 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11247 If you include the file z180.h this will be set automatically.
11253 \begin_inset LatexCommand \index{HC08!Storage class}
11257 Language Extensions
11259 \layout Subsubsection
11261 \begin_inset LatexCommand \index{data (hc08 storage class)}
11266 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11273 The data storage class declares a variable that resides in the first 256
11274 bytes of memory (the direct page).
11276 \begin_inset LatexCommand \index{HC08}
11280 is most efficient at accessing variables (especially pointers) stored here.
11282 \layout Subsubsection
11284 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11289 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11296 \added_space_bottom bigskip
11297 The xdata storage class declares a variable that can reside anywhere in
11299 This is the default if no storage class is specified.
11305 Absolute Addressing
11306 \begin_inset LatexCommand \index{Absolute addressing}
11313 Data items can be assigned an absolute address with the
11316 \begin_inset LatexCommand \index{at}
11321 \begin_inset LatexCommand \index{\_\_at}
11327 keyword, in addition to a storage class, e.g.:
11333 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11338 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11343 \begin_inset LatexCommand \index{at}
11348 \begin_inset LatexCommand \index{\_\_at}
11352 0x7ffe unsigned int chksum;
11355 or, better conforming to ISO/IEC 9899 C:
11360 __xdata __at (0x7ffe) unsigned int chksum;
11363 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11364 of the external ram.
11369 reserve any space for variables declared in this way
11370 \begin_inset Marginal
11381 (they are implemented with an equate in the assembler).
11382 Thus it is left to the programmer to make sure there are no overlaps with
11383 other variables that are declared without the absolute address.
11384 The assembler listing file (.lst
11385 \begin_inset LatexCommand \index{<file>.lst}
11389 ) and the linker output files (.rst
11390 \begin_inset LatexCommand \index{<file>.rst}
11395 \begin_inset LatexCommand \index{<file>.map}
11399 ) are good places to look for such overlaps.
11400 Variables with an absolute address are
11403 \begin_inset Marginal
11417 \begin_inset LatexCommand \index{Variable initialization}
11424 In case of memory mapped I/O devices the keyword
11428 has to be used to tell the compiler that accesses might not be removed:
11434 \begin_inset LatexCommand \index{volatile}
11439 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11444 \begin_inset LatexCommand \index{at}
11448 (0x8000) unsigned char PORTA_8255;
11451 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11456 \begin_inset LatexCommand \index{Aligned array}
11463 starts at a block (256 byte) boundary
11464 \begin_inset LatexCommand \index{block boundary}
11469 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11475 Absolute addresses can be specified for variables in all
11476 storage classes, e.g.:
11482 \begin_inset LatexCommand \index{bit}
11487 \begin_inset LatexCommand \index{at}
11494 The above example will allocate the variable at offset 0x02 in the bit-addressab
11496 There is no real advantage to assigning absolute addresses to variables
11497 in this manner, unless you want strict control over all the variables allocated.
11498 One possible use would be to write hardware portable code.
11499 For example, if you have a routine that uses one or more of the microcontroller
11500 I/O pins, and such pins are different for two different hardwares, you
11501 can declare the I/O pins in your routine using:
11507 \begin_inset LatexCommand \index{volatile}
11511 __bit MOSI;\SpecialChar ~
11515 /* master out, slave in */
11517 extern volatile __bit MISO;\SpecialChar ~
11524 extern volatile __bit MCLK;\SpecialChar ~
11533 Output of a byte on a 3-wire serial bus.
11538 If needed adapt polarity of clock,
11539 polarity of data and bit order
11544 unsigned char spi_io(unsigned char out_byte)
11569 MOSI = out_byte & 0x80;
11600 /* _asm nop _endasm; */\SpecialChar ~
11608 /* for slow peripherals */
11660 Then, someplace in the code for the first hardware you would use
11666 \begin_inset LatexCommand \index{at}
11671 \begin_inset LatexCommand \index{\_\_at}
11675 (0x80) MOSI;\SpecialChar ~
11679 /* I/O port 0, bit 0 */
11681 __bit __at (0x81) MISO;\SpecialChar ~
11688 __bit __at (0x82) MCLK;\SpecialChar ~
11692 /* I/O port 0, bit 2 */
11695 Similarly, for the second hardware you would use
11700 __bit __at (0x83) MOSI;\SpecialChar ~
11704 /* I/O port 0, bit 3 */
11706 __bit __at (0x91) MISO;\SpecialChar ~
11711 I/O port 1, bit 1 */
11714 \begin_inset LatexCommand \index{bit}
11718 __at (0x92) MCLK;\SpecialChar ~
11722 /* I/O port 1, bit 2 */
11725 \added_space_bottom bigskip
11726 and you can use the same hardware dependent routine without changes, as
11727 for example in a library.
11728 This is somehow similar to sbit, but only one absolute address has to be
11729 specified in the whole project.
11735 \begin_inset LatexCommand \index{Parameters}
11740 \begin_inset LatexCommand \index{function parameter}
11745 \begin_inset LatexCommand \index{local variables}
11750 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11757 Automatic (local) variables and parameters to functions can either be placed
11758 on the stack or in data-space.
11759 The default action of the compiler is to place these variables in the internal
11760 RAM (for small model) or external RAM (for large model).
11761 This in fact makes them similar to
11764 \begin_inset LatexCommand \index{static}
11770 so by default functions are non-reentrant
11771 \begin_inset LatexCommand \index{reentrant}
11780 They can be placed on the stack
11781 \begin_inset LatexCommand \index{stack}
11800 \begin_inset LatexCommand \index{-\/-stack-auto}
11808 #pragma\SpecialChar ~
11812 \begin_inset LatexCommand \index{\#pragma stackauto}
11819 \begin_inset LatexCommand \index{reentrant}
11825 keyword in the function declaration, e.g.:
11830 unsigned char foo(char i) __reentrant
11844 Since stack space on 8051 is limited, the
11864 option should be used sparingly.
11865 Note that the reentrant keyword just means that the parameters & local
11866 variables will be allocated to the stack, it
11870 mean that the function is register bank
11871 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11880 \begin_inset LatexCommand \index{local variables}
11884 can be assigned storage classes and absolute
11885 \begin_inset LatexCommand \index{Absolute addressing}
11894 unsigned char foo()
11902 __xdata unsigned char i;
11915 \begin_inset LatexCommand \index{at}
11919 (0x31) unsigned char j;
11931 In the above example the variable
11935 will be allocated in the external ram,
11939 in bit addressable space and
11960 or when a function is declared as
11964 this should only be done for static variables.
11968 \begin_inset LatexCommand \index{function parameter}
11972 however are not allowed any storage class
11973 \begin_inset LatexCommand \index{Storage class}
11977 , (storage classes for parameters will be ignored), their allocation is
11978 governed by the memory model in use, and the reentrancy options.
11981 It is however allowed to use bit parameters in reentrant functions and also
11982 non-static local bit variables are supported.
11983 Efficient use is limited to 8 semi-bitregisters in bit space.
11984 They are pushed and popped to stack
11985 \begin_inset LatexCommand \index{stack}
11989 as a single byte just like the normal registers.
11993 \begin_inset LatexCommand \label{sub:Overlaying}
11998 \begin_inset LatexCommand \index{Overlaying}
12006 \begin_inset LatexCommand \index{reentrant}
12010 functions SDCC will try to reduce internal ram space usage by overlaying
12011 parameters and local variables of a function (if possible).
12012 Parameters and local variables
12013 \begin_inset LatexCommand \index{local variables}
12017 of a function will be allocated to an overlayable segment if the function
12020 no other function calls and the function is non-reentrant and the memory
12022 \begin_inset LatexCommand \index{Memory model}
12029 If an explicit storage class
12030 \begin_inset LatexCommand \index{Storage class}
12034 is specified for a local variable, it will NOT be overlayed.
12037 Note that the compiler (not the linkage editor) makes the decision for overlayin
12039 Functions that are called from an interrupt service routine
12040 \begin_inset Marginal
12050 should be preceded by a #pragma\SpecialChar ~
12052 \begin_inset LatexCommand \index{\#pragma nooverlay}
12056 if they are not reentrant.
12059 Also note that the compiler does not do any processing of inline assembler
12060 code, so the compiler might incorrectly assign local variables and parameters
12061 of a function into the overlay segment if the inline assembler code calls
12062 other c-functions that might use the overlay.
12063 In that case the #pragma\SpecialChar ~
12064 nooverlay should be used.
12067 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12069 \begin_inset LatexCommand \index{Multiplication}
12074 \begin_inset LatexCommand \index{Division}
12078 will NOT be overlayed since these are implemented using external functions,
12087 \begin_inset LatexCommand \index{\#pragma nooverlay}
12093 void set_error(unsigned char errcd)
12110 some_isr () __interrupt
12111 \begin_inset LatexCommand \index{interrupt}
12141 \added_space_bottom bigskip
12142 In the above example the parameter
12150 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12152 not present, this could cause unpredictable runtime behavior when called
12153 from an interrupt service routine.
12154 The #pragma\SpecialChar ~
12155 nooverlay ensures that the parameters and local variables for
12156 the function are NOT overlayed.
12161 Interrupt Service Routines
12162 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12169 General Information
12184 outines to be coded in C, with some extended keywords.
12189 void timer_isr (void) __interrupt (1) __using (1)
12203 The optional number following the
12206 \begin_inset LatexCommand \index{interrupt}
12211 \begin_inset LatexCommand \index{\_\_interrupt}
12217 keyword is the interrupt number this routine will service.
12218 When present, the compiler will insert a call to this routine in the interrupt
12220 \begin_inset LatexCommand \index{interrupt vector table}
12224 for the interrupt number specified.
12225 If you have multiple source files in your project, interrupt service routines
12226 can be present in any of them, but a prototype of the isr MUST be present
12227 or included in the file that contains the function
12232 The optional (8051 specific) keyword
12235 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12240 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12246 can be used to tell the compiler to use the specified register bank when
12247 generating code for this function.
12250 Interrupt service routines open the door for some very interesting bugs:
12252 \layout Subsubsection
12253 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12257 Common interrupt pitfall: variable not declared
12262 If an interrupt service routine changes variables which are accessed by
12263 other functions these variables have to be declared
12268 \begin_inset LatexCommand \index{volatile}
12274 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12280 \layout Subsubsection
12281 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12285 Common interrupt pitfall:
12290 If the access to these variables is not
12293 \begin_inset LatexCommand \index{atomic}
12300 the processor needs more than one instruction for the access and could
12301 be interrupted while accessing the variable) the interrupt must be disabled
12302 during the access to avoid inconsistent data.
12305 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12306 and should be protected by disabling interrupts.
12307 You're not automatically on the safe side if you use 8 bit variables though.
12308 We need an example here: f.e.
12309 on the 8051 the harmless looking
12310 \begin_inset Quotes srd
12315 flags\SpecialChar ~
12320 \begin_inset Quotes sld
12329 \begin_inset Quotes srd
12334 flags\SpecialChar ~
12339 \begin_inset Quotes sld
12342 from within an interrupt routine might get lost if the interrupt occurs
12345 \begin_inset Quotes sld
12350 counter\SpecialChar ~
12355 \begin_inset Quotes srd
12358 is not atomic on the 8051 even if
12362 is located in data memory.
12364 Bugs like these are hard to reproduce and can
12365 cause a lot of trouble.
12368 \layout Subsubsection
12369 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12373 Common interrupt pitfall:
12378 The return address and the registers used in the interrupt service routine
12379 are saved on the stack
12380 \begin_inset LatexCommand \index{stack}
12384 so there must be sufficient stack space.
12385 If there isn't variables or registers (or even the return address itself)
12392 \begin_inset LatexCommand \index{stack overflow}
12396 is most likely to happen if the interrupt occurs during the
12397 \begin_inset Quotes sld
12401 \begin_inset Quotes srd
12404 subroutine when the stack is already in use for f.e.
12405 many return addresses.
12407 \layout Subsubsection
12408 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12412 Common interrupt pitfall:
12414 use of non-reentrant functions
12417 A special note here, int (16 bit) and long (32 bit) integer division
12418 \begin_inset LatexCommand \index{Division}
12423 \begin_inset LatexCommand \index{Multiplication}
12428 \begin_inset LatexCommand \index{Modulus}
12433 \begin_inset LatexCommand \index{Floating point support}
12437 operations are implemented using external support routines.
12438 If an interrupt service routine needs to do any of these operations then
12439 the support routines (as mentioned in a following section) will have to
12440 be recompiled using the
12455 \begin_inset LatexCommand \index{-\/-stack-auto}
12461 option and the source file will need to be compiled using the
12478 \begin_inset LatexCommand \index{-\/-int-long-reent}
12485 Note, the type promotion
12486 \begin_inset LatexCommand \index{type promotion}
12490 required by ANSI C can cause 16 bit routines to be used
12491 \begin_inset Marginal
12502 without the programmer being aware of it.
12506 (unsigned char)(tail-1)
12508 within the if clause in section
12509 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12516 \added_space_bottom bigskip
12517 Calling other functions from an interrupt service routine is not recommended,
12518 avoid it if possible.
12519 Note that when some function is called from an interrupt service routine
12520 it should be preceded by a #pragma\SpecialChar ~
12522 \begin_inset LatexCommand \index{\#pragma nooverlay}
12526 if it is not reentrant.
12527 Furthermore nonreentrant functions should not be called from the main program
12528 while the interrupt service routine might be active.
12529 They also must not be called from low priority interrupt service routines
12530 while a high priority interrupt service routine might be active.
12531 You could use semaphores or make the function
12535 if all parameters are passed in registers.
12538 \begin_inset LatexCommand \ref{sub:Overlaying}
12543 about Overlaying and section
12544 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12549 about Functions using private register banks.
12554 MCS51/DS390 Interrupt Service Routines
12558 \begin_inset LatexCommand \index{interrupt}
12562 numbers and the corresponding address & descriptions for the Standard 8051/8052
12564 SDCC will automatically adjust the
12565 \begin_inset LatexCommand \index{interrupt vector table}
12569 to the maximum interrupt number specified.
12575 \begin_inset Tabular
12576 <lyxtabular version="3" rows="9" columns="3">
12578 <column alignment="center" valignment="top" leftline="true" width="0in">
12579 <column alignment="left" valignment="top" leftline="true" width="0in">
12580 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12581 <row topline="true" bottomline="true">
12582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12607 <row topline="true">
12608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12633 <row topline="true">
12634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12659 <row topline="true">
12660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12685 <row topline="true">
12686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12711 <row topline="true">
12712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12737 <row topline="true">
12738 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12763 <row topline="true">
12764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12789 <row topline="true" bottomline="true">
12790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12824 If the interrupt service routine is defined without
12827 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12832 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12838 a register bank or with register bank 0 (
12842 0), the compiler will save the registers used by itself on the stack upon
12843 entry and restore them at exit, however if such an interrupt service routine
12844 calls another function then the entire register bank will be saved on the
12846 This scheme may be advantageous for small interrupt service routines which
12847 have low register usage.
12850 \added_space_bottom bigskip
12851 If the interrupt service routine is defined to be using a specific register
12856 & psw are saved and restored, if such an interrupt service routine calls
12857 another function (using another register bank) then the entire register
12858 bank of the called function will be saved on the stack
12859 \begin_inset LatexCommand \index{stack}
12864 This scheme is recommended for larger interrupt service routines.
12870 \begin_inset LatexCommand \index{HC08}
12874 Interrupt Service Routines
12877 \added_space_bottom bigskip
12878 Since the number of interrupts
12879 \begin_inset LatexCommand \index{HC08!interrupt}
12883 available is chip specific and the interrupt vector table always ends at
12884 the last byte of memory, the interrupt numbers corresponds to the interrupt
12885 vectors in reverse order of address.
12886 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12887 2 will use the interrupt vector at 0xfffa, and so on.
12888 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12889 this way; instead see section
12890 \begin_inset LatexCommand \ref{sub:Startup-Code}
12894 for details on customizing startup.
12899 Z80 Interrupt Service Routines
12903 \begin_inset LatexCommand \index{Z80}
12907 uses several different methods for determining the correct interrupt
12908 \begin_inset LatexCommand \index{Z80!interrupt}
12912 vector depending on the hardware implementation.
12913 Therefore, SDCC ignores the optional interrupt number and does not attempt
12914 to generate an interrupt vector table.
12917 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12918 instruction to return from the interrupt.
12919 To write an interrupt handler for the non-maskable interrupt, which needs
12920 a RETN instruction instead, add the
12929 void nmi_isr (void) critical interrupt
12943 \added_space_bottom bigskip
12944 However if you need to create a non-interruptable interrupt service routine
12945 you would also require the
12950 To distinguish between this and an nmi_isr you must provide an interrupt
12956 Enabling and Disabling Interrupts
12959 Critical Functions and Critical Statements
12962 A special keyword may be associated with a block or a function declaring
12968 SDCC will generate code to disable all interrupts
12969 \begin_inset LatexCommand \index{interrupt}
12973 upon entry to a critical function and restore the interrupt enable to the
12974 previous state before returning.
12975 Nesting critical functions will need one additional byte on the stack
12976 \begin_inset LatexCommand \index{stack}
12985 int foo () __critical
12986 \begin_inset LatexCommand \index{critical}
12991 \begin_inset LatexCommand \index{\_\_critical}
13016 The critical attribute maybe used with other attributes like
13026 may also be used to disable interrupts more locally:
13034 More than one statement could have been included in the block.
13037 Enabling and Disabling Interrupts directly
13041 \begin_inset LatexCommand \index{interrupt}
13045 can also be disabled and enabled directly (8051):
13050 EA = 0;\SpecialChar ~
13113 EA = 1;\SpecialChar ~
13180 On other architectures which have seperate opcodes for enabling and disabling
13181 interrupts you might want to make use of defines with inline assembly
13182 \begin_inset LatexCommand \index{Assembler routines}
13187 \begin_inset LatexCommand \index{HC08!interrupt}
13197 \begin_inset LatexCommand \index{\_asm}
13206 \begin_inset LatexCommand \index{\_endasm}
13215 #define SEI _asm\SpecialChar ~
13227 Note: it is sometimes sufficient to disable only a specific interrupt source
13229 a timer or serial interrupt by manipulating an
13232 \begin_inset LatexCommand \index{interrupt mask}
13242 Usually the time during which interrupts are disabled should be kept as
13244 This minimizes both
13249 \begin_inset LatexCommand \index{interrupt latency}
13253 (the time between the occurrence of the interrupt and the execution of
13254 the first code in the interrupt routine) and
13259 \begin_inset LatexCommand \index{interrupt jitter}
13263 (the difference between the shortest and the longest interrupt latency).
13264 These really are something different, f.e.
13265 a serial interrupt has to be served before its buffer overruns so it cares
13266 for the maximum interrupt latency, whereas it does not care about jitter.
13267 On a loudspeaker driven via a digital to analog converter which is fed
13268 by an interrupt a latency of a few milliseconds might be tolerable, whereas
13269 a much smaller jitter will be very audible.
13272 You can reenable interrupts within an interrupt routine and on some architecture
13273 s you can make use of two (or more) levels of
13275 interrupt priorities
13278 \begin_inset LatexCommand \index{interrupt priority}
13283 On some architectures which don't support interrupt priorities these can
13284 be implemented by manipulating the interrupt mask and reenabling interrupts
13285 within the interrupt routine.
13286 Check there is sufficient space on the stack
13287 \begin_inset LatexCommand \index{stack}
13291 and don't add complexity unless you have to.
13296 \begin_inset LatexCommand \index{semaphore}
13300 locking (mcs51/ds390)
13303 Some architectures (mcs51/ds390) have an atomic
13304 \begin_inset LatexCommand \index{atomic}
13317 These type of instructions are typically used in preemptive multitasking
13318 systems, where a routine f.e.
13319 claims the use of a data structure ('acquires a lock
13320 \begin_inset LatexCommand \index{lock}
13324 on it'), makes some modifications and then releases the lock when the data
13325 structure is consistent again.
13326 The instruction may also be used if interrupt and non-interrupt code have
13327 to compete for a resource.
13328 With the atomic bit test and clear instruction interrupts
13329 \begin_inset LatexCommand \index{interrupt}
13333 don't have to be disabled for the locking operation.
13337 SDCC generates this instruction if the source follows this pattern:
13343 \begin_inset LatexCommand \index{volatile}
13347 bit resource_is_free;
13351 if (resource_is_free)
13361 resource_is_free=0;
13374 resource_is_free=1;
13381 Note, mcs51 and ds390 support only an atomic
13382 \begin_inset LatexCommand \index{atomic}
13390 instruction (as opposed to atomic bit test and
13395 Functions using private register banks
13396 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13403 Some architectures have support for quickly changing register sets.
13404 SDCC supports this feature with the
13407 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13412 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13418 attribute (which tells the compiler to use a register bank
13419 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13423 other than the default bank zero).
13424 It should only be applied to
13427 \begin_inset LatexCommand \index{interrupt}
13433 functions (see footnote below).
13434 This will in most circumstances make the generated ISR code more efficient
13435 since it will not have to save registers on the stack.
13442 attribute will have no effect on the generated code for a
13446 function (but may occasionally be useful anyway
13451 possible exception: if a function is called ONLY from 'interrupt' functions
13452 using a particular bank, it can be declared with the same 'using' attribute
13453 as the calling 'interrupt' functions.
13454 For instance, if you have several ISRs using bank one, and all of them
13455 call memcpy(), it might make sense to create a specialized version of memcpy()
13456 'using 1', since this would prevent the ISR from having to save bank zero
13457 to the stack on entry and switch to bank zero before calling the function
13465 (pending: Note, nowadays the
13469 attribute has an effect on
13473 the generated code for a
13488 function using a non-zero bank will assume that it can trash that register
13489 bank, and will not save it.
13490 Since high-priority interrupts
13491 \begin_inset LatexCommand \index{interrupts}
13496 \begin_inset LatexCommand \index{interrupt priority}
13500 can interrupt low-priority ones on the 8051 and friends, this means that
13501 if a high-priority ISR
13505 a particular bank occurs while processing a low-priority ISR
13509 the same bank, terrible and bad things can happen.
13510 To prevent this, no single register bank should be
13514 by both a high priority and a low priority ISR.
13515 This is probably most easily done by having all high priority ISRs use
13516 one bank and all low priority ISRs use another.
13517 If you have an ISR which can change priority at runtime, you're on your
13518 own: I suggest using the default bank zero and taking the small performance
13522 \added_space_bottom bigskip
13523 It is most efficient if your ISR calls no other functions.
13524 If your ISR must call other functions, it is most efficient if those functions
13525 use the same bank as the ISR (see note 1 below); the next best is if the
13526 called functions use bank zero.
13527 It is very inefficient to call a function using a different, non-zero bank
13535 \begin_inset LatexCommand \label{sub:Startup-Code}
13540 \begin_inset LatexCommand \index{Startup code}
13547 MCS51/DS390 Startup Code
13550 The compiler inserts a call to the C routine
13552 _sdcc_external_startup()
13553 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13562 at the start of the CODE area.
13563 This routine is in the runtime library
13564 \begin_inset LatexCommand \index{Runtime library}
13569 By default this routine returns 0, if this routine returns a non-zero value,
13570 the static & global variable initialization will be skipped and the function
13571 main will be invoked.
13572 Otherwise static & global variables will be initialized before the function
13576 _sdcc_external_startup()
13578 routine to your program to override the default if you need to setup hardware
13579 or perform some other critical operation prior to static & global variable
13581 \begin_inset LatexCommand \index{Variable initialization}
13586 On some mcs51 variants xdata
13587 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13591 memory has to be explicitly enabled before it can be accessed or if the
13593 \begin_inset LatexCommand \index{watchdog}
13597 needs to be disabled, this is the place to do it.
13598 The startup code clears all internal data memory, 256 bytes by default,
13599 but from 0 to n-1 if
13614 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13621 (recommended for Chipcon CC1010).
13624 \added_space_bottom bigskip
13625 See also the compiler options
13646 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13667 \begin_inset LatexCommand \index{-\/-main-return}
13672 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13676 about MCS51-variants.
13684 \added_space_bottom bigskip
13686 \begin_inset LatexCommand \index{HC08}
13690 startup code follows the same scheme as the MCS51 startup code.
13698 \added_space_bottom bigskip
13700 \begin_inset LatexCommand \index{Z80}
13704 the startup code is inserted by linking with crt0.o which is generated from
13705 sdcc/device/lib/z80/crt0.s.
13706 If you need a different startup code you can use the compiler option
13729 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13733 and provide your own crt0.o.
13739 Inline Assembler Code
13740 \begin_inset LatexCommand \index{Assembler routines}
13747 A Step by Step Introduction
13748 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13755 Starting from a small snippet of c-code this example shows for the MCS51
13756 how to use inline assembly, access variables, a function parameter and
13757 an array in xdata memory.
13758 The example uses an MCS51 here but is easily adapted for other architectures.
13759 This is a buffer routine which should be optimized:
13765 unsigned char __far
13766 \begin_inset LatexCommand \index{far (storage class)}
13771 \begin_inset LatexCommand \index{\_\_far (storage class)}
13776 \begin_inset LatexCommand \index{at}
13781 \begin_inset LatexCommand \index{\_\_at}
13785 (0x7f00) buf[0x100];
13786 \begin_inset LatexCommand \index{Aligned array}
13792 unsigned char head, tail;\SpecialChar ~
13810 \begin_inset LatexCommand \index{interrupt}
13862 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13874 void to_buffer( unsigned char c )
13882 if( head != (unsigned char)(tail-1)
13889 \begin_inset LatexCommand \index{promotion to signed int}
13894 \begin_inset LatexCommand \index{type promotion}
13899 \begin_inset Marginal
13920 buf[ head++ ] = c;\SpecialChar ~
13936 /* access to a 256 byte aligned array */
13941 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13942 then a corresponding buffer.asm file is generated.
13943 We define a new function
13947 in file buffer.c in which we cut and paste the generated code, removing
13948 unwanted comments and some ':'.
13950 \begin_inset Quotes sld
13954 \begin_inset Quotes srd
13958 \begin_inset Quotes sld
13962 \begin_inset Quotes srd
13965 to the beginning and the end of the function body:
13971 /* With a cut and paste from the .asm file, we have something to start with.
13977 function is not yet OK! (registers aren't saved) */
13979 void to_buffer_asm(
13989 \begin_inset LatexCommand \index{\_asm}
13994 \begin_inset LatexCommand \index{\_\_asm}
14008 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14014 \begin_inset LatexCommand \index{promotion to signed int}
14019 \begin_inset LatexCommand \index{type promotion}
14072 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14073 \begin_inset LatexCommand \index{Aligned array}
14139 \begin_inset LatexCommand \index{\_endasm}
14144 \begin_inset LatexCommand \index{\_\_endasm}
14153 The new file buffer.c should compile with only one warning about the unreferenced
14154 function argument 'c'.
14155 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14156 (1) and finally have:
14162 unsigned char __far __at(0x7f00) buf[0x100];
14164 unsigned char head, tail;
14175 void to_buffer( unsigned char c )
14184 head != (unsigned char)(tail-1) )
14213 c; // to avoid warning: unreferenced function argument
14220 \begin_inset LatexCommand \index{\_asm}
14225 \begin_inset LatexCommand \index{\_\_asm}
14239 ; save used registers here.
14250 ; If we were still using r2,r3 we would have to push them here.
14253 ; if( head != (unsigned char)(tail-1) )
14297 could do an ANL a,#0x0f here to use a smaller buffer (see below)
14333 a,dpl \SpecialChar ~
14340 ; dpl holds lower byte of function argument
14352 dpl,_head \SpecialChar ~
14355 ; buf is 0x100 byte aligned so head can be used directly
14398 ; we could do an ANL _head,#0x0f here to use a
14399 smaller buffer (see above)
14411 ; restore used registers here
14418 \begin_inset LatexCommand \index{\_endasm}
14423 \begin_inset LatexCommand \index{\_\_endasm}
14434 The inline assembler code can contain any valid code understood by the assembler
14435 , this includes any assembler directives and comment lines.
14436 The assembler does not like some characters like ':' or ''' in comments.
14437 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
14438 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
14443 \begin_inset LatexCommand \index{Assembler documentation}
14448 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
14456 The compiler does not do any validation of the code within the
14459 \begin_inset LatexCommand \index{\_asm}
14464 \begin_inset LatexCommand \index{\_\_asm}
14472 \begin_inset LatexCommand \index{\_endasm}
14477 \begin_inset LatexCommand \index{\_\_endasm}
14486 Specifically it will not know which registers are used and thus register
14488 \begin_inset LatexCommand \index{push/pop}
14492 has to be done manually.
14496 It is recommended that each assembly instruction (including labels) be placed
14497 in a separate line (as the example shows).
14513 \begin_inset LatexCommand \index{-\/-peep-asm}
14519 command line option is used, the inline assembler code will be passed through
14520 the peephole optimizer
14521 \begin_inset LatexCommand \index{Peephole optimizer}
14526 There are only a few (if any) cases where this option makes sense, it might
14527 cause some unexpected changes in the inline assembler code.
14528 Please go through the peephole optimizer rules defined in file
14532 before using this option.
14536 \begin_inset LatexCommand \label{sub:Naked-Functions}
14541 \begin_inset LatexCommand \index{Naked functions}
14548 A special keyword may be associated with a function declaring it as
14551 \begin_inset LatexCommand \index{\_naked}
14556 \begin_inset LatexCommand \index{\_\_naked}
14567 function modifier attribute prevents the compiler from generating prologue
14568 \begin_inset LatexCommand \index{function prologue}
14573 \begin_inset LatexCommand \index{function epilogue}
14577 code for that function.
14578 This means that the user is entirely responsible for such things as saving
14579 any registers that may need to be preserved, selecting the proper register
14580 bank, generating the
14584 instruction at the end, etc.
14585 Practically, this means that the contents of the function must be written
14586 in inline assembler.
14587 This is particularly useful for interrupt functions, which can have a large
14588 (and often unnecessary) prologue/epilogue.
14589 For example, compare the code generated by these two functions:
14595 \begin_inset LatexCommand \index{volatile}
14599 data unsigned char counter;
14603 void simpleInterrupt(void) __interrupt
14604 \begin_inset LatexCommand \index{interrupt}
14609 \begin_inset LatexCommand \index{\_\_interrupt}
14627 void nakedInterrupt(void) __interrupt (2) __naked
14636 \begin_inset LatexCommand \index{\_asm}
14641 \begin_inset LatexCommand \index{\_\_asm}
14658 _counter ; does not change flags, no need to save psw
14671 include ret or reti in _naked function.
14678 \begin_inset LatexCommand \index{\_endasm}
14683 \begin_inset LatexCommand \index{\_\_endasm}
14692 For an 8051 target, the generated simpleInterrupt looks like:
14701 example, recent versions of SDCC generate
14707 code for simpleInterrupt() and nakedInterrupt()!
14848 whereas nakedInterrupt looks like:
14863 _counter ; does not change flags, no need to save psw
14882 MUST explicitly include ret or reti in _naked function
14885 The related directive #pragma exclude
14886 \begin_inset LatexCommand \index{\#pragma exclude}
14890 allows a more fine grained control over pushing & popping
14891 \begin_inset LatexCommand \index{push/pop}
14898 While there is nothing preventing you from writing C code inside a
14902 function, there are many ways to shoot yourself in the foot doing this,
14903 and it is recommended that you stick to inline assembler.
14906 Use of Labels within Inline Assembler
14909 SDCC allows the use of in-line assembler with a few restrictions regarding
14911 In older versions of the compiler all labels defined within inline assembler
14920 where nnnn is a number less than 100 (which implies a limit of utmost 100
14921 inline assembler labels
14935 \begin_inset LatexCommand \index{\_asm}
14940 \begin_inset LatexCommand \index{\_\_asm}
14970 \begin_inset LatexCommand \index{\_endasm}
14975 \begin_inset LatexCommand \index{\_\_endasm}
14982 Inline assembler code cannot reference any C-Labels, however it can reference
14984 \begin_inset LatexCommand \index{Labels}
14988 defined by the inline assembler, e.g.:
15013 ; some assembler code
15034 /* some more c code */
15036 clabel:\SpecialChar ~
15038 /* inline assembler cannot reference this
15051 $0003: ;label (can be referenced by inline assembler only)
15059 \begin_inset LatexCommand \index{\_endasm}
15064 \begin_inset LatexCommand \index{\_\_endasm}
15074 /* some more c code */
15079 In other words inline assembly code can access labels defined in inline
15080 assembly within the scope of the function.
15081 The same goes the other way, i.e.
15082 labels defines in inline assembly can not be accessed by C statements.
15085 Interfacing with Assembler Code
15086 \begin_inset LatexCommand \index{Assembler routines}
15093 Global Registers used for Parameter Passing
15094 \begin_inset LatexCommand \index{Parameter passing}
15101 The compiler always uses the global registers
15104 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15109 \begin_inset LatexCommand \index{DPTR}
15114 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15123 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15129 to pass the first parameter to a routine.
15130 The second parameter onwards is either allocated on the stack (for reentrant
15143 -stack-auto is used) or in data / xdata memory (depending on the memory
15148 Assembler Routine (non-reentrant)
15151 In the following example
15152 \begin_inset LatexCommand \index{reentrant}
15157 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15161 the function c_func calls an assembler routine asm_func, which takes two
15163 \begin_inset LatexCommand \index{function parameter}
15172 extern int asm_func(unsigned char, unsigned char);
15176 int c_func (unsigned char
15177 i, unsigned char j)
15185 return asm_func(i,j);
15199 return c_func(10,9);
15204 The corresponding assembler function is:
15209 .globl _asm_func_PARM_2
15311 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15328 Note here that the return values
15329 \begin_inset LatexCommand \index{return value}
15333 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
15335 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
15336 b' & 'acc' for four byte values.
15339 The parameter naming convention is _<function_name>_PARM_<n>, where n is
15340 the parameter number starting from 1, and counting from the left.
15341 The first parameter is passed in
15342 \begin_inset Quotes eld
15346 \begin_inset Quotes erd
15349 for a one byte parameter,
15350 \begin_inset Quotes eld
15354 \begin_inset Quotes erd
15358 \begin_inset Quotes eld
15362 \begin_inset Quotes erd
15365 for three bytes and
15366 \begin_inset Quotes eld
15370 \begin_inset Quotes erd
15373 for a four bytes parameter.
15374 The variable name for the second parameter will be _<function_name>_PARM_2.
15379 ble the assembler routine with the following command:
15386 asx8051 -losg asmfunc.asm
15393 Then compile and link the assembler routine to the C source file with the
15401 sdcc cfunc.c asmfunc.rel
15404 Assembler Routine (reentrant)
15408 \begin_inset LatexCommand \index{reentrant}
15413 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
15417 the second parameter
15418 \begin_inset LatexCommand \index{function parameter}
15422 onwards will be passed on the stack, the parameters are pushed from right
15424 after the call the leftmost parameter will be on the top of the stack.
15425 Here is an example:
15430 extern int asm_func(unsigned char, unsigned char);
15434 int c_func (unsigned char
15435 i, unsigned char j) reentrant
15443 return asm_func(i,j);
15463 The corresponding assembler routine is:
15565 \added_space_bottom bigskip
15566 The compiling and linking procedure remains the same, however note the extra
15567 entry & exit linkage required for the assembler code, _bp is the stack
15568 frame pointer and is used to compute the offset into the stack for parameters
15569 and local variables.
15575 \begin_inset LatexCommand \index{int (16 bit)}
15580 \begin_inset LatexCommand \index{long (32 bit)}
15587 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15588 multiplication and modulus operations are implemented by support routines.
15589 These support routines are all developed in ANSI-C to facilitate porting
15590 to other MCUs, although some model specific assembler optimizations are
15592 The following files contain the described routines, all of them can be
15593 found in <installdir>/share/sdcc/lib.
15599 \begin_inset Tabular
15600 <lyxtabular version="3" rows="11" columns="2">
15602 <column alignment="left" valignment="top" leftline="true" width="0">
15603 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15604 <row topline="true" bottomline="true">
15605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15626 <row topline="true">
15627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15639 16 bit multiplication
15644 <row topline="true">
15645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15657 signed 16 bit division (calls _divuint)
15662 <row topline="true">
15663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15675 unsigned 16 bit division
15680 <row topline="true">
15681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15693 signed 16 bit modulus (calls _moduint)
15698 <row topline="true">
15699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15711 unsigned 16 bit modulus
15716 <row topline="true">
15717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15729 32 bit multiplication
15734 <row topline="true">
15735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15747 signed 32 division (calls _divulong)
15752 <row topline="true">
15753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15765 unsigned 32 division
15770 <row topline="true">
15771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15783 signed 32 bit modulus (calls _modulong)
15788 <row topline="true" bottomline="true">
15789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15801 unsigned 32 bit modulus
15815 Since they are compiled as
15820 \begin_inset LatexCommand \index{reentrant}
15825 \begin_inset LatexCommand \index{interrupt}
15829 service routines should not do any of the above operations.
15830 If this is unavoidable then the above routines will need to be compiled
15846 \begin_inset LatexCommand \index{-\/-stack-auto}
15852 option, after which the source program will have to be compiled with
15867 \begin_inset LatexCommand \index{-\/-int-long-reent}
15874 Notice that you don't have to call these routines directly.
15875 The compiler will use them automatically every time an integer operation
15879 Floating Point Support
15880 \begin_inset LatexCommand \index{Floating point support}
15887 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15888 The floating point support routines are derived from gcc's floatlib.c and
15889 consist of the following routines:
15897 \begin_inset Tabular
15898 <lyxtabular version="3" rows="17" columns="2">
15900 <column alignment="left" valignment="top" leftline="true" width="0">
15901 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15902 <row topline="true" bottomline="true">
15903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15929 <row topline="true">
15930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15960 add floating point numbers
15965 <row topline="true">
15966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15996 subtract floating point numbers
16001 <row topline="true">
16002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16032 divide floating point numbers
16037 <row topline="true">
16038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16068 multiply floating point numbers
16073 <row topline="true">
16074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16104 convert floating point to unsigned char
16109 <row topline="true">
16110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16140 convert floating point to signed char
16145 <row topline="true">
16146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16176 convert floating point to unsigned int
16181 <row topline="true">
16182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16212 convert floating point to signed int
16217 <row topline="true">
16218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16256 convert floating point to unsigned long
16261 <row topline="true">
16262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16292 convert floating point to signed long
16297 <row topline="true">
16298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16328 convert unsigned char to floating point
16333 <row topline="true">
16334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16364 convert char to floating point number
16369 <row topline="true">
16370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16400 convert unsigned int to floating point
16405 <row topline="true">
16406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16436 convert int to floating point numbers
16441 <row topline="true">
16442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16472 convert unsigned long to floating point number
16477 <row topline="true" bottomline="true">
16478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16508 convert long to floating point number
16522 \added_space_bottom bigskip
16523 These support routines are developed in ANSI-C so there is room for space
16524 and speed improvement
16529 These floating point routines (
16533 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
16539 Note if all these routines are used simultaneously the data space might
16541 For serious floating point usage the large model might be needed.
16542 Also notice that you don't have to call this routines directly.
16543 The compiler will use them automatically every time a floating point operation
16550 \begin_inset LatexCommand \index{Libraries}
16559 <pending: this is messy and incomplete - a little more information is in
16560 sdcc/doc/libdoc.txt
16565 Compiler support routines (_gptrget, _mulint etc.)
16568 Stdclib functions (puts, printf, strcat etc.)
16570 \layout Subsubsection
16574 getchar(), putchar()
16577 \begin_inset LatexCommand \index{<stdio.h>}
16581 As usual on embedded systems you have to provide your own
16584 \begin_inset LatexCommand \index{getchar()}
16593 \begin_inset LatexCommand \index{putchar()}
16600 SDCC does not know whether the system connects to a serial line with or
16601 without handshake, LCD, keyboard or other device.
16615 You'll find examples for serial routines f.e.
16616 in sdcc/device/lib.
16617 For the mcs51 this minimalistic polling
16621 routine might be a start:
16626 void putchar (char c) {
16632 while (!TI)\SpecialChar ~
16635 /* assumes UART is initialized */
16669 \begin_inset LatexCommand \index{printf()}
16679 does not support float (except on ds390).
16680 To enable this recompile it with the option
16695 \begin_inset LatexCommand \index{USE\_FLOATS}
16701 on the command line.
16717 \begin_inset LatexCommand \index{-\/-model-large}
16723 for the mcs51 port, since this uses a lot of memory.
16726 If you're short on code memory you might want to use
16729 \begin_inset LatexCommand \index{printf\_small()}
16744 For the mcs51 there additionally are assembly versions
16747 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16753 (subset of printf using less than 270 bytes) and
16756 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16765 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16771 (floating-point aware version of printf_fast) which should fit the requirements
16772 of many embedded systems (printf_fast() can be customized by unsetting
16777 support long variables and field widths).
16778 Be sure to only use only one of these printf options within a project.
16783 Feature matrix of different
16790 \begin_inset Tabular
16791 <lyxtabular version="3" rows="14" columns="7">
16792 <features islongtable="true">
16793 <column alignment="left" valignment="center" leftline="true" width="14col%">
16794 <column alignment="center" valignment="top" leftline="true" width="0">
16795 <column alignment="center" valignment="top" leftline="true" width="12col%">
16796 <column alignment="center" valignment="top" leftline="true" width="10col%">
16797 <column alignment="center" valignment="top" leftline="true" width="0">
16798 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
16799 <column alignment="center" valignment="top" rightline="true" width="0">
16800 <row topline="true" bottomline="true" endhead="true">
16801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16817 \begin_inset LatexCommand \index{printf}
16825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16868 <row topline="true" endhead="true">
16869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16938 <row topline="true" endhead="true">
16939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16943 \begin_inset Quotes sld
16947 \begin_inset Quotes srd
16957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17006 <row topline="true" endhead="true">
17007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17038 0.45k / 0.47k (+ _ltoa)
17042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17067 <row topline="true">
17068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17203 <row topline="true">
17204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17208 long (32 bit) support
17212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17270 <row topline="true">
17271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17275 byte arguments on stack
17279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17328 <row topline="true">
17329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17334 \begin_inset LatexCommand \index{Floating point support}
17342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17383 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
17391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17400 <row topline="true">
17401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17405 float formats %e %g
17409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17458 <row topline="true" bottomline="true">
17459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17516 <row bottomline="true">
17517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17526 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
17530 n'); standard 8051 @ 22.1184 MHz, empty putchar()
17541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17590 <row bottomline="true">
17591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17600 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
17612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17661 printf_tiny integer speed is data dependent, worst case is 0.33 ms
17670 <row bottomline="true">
17671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17680 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
17692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17741 <row bottomline="true">
17742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17751 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
17763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17818 \layout Subsubsection
17820 \begin_inset LatexCommand \index{malloc.h}
17827 As of SDCC 2.6.2 you no longer need to call an initialization routine before
17828 using dynamic memory allocation
17829 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
17834 \begin_inset LatexCommand \index{heap (malloc)}
17838 space of 1024 bytes is provided for malloc to allocate memory from.
17839 If you need a different heap size you need to recompile _heap.c with the
17840 required size defined in HEAP_SIZE.
17841 It is recommended to make a copy of this file into your project directory
17842 and compile it there with:
17847 sdcc -c _heap.c -D HEAD_SIZE=2048
17850 And then link it with:
17855 sdcc main.rel _heap.rel
17858 Math functions (sinf, powf, sqrtf etc.)
17860 \layout Subsubsection
17864 See definitions in file <math.h>.
17871 \begin_inset LatexCommand \index{Libraries}
17875 included in SDCC should have a license at least as liberal as the GNU Lesser
17876 General Public License
17877 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
17892 license statements for the libraries are missing.
17893 sdcc/device/lib/ser_ir.c
17897 come with a GPL (as opposed to LGPL) License - this will not be liberal
17898 enough for many embedded programmers.
17905 If you have ported some library or want to share experience about some code
17907 falls into any of these categories Busses (I
17908 \begin_inset Formula $^{\textrm{2}}$
17911 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
17912 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
17913 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
17914 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
17919 would certainly like to hear about it.
17922 \added_space_bottom bigskip
17923 Programmers coding for embedded systems are not especially famous for being
17924 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
17925 e these references are very valuable.
17926 Let's help to create a climate where information is shared.
17934 MCS51 Memory Models
17935 \begin_inset LatexCommand \index{Memory model}
17940 \begin_inset LatexCommand \index{MCS51 memory model}
17946 \layout Subsubsection
17947 Small, Medium and Large
17950 SDCC allows three memory models for MCS51 code,
17959 Modules compiled with different memory models should
17963 be combined together or the results would be unpredictable.
17964 The library routines supplied with the compiler are compiled as small,
17966 The compiled library modules are contained in separate directories as small,
17967 medium and large so that you can link to the appropriate set.
17970 When the medium or large model is used all variables declared without a
17971 storage class will be allocated into the external ram, this includes all
17972 parameters and local variables (for non-reentrant
17973 \begin_inset LatexCommand \index{reentrant}
17978 When the small model is used variables without storage class are allocated
17979 in the internal ram.
17982 Judicious usage of the processor specific storage classes
17983 \begin_inset LatexCommand \index{Storage class}
17987 and the 'reentrant' function type will yield much more efficient code,
17988 than using the large model.
17989 Several optimizations are disabled when the program is compiled using the
17990 large model, it is therefore recommended that the small model be used unless
17991 absolutely required.
17993 \layout Subsubsection
17995 \begin_inset LatexCommand \label{sub:External-Stack}
18000 \begin_inset LatexCommand \index{stack}
18005 \begin_inset LatexCommand \index{External stack (mcs51)}
18012 The external stack (-
18025 \begin_inset LatexCommand \index{-\/-xstack}
18029 ) is located in pdata
18030 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18034 memory (usually at the start of the external ram segment) and uses all
18035 unused space in pdata (max.
18049 -xstack option is used to compile the program, the parameters and local
18051 \begin_inset LatexCommand \index{local variables}
18055 of all reentrant functions are allocated in this area.
18056 This option is provided for programs with large stack space requirements.
18057 When used with the -
18070 \begin_inset LatexCommand \index{-\/-stack-auto}
18074 option, all parameters and local variables are allocated on the external
18075 stack (note: support libraries will need to be recompiled with the same
18077 There is a predefined target in the library makefile).
18080 The compiler outputs the higher order address byte of the external ram segment
18082 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18087 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18091 ), therefore when using the External Stack option, this port
18095 be used by the application program.
18099 \begin_inset LatexCommand \index{Memory model}
18104 \begin_inset LatexCommand \index{DS390 memory model}
18111 The only model supported is Flat 24
18112 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18117 This generates code for the 24 bit contiguous addressing mode of the Dallas
18119 In this mode, up to four meg of external RAM or code space can be directly
18121 See the data sheets at www.dalsemi.com for further information on this part.
18126 that the compiler does not generate any code to place the processor into
18127 24 bitmode (although
18131 in the ds390 libraries will do that for you).
18137 \begin_inset LatexCommand \index{Tinibios (DS390)}
18141 , the boot loader or similar code must ensure that the processor is in 24
18142 bit contiguous addressing mode before calling the SDCC startup code.
18163 option, variables will by default be placed into the XDATA segment.
18168 Segments may be placed anywhere in the 4 meg address space using the usual
18182 Note that if any segments are located above 64K, the -r flag must be passed
18183 to the linker to generate the proper segment relocations, and the Intel
18184 HEX output format must be used.
18185 The -r flag can be passed to the linker by using the option
18189 on the SDCC command line.
18190 However, currently the linker can not handle code segments > 64k.
18194 \begin_inset LatexCommand \label{sec:Pragmas}
18199 \begin_inset LatexCommand \index{Pragmas}
18206 SDCC supports the following #pragma directives:
18214 \begin_inset LatexCommand \index{\#pragma save}
18218 - this will save most current options to the save/restore stack.
18219 See #pragma\SpecialChar ~
18228 \begin_inset LatexCommand \index{\#pragma restore}
18232 - will restore saved options from the last save.
18233 saves & restores can be nested.
18234 SDCC uses a save/restore stack: save pushes current options to the stack,
18235 restore pulls current options from the stack.
18236 See #pragma\SpecialChar ~
18247 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18252 \begin_inset LatexCommand \index{function prologue}
18256 function1[,function2[,function3...]] - The compiler by default uses a caller
18257 saves convention for register saving across function calls, however this
18258 can cause unnecessary register pushing & popping
18259 \begin_inset LatexCommand \index{push/pop}
18263 when calling small functions from larger functions.
18264 This option can be used to switch off the register saving convention for
18265 the function names specified.
18266 The compiler will not save registers when calling these functions, extra
18267 code need to be manually inserted at the entry & exit for these functions
18268 to save & restore the registers used by these functions, this can SUBSTANTIALLY
18269 reduce code & improve run time performance of the generated code.
18270 In the future the compiler (with inter procedural analysis) may be able
18271 to determine the appropriate scheme to use for each function call.
18284 -callee-saves command line option is used, the function names specified
18285 in #pragma\SpecialChar ~
18287 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18291 is appended to the list of functions specified in the command line.
18299 \begin_inset LatexCommand \index{\#pragma exclude}
18303 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
18304 of pairs of push/pop
18305 \begin_inset LatexCommand \index{push/pop}
18314 \begin_inset LatexCommand \index{interrupt}
18327 The directive should be placed immediately before the ISR function definition
18328 and it affects ALL ISR functions following it.
18329 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
18330 exclude\SpecialChar ~
18332 \begin_inset LatexCommand \index{\#pragma exclude}
18337 See also the related keyword _naked
18338 \begin_inset LatexCommand \index{\_naked}
18343 \begin_inset LatexCommand \index{\_\_naked}
18355 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
18359 - the compiler will not warn you anymore for obvious mistakes, you'r on
18368 \begin_inset LatexCommand \index{\#pragma disable\_warning}
18372 - the compiler will not warn you anymore about warning number <nnnn>.
18380 \begin_inset LatexCommand \index{\#pragma nogcse}
18384 - will stop global common subexpression elimination.
18392 \begin_inset LatexCommand \index{\#pragma noinduction}
18396 - will stop loop induction optimizations.
18404 \begin_inset LatexCommand \index{\#pragma noinvariant}
18408 - will not do loop invariant optimizations.
18409 For more details see Loop Invariants in section
18410 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
18422 \begin_inset LatexCommand \index{\#pragma noiv}
18426 - Do not generate interrupt
18427 \begin_inset LatexCommand \index{interrupt}
18432 \begin_inset LatexCommand \index{interrupt vector table}
18436 entries for all ISR functions defined after the pragma.
18437 This is useful in cases where the interrupt vector table must be defined
18438 manually, or when there is a secondary, manually defined interrupt vector
18440 for the autovector feature of the Cypress EZ-USB FX2).
18441 More elegantly this can be achieved by obmitting the optional interrupt
18442 number after the interrupt keyword, see section
18443 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
18456 \begin_inset LatexCommand \index{\#pragma nojtbound}
18460 - will not generate code for boundary value checking, when switch statements
18461 are turned into jump-tables (dangerous).
18462 For more details see section
18463 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
18475 \begin_inset LatexCommand \index{\#pragma noloopreverse}
18479 - Will not do loop reversal optimization
18487 \begin_inset LatexCommand \index{\#pragma nooverlay}
18491 - the compiler will not overlay the parameters and local variables of a
18500 \begin_inset LatexCommand \index{\#pragma stackauto}
18517 \begin_inset LatexCommand \index{-\/-stack-auto}
18522 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
18526 Parameters and Local Variables.
18534 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
18538 - The compiler will optimize code generation towards fast code, possibly
18539 at the expense of code size.
18540 Currently this has little effect.
18548 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
18552 - The compiler will optimize code generation towards compact code, possibly
18553 at the expense of code speed.
18554 Currently this has little effect.
18562 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
18566 - The compiler will attempt to generate code that is both compact and fast,
18567 as long as meeting one goal is not a detriment to the other (this is the
18577 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
18581 - Generally follow the C89 standard, but allow SDCC features that conflict
18582 with the standard (default).
18590 \begin_inset LatexCommand \index{\#pragma std\_c89}
18594 - Follow the C89 standard and disable SDCC features that conflict with the
18603 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
18607 - Generally follow the C99 standard, but allow SDCC features that conflict
18608 with the standard (incomplete support).
18616 \begin_inset LatexCommand \index{\#pragma std\_c99}
18620 - Follow the C99 standard and disable SDCC features that conflict with the
18621 standard (incomplete support).
18629 \begin_inset LatexCommand \index{\#pragma codeseg}
18633 - Use this name (max.
18634 8 characters) for the code segment.
18655 \begin_inset LatexCommand \index{\#pragma constseg}
18659 - Use this name (max.
18660 8 characters) for the const segment.
18676 The preprocessor SDCPP
18677 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
18681 supports the following #pragma directives:
18686 pedantic_parse_number
18689 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18693 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
18694 parsed properly and the macro LO_B(3) gets expanded.
18696 Below is an example on how to use this pragma.
18699 Note: this functionality is not in conformance with standard!
18704 #pragma pedantic_parse_number +
18705 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18713 #define LO_B(x) ((x) & 0xff)
18717 unsigned char foo(void)
18724 unsigned char c=0xfe-LO_B(3)
18744 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18748 (+ | -) - switch _asm _endasm block preprocessing on / off.
18750 You use this prama to define multilines of assembly code.
18751 This will prevent the preprocessor from changing the formating required
18753 Below is an example on how to use this pragma.
18758 #pragma preproc_asm -
18759 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18765 #define MYDELAY _asm
18770 nop ;my assembly comment...
18784 #pragma preproc_asm
18820 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18824 (+ | -) - Allow "naked" hash in macro definition, for example:
18828 #define DIR_LO(x) #(x & 0xff)
18833 Below is an example on how to use this pragma.
18838 #pragma preproc_asm +
18840 #pragma sdcc_hash +
18841 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18856 mov R6_B3, #(x & 0xff)
18863 mov R7_B3, #((x >> 8) & 0xff)
18887 The pragma's are intended to be used to turn-on or off certain optimizations
18888 which might cause the compiler to generate extra stack / data space to
18889 store compiler generated temporary variables.
18890 This usually happens in large functions.
18891 Pragma directives should be used as shown in the following example, they
18892 are used to control options & optimizations for a given function; pragmas
18893 should be placed before and/or after a function, placing pragma's inside
18894 a function body could have unpredictable results.
18900 \begin_inset LatexCommand \index{\#pragma save}
18911 /* save the current settings */
18914 \begin_inset LatexCommand \index{\#pragma nogcse}
18923 /* turnoff global subexpression elimination */
18925 #pragma noinduction
18926 \begin_inset LatexCommand \index{\#pragma noinduction}
18930 /* turn off induction optimizations */
18953 \begin_inset LatexCommand \index{\#pragma restore}
18957 /* turn the optimizations back on */
18960 The compiler will generate a warning message when extra space is allocated.
18961 It is strongly recommended that the save and restore pragma's be used when
18962 changing options for a function.
18971 Defines Created by the Compiler
18974 The compiler creates the following #defines
18975 \begin_inset LatexCommand \index{\#defines}
18980 \begin_inset LatexCommand \index{Defines created by the compiler}
18989 \begin_inset Tabular
18990 <lyxtabular version="3" rows="11" columns="2">
18992 <column alignment="left" valignment="top" leftline="true" width="3in">
18993 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
18994 <row topline="true" bottomline="true">
18995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19016 <row topline="true">
19017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19022 \begin_inset LatexCommand \index{SDCC}
19030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19035 Since version 2.5.6 the version number as an int (ex.
19041 <row topline="true">
19042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19047 \begin_inset LatexCommand \index{SDCC\_mcs51}
19052 \begin_inset LatexCommand \index{SDCC\_ds390}
19057 \begin_inset LatexCommand \index{SDCC\_z80}
19065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19069 depending on the model used (e.g.: -mds390)
19074 <row topline="true">
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19080 \begin_inset LatexCommand \index{\_\_mcs51}
19085 \begin_inset LatexCommand \index{\_\_ds390}
19090 \begin_inset LatexCommand \index{\_\_hc08}
19095 \begin_inset LatexCommand \index{\_\_z80}
19103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19107 depending on the model used (e.g.
19113 <row topline="true">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19119 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19152 <row topline="true">
19153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19158 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19197 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
19205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19230 <row topline="true">
19231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19236 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
19244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19269 <row topline="true">
19270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19308 <row topline="true">
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19314 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
19322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19335 <row topline="true" bottomline="true">
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19341 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
19349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19369 Notes on supported Processors
19373 \begin_inset LatexCommand \label{sub:MCS51-variants}
19378 \begin_inset LatexCommand \index{MCS51 variants}
19385 MCS51 processors are available from many vendors and come in many different
19387 While they might differ considerably in respect to Special Function Registers
19388 the core MCS51 is usually not modified or is kept compatible.
19392 pdata access by SFR
19395 With the upcome of devices with internal xdata and flash memory devices
19397 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19401 as dedicated I/O port is becoming more popular.
19402 Switching the high byte for pdata
19403 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19407 access which was formerly done by port P2 is then achieved by a Special
19409 \begin_inset LatexCommand \index{sfr}
19414 In well-established MCS51 tradition the address of this
19418 is where the chip designers decided to put it.
19419 Needless to say that they didn't agree on a common name either.
19420 So that the startup code can correctly initialize xdata variables, you
19421 should define an sfr with the name _XPAGE
19424 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
19430 at the appropriate location if the default, port P2, is not used for this.
19436 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
19441 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19446 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19449 For more exotic implementations further customizations may be needed.
19451 \begin_inset LatexCommand \ref{sub:Startup-Code}
19455 for other possibilities.
19458 Other Features available by SFR
19461 \added_space_bottom bigskip
19462 Some MCS51 variants offer features like Double DPTR
19463 \begin_inset LatexCommand \index{DPTR}
19467 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19468 These are currently not used for the MCS51 port.
19469 If you absolutely need them you can fall back to inline assembly or submit
19478 \added_space_bottom bigskip
19480 \begin_inset LatexCommand \index{DS80C400}
19485 \begin_inset LatexCommand \index{DS400}
19489 microcontroller has a rich set of peripherals.
19490 In its built-in ROM library it includes functions to access some of the
19491 features, among them is a TCP stack with IP4 and IP6 support.
19492 Library headers (currently in beta status) and other files are provided
19496 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
19506 The Z80 and gbz80 port
19509 SDCC can target both the Zilog Z80
19510 \begin_inset LatexCommand \index{Z80}
19514 and the Nintendo Gameboy's Z80-like gbz80
19515 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19520 The Z80 port is passed through the same
19523 \begin_inset LatexCommand \index{Regression test}
19530 \begin_inset LatexCommand \ref{sec:Quality-control}
19534 ) as the MCS51 and DS390 ports, so floating point support, support for long
19535 variables and bitfield support is fine.
19536 See mailing lists and forums about interrupt routines.
19539 \added_space_bottom bigskip
19540 As always, the code is the authoritative reference - see z80/ralloc.c and
19543 \begin_inset LatexCommand \index{Z80!stack}
19547 frame is similar to that generated by the IAR Z80 compiler.
19548 IX is used as the base pointer, HL and IY are used as a temporary registers,
19549 and BC and DE are available for holding variables.
19551 \begin_inset LatexCommand \index{Z80!return value}
19555 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
19557 The gbz80 port use the same set of registers for the return values, but
19558 in a different order of significance: E (one byte), DE (two bytes), or
19567 The port to the Freescale/Motorola HC08
19568 \begin_inset LatexCommand \index{HC08}
19572 family has been added in October 2003, and is still undergoing some basic
19574 The code generator is complete, but the register allocation is still quite
19576 Some of the SDCC's standard C library functions have embedded non-HC08
19577 inline assembly and so are not yet usable.
19580 \added_space_bottom bigskip
19582 The HC08 port passes the regression test suite (see section
19583 \begin_inset LatexCommand \ref{sec:Quality-control}
19597 \begin_inset LatexCommand \index{PIC14}
19601 port still requires a major effort from the development community.
19602 However it can work for simple code.
19603 It passes its (smaller set of) regression tests
19604 \begin_inset LatexCommand \index{Regression test (PIC14)}
19610 sdcc/src/regression
19615 C code and 14bit PIC code page
19616 \begin_inset LatexCommand \index{code page (pic14)}
19621 \begin_inset LatexCommand \index{RAM bank (pic14)}
19628 The linker organizes allocation for the code page and RAM banks.
19629 It does not have intimate knowledge of the code flow.
19630 It will put all the code section of a single asm file into a single code
19632 In order to make use of multiple code pages, separate asm files must be
19634 The compiler treats all functions of a single C file as being in the same
19635 code page unless it is non static.
19639 To get the best follow these guide lines:
19642 Make local functions static, as non static functions require code page selection
19646 For devices that have multiple code pages it is more efficient to use the
19647 same number of files as pages, i.e.
19648 for the 16F877 use 4 separate files and i.e.
19649 for the 16F874 use 2 separate files.
19650 This way the linker can put the code for each file into different code
19651 pages and there's less page selection overhead.
19654 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19655 instruction set), use 'unsigned char' whereever possible instead of 'int'.
19658 Creating a device include file
19661 For generating a device include file
19662 \begin_inset LatexCommand \index{PIC14!Header files}
19666 use the support perl script inc2h.pl kept in directory support/script.
19672 For the interrupt function, use the keyword '__interrupt'
19673 \begin_inset LatexCommand \index{PIC14!interrupt}
19677 with level number of 0 (PIC14 only has 1 interrupt so this number is only
19678 there to avoid a syntax error - it ought to be fixed).
19684 void Intr(void) __interrupt 0
19690 T0IF = 0; /* Clear timer interrupt */
19695 Linking and assembling
19698 For assembling you can use either GPUTILS'
19699 \begin_inset LatexCommand \index{gputils (pic tools)}
19703 gpasm.exe or MPLAB's mpasmwin.exe.
19704 GPUTILS is available from
19705 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19710 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19711 If you use MPLAB and an interrupt function then the linker script file
19712 vectors section will need to be enlarged to link with mplink.
19735 sdcc -S -V -mpic14 -p16F877 $<
19749 $(PRJ).hex: $(OBJS)
19760 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
19782 sdcc -S -V -mpic14 -p16F877 $<
19792 mpasmwin /q /o $*.asm
19796 $(PRJ).hex: $(OBJS)
19807 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
19810 Please note that indentations within a
19814 have to be done with a tabulator character.
19817 Command-line options
19820 Besides the switches common to all SDCC backends, the PIC14 port accepts
19821 the following options (for an updated list see sdcc -
19836 \labelwidthstring 00.00.0000
19850 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
19854 emit debug info in assembly output
19857 \labelwidthstring 00.00.0000
19871 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
19875 disable (slightly faulty) optimization on pCode
19878 \labelwidthstring 00.00.0000
19892 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
19896 sets the lowest address of the argument passing stack (defaults to a suitably
19897 large shared databank to reduce BANKSEL overhead)
19900 \labelwidthstring 00.00.0000
19914 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
19918 sets the size if the argument passing stack (default: 16, minimum: 4)
19923 \layout Subsubsection
19924 error: missing definition for symbol
19925 \begin_inset Quotes sld
19929 \begin_inset Quotes srd
19935 The PIC14 port uses library routines to provide more complex operations
19936 like multiplication, division/modulus and (generic) pointer dereferencing.
19937 In order to add these routines to your project, you must link with PIC14's
19943 For single source file projects this is done automatically, more complex
19948 to the linker's arguments.
19949 Make sure you also add an include path for the library (using the -I switch
19952 \layout Subsubsection
19953 Processor mismatch in file
19954 \begin_inset Quotes sld
19958 \begin_inset Quotes srd
19964 This warning can usually be ignored due to the very good compatibility amongst
19966 \begin_inset LatexCommand \index{PIC14}
19973 You might also consider recompiling the library for your specific device
19974 by changing the ARCH=p16f877 (default target) entry in
19976 device/lib/pic/Makefile.in
19980 device/lib/pic/Makefile
19982 to reflect your device.
19983 This might even improve performance for smaller devices as unneccesary
19984 BANKSELs migth be removed.
19989 \layout Subsubsection
19993 Currently, data can only be initialized if it resides in the source file
20000 Data in other source files will silently
20008 \begin_inset Marginal
20024 \begin_inset LatexCommand \index{PIC16}
20032 \begin_inset LatexCommand \index{PIC16}
20036 port is the portion of SDCC that is responsible to produce code for the
20038 \begin_inset LatexCommand \index{Microchip}
20042 (TM) microcontrollers with 16 bit core.
20043 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20044 Currently supported devices are:
20048 \begin_inset Tabular
20049 <lyxtabular version="3" rows="4" columns="6">
20051 <column alignment="center" valignment="top" leftline="true" width="0">
20052 <column alignment="center" valignment="top" leftline="true" width="0">
20053 <column alignment="center" valignment="top" leftline="true" width="0">
20054 <column alignment="center" valignment="top" leftline="true" width="0">
20055 <column alignment="center" valignment="top" leftline="true" width="0">
20056 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20057 <row topline="true">
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20107 <row topline="true">
20108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20157 <row topline="true">
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20207 <row topline="true" bottomline="true">
20208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20267 PIC16 port supports the standard command line arguments as supposed, with
20268 the exception of certain cases that will be mentioned in the following
20272 \labelwidthstring 00.00.0000
20286 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
20305 \labelwidthstring 00.00.0000
20319 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
20323 All function arguments are passed on stack by default.
20326 There is no need to specify this in the command line.
20329 \labelwidthstring 00.00.0000
20342 -fommit-frame-pointer
20343 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
20347 Frame pointer will be omitted when the function uses no local variables.
20350 Port Specific Options
20351 \begin_inset LatexCommand \index{Options PIC16}
20358 The port specific options appear after the global options in the sdcc --help
20361 \layout Subsubsection
20365 General options enable certain port features and optimizations.
20368 \labelwidthstring 00.00.0000
20381 -pstack-model=[model] Used in conjuction with the command above.
20382 Defines the stack model to be used, valid stack models are :
20386 \labelwidthstring 00.00.0000
20391 Selects small stack model.
20392 8 bit stack and frame pointers.
20393 Supports 256 bytes stack size.
20396 \labelwidthstring 00.00.0000
20401 Selects large stack model.
20402 16 bit stack and frame pointers.
20403 Supports 65536 bytes stack size.
20407 \labelwidthstring 00.00.0000
20420 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
20421 unitialized data variables with [kword].
20422 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
20425 \labelwidthstring 00.00.0000
20438 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
20439 Useful for bootloaders.
20442 \labelwidthstring 00.00.0000
20455 -asm= sets the full path and name of an external assembler to call.
20458 \labelwidthstring 00.00.0000
20471 -link= sets the full path and name of an external linker to call.
20474 \labelwidthstring 00.00.0000
20488 \begin_inset LatexCommand \index{PIC16!MPLAB}
20492 compatibility option.
20493 Currently only suppresses special gpasm directives.
20495 \layout Subsubsection
20496 Optimization Options
20499 \labelwidthstring 00.00.0000
20512 -optimize-goto Try to use (conditional) BRA instead of GOTO
20515 \labelwidthstring 00.00.0000
20528 -optimize-cmp Try to optimize some compares.
20531 \labelwidthstring 00.00.0000
20544 -optimize-df Analyze the dataflow of the generated code and improve it.
20547 \labelwidthstring 00.00.0000
20560 -obanksel=nn Set optimization level for inserting BANKSELs.
20566 \labelwidthstring 00.00.0000
20570 \labelwidthstring 00.00.0000
20571 1 checks previous used register and if it is the same then does not emit
20572 BANKSEL, accounts only for labels.
20575 \labelwidthstring 00.00.0000
20576 2 tries to check the location of (even different) symbols and removes BANKSELs
20577 if they are in the same bank.
20582 Important: There might be problems if the linker script has data sections
20583 across bank borders!
20586 \layout Subsubsection
20590 \labelwidthstring 00.00.0000
20603 -nodefaultlibs do not link default libraries when linking
20606 \labelwidthstring 00.00.0000
20619 -no-crt Don't link the default run-time modules
20622 \labelwidthstring 00.00.0000
20635 -use-crt= Use a custom run-time module instead of the defaults.
20637 \layout Subsubsection
20641 Debugging options enable extra debugging information in the output files.
20644 \labelwidthstring 00.00.0000
20657 -debug-xtra Similar to -
20670 \begin_inset LatexCommand \index{-\/-debug}
20674 , but dumps more information.
20677 \labelwidthstring 00.00.0000
20690 -debug-ralloc Force register allocator to dump <source>.d file with debugging
20692 <source> is the name of the file compiled.
20695 \labelwidthstring 00.00.0000
20708 -pcode-verbose Enable pcode debugging information in translation.
20711 \labelwidthstring 00.00.0000
20724 -denable-peeps Force the usage of peepholes.
20728 \labelwidthstring 00.00.0000
20741 -gstack Trace push/pops for stack pointer overflow
20744 \labelwidthstring 00.00.0000
20757 -call-tree dump call tree in .calltree file
20760 Enviromental Variables
20763 There is a number of enviromental variables that can be used when running
20764 SDCC to enable certain optimizations or force a specific program behaviour.
20765 these variables are primarily for debugging purposes so they can be enabled/dis
20769 Currently there is only two such variables available:
20772 \labelwidthstring 00.00.0000
20773 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
20774 bitfields is optimized by directly loading FSR0 with the address of the
20775 bitfield structure.
20776 Normally SDCC will cast the bitfield structure to a bitfield pointer and
20778 This step saves data ram and code space for functions that perform heavy
20781 80 bytes of code space are saved when compiling malloc.c with this option).
20785 \labelwidthstring 00.00.0000
20786 NO_REG_OPT do not perform pCode registers optimization.
20787 This should be used for debugging purposes.
20788 In some where bugs in the pcode optimizer are found, users can benefit
20789 from temporarily disabling the optimizer until the bug is fixed.
20792 Preprocessor Macros
20796 \begin_inset LatexCommand \index{PIC16}
20800 port defines the following preprocessor macros while translating a source.
20804 \begin_inset Tabular
20805 <lyxtabular version="3" rows="6" columns="2">
20807 <column alignment="center" valignment="top" leftline="true" width="0">
20808 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20809 <row topline="true" bottomline="true">
20810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20827 <row topline="true">
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20840 Port identification
20845 <row topline="true">
20846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20870 Port identification (same as above)
20875 <row topline="true">
20876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20888 MCU Identification.
20893 is the microcontrol identification number, i.e.
20899 <row topline="true">
20900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20924 MCU Identification (same as above)
20929 <row topline="true" bottomline="true">
20930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20942 nnn = SMALL or LARGE respectively according to the stack model used
20954 In addition the following macros are defined when calling assembler:
20958 \begin_inset Tabular
20959 <lyxtabular version="3" rows="4" columns="2">
20961 <column alignment="center" valignment="top" leftline="true" width="0">
20962 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20963 <row topline="true" bottomline="true">
20964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20981 <row topline="true">
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20994 MCU Identification.
20999 is the microcontrol identification number, i.e.
21005 <row topline="true">
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21018 nnn = SMALL or LARGE respectively according to the memory model used for
21024 <row topline="true" bottomline="true">
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21037 nnn = SMALL or LARGE respectively according to the stack model used
21053 \begin_inset LatexCommand \index{PIC16}
21057 port uses the following directories for searching header files and libraries.
21061 \begin_inset Tabular
21062 <lyxtabular version="3" rows="3" columns="4">
21064 <column alignment="center" valignment="top" leftline="true" width="0">
21065 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21066 <column alignment="center" valignment="top" width="0">
21067 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
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" rightline="true" usebox="none">
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21102 <row topline="true">
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21107 PREFIX/sdcc/include/pic16
21111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21115 PIC16 specific headers
21119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21136 <row topline="true" bottomline="true">
21137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21141 PREFIX/sdcc/lib/pic16
21145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21149 PIC16 specific libraries
21153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21178 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
21186 \begin_inset LatexCommand \index{PIC16}
21190 port currently supports the following pragmas:
21193 \labelwidthstring 00.00.0000
21195 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
21200 \begin_inset LatexCommand \index{PIC16!stack}
21204 forces the code generator to initialize the stack & frame pointers at a
21206 This is an adhoc solution for cases where no STACK directive is available
21207 in the linker script or gplink is not instructed to create a stack section.
21210 stack pragma should be used only once in a project.
21211 Multiple pragmas may result in indeterminate behaviour of the program.
21216 The old format (ie.
21217 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
21218 cross page boundaries (or even exceed the available data RAM) and crash
21220 Make sure that stack does not cross page boundaries when using the SMALL
21227 The format is as follows:
21230 #pragma stack bottom_address [stack_size]
21237 is the lower bound of the stack section.
21238 The stack pointer initially will point at address (bottom_address+stack_size-1).
21247 /* initializes stack of 100 bytes at RAM address 0x200 */
21250 #pragma stack 0x200 100
21253 If the stack_size field is omitted then a stack is created with the default
21255 This size might be enough for most programs, but its not enough for operations
21256 with deep function nesting or excessive stack usage.
21259 \labelwidthstring 00.00.0000
21261 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
21265 place a function symbol at static FLASH address
21274 /* place function test_func at 0x4000 */
21277 #pragma code test_func 0x4000
21283 \labelwidthstring 00.00.0000
21284 library instructs the linker to use a library module.
21289 #pragma library module_name
21296 can be any library or object file (including its path).
21297 Note that there are four reserved keywords which have special meaning.
21302 \begin_inset Tabular
21303 <lyxtabular version="3" rows="6" columns="3">
21305 <column alignment="center" valignment="top" leftline="true" width="0">
21306 <column alignment="block" valignment="top" leftline="true" width="20page%">
21307 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
21308 <row topline="true" bottomline="true">
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21334 <row topline="true">
21335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21349 ignore all library pragmas
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21364 <row topline="true">
21365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21396 <row topline="true">
21397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21411 link the Math libarary
21415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21428 <row topline="true">
21429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21443 link the I/O library
21447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21460 <row topline="true" bottomline="true">
21461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21475 link the debug library
21479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21498 * is the device number, i.e.
21499 452 for PIC18F452 MCU.
21502 This feature allows for linking with specific libraries withoug having to
21503 explicit name them in the command line.
21508 keyword will reject all modules specified by the library pragma.
21511 \labelwidthstring 00.00.0000
21512 udata pragma udata instructs the compiler to emit code so that linker will
21513 place a variable at a specific memory bank
21522 /* places variable foo at bank2 */
21525 #pragma udata bank2 foo
21531 In order for this pragma to work extra SECTION directives should be added
21532 in the .lkr script.
21533 In the following example a sample .lkr file is shown:
21539 // Sample linker script for the PIC18F452 processor
21545 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
21548 CODEPAGE NAME=page START=0x2A END=0x7FFF
21551 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
21554 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
21557 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
21560 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
21563 ACCESSBANK NAME=accessram START=0x0 END=0x7F
21569 DATABANK NAME=gpr0 START=0x80 END=0xFF
21572 DATABANK NAME=gpr1 START=0x100 END=0x1FF
21575 DATABANK NAME=gpr2 START=0x200 END=0x2FF
21578 DATABANK NAME=gpr3 START=0x300 END=0x3FF
21581 DATABANK NAME=gpr4 START=0x400 END=0x4FF
21584 DATABANK NAME=gpr5 START=0x500 END=0x5FF
21587 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
21593 SECTION NAME=CONFIG ROM=config
21599 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
21602 SECTION NAME=bank1 RAM=gpr1 # should be added to link
21605 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
21608 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
21611 SECTION NAME=bank4 RAM=gpr4
21614 SECTION NAME=bank5 RAM=gpr5
21617 The linker will recognise the section name set in the pragma statement and
21618 will position the variable at the memory bank set with the RAM field at
21619 the SECTION line in the linker script file.
21623 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
21630 There is one main header file
21631 \begin_inset LatexCommand \index{PIC16!Header files}
21635 that can be included to the source files using the pic16
21636 \begin_inset LatexCommand \index{PIC16}
21646 This header file contains the definitions for the processor special registers,
21647 so it is necessary if the source accesses them.
21648 It can be included by adding the following line in the beginning of the
21652 #include <pic18fregs.h>
21655 The specific microcontroller is selected within the pic18fregs.h automatically,
21656 so the same source can be used with a variety of devices.
21663 \begin_inset LatexCommand \index{PIC16!Libraries}
21668 \begin_inset LatexCommand \index{PIC16}
21672 port depends on are the microcontroller device libraries which contain
21673 the symbol definitions for the microcontroller special function registers.
21674 These libraries have the format pic18fxxxx.lib, where
21678 is the microcontroller identification number.
21679 The specific library is selected automatically by the compiler at link
21680 stage according to the selected device.
21683 Libraries are created with gplib which is part of the gputils package
21684 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21690 \layout Subsubsection*
21691 Building the libraries
21694 Before using SDCC/pic16 there are some libraries that need to be compiled.
21695 This process is not done automatically by SDCC since not all users use
21696 SDCC for pic16 projects.
21697 So each user should compile the libraries separately.
21700 The steps to compile the pic16 libraries under Linux are:
21703 cd device/lib/pic16
21718 su -c 'make install' # install the libraries, you need the root password
21721 If you need to install the headers too, do:
21727 su -c 'make install' # install the headers, you need the root password
21730 There exist a special target to build the I/O libraries.
21731 This target is not automatically build because it will build the I/O library
21737 This way building will take quite a lot of time.
21738 Users are advised to edit the
21740 device/lib/pic16/pics.build
21742 file and then execute:
21751 The following memory models are supported by the PIC16 port:
21760 Memory model affects the default size of pointers within the source.
21761 The sizes are shown in the next table:
21765 \begin_inset Tabular
21766 <lyxtabular version="3" rows="3" columns="3">
21768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21769 <column alignment="center" valignment="top" leftline="true" width="0">
21770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21771 <row topline="true" bottomline="true">
21772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21776 Pointer sizes according to memory model
21780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21797 <row topline="true" bottomline="true">
21798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21806 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21823 <row topline="true" bottomline="true">
21824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21832 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
21840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21856 It is advisable that all sources within a project are compiled with the
21858 If one wants to override the default memory model, this can be done by
21859 declaring a pointer as
21868 Far selects large memory model's pointers, while near selects small memory
21872 The standard device libraries (see
21873 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
21877 ) contain no reference to pointers, so they can be used with both memory
21885 \begin_inset LatexCommand \index{PIC16!stack}
21889 implementation for the PIC16 port uses two indirect registers, FSR1 and
21893 \labelwidthstring 00.00.0000
21894 FSR1 is assigned as stack pointer
21897 \labelwidthstring 00.00.0000
21898 FSR2 is assigned as frame pointer
21901 The following stack models are supported by the PIC16 port
21922 model means that only the FSRxL byte is used to access stack and frame,
21929 uses both FSRxL and FSRxH registers.
21930 The following table shows the stack/frame pointers sizes according to stack
21931 model and the maximum space they can address:
21935 \begin_inset Tabular
21936 <lyxtabular version="3" rows="3" columns="3">
21938 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21939 <column alignment="center" valignment="top" leftline="true" width="0">
21940 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21941 <row topline="true" bottomline="true">
21942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21946 Stack & Frame pointer sizes according to stack model
21950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21967 <row topline="true">
21968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21993 <row topline="true" bottomline="true">
21994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22030 stack model is currently not working properly throughout the code generator.
22031 So its use is not advised.
22032 Also there are some other points that need special care:
22037 Do not create stack sections with size more than one physical bank (that
22041 Stack sections should no cross physical bank limits (i.e.
22042 #pragma stack 0x50 0x100)
22045 These limitations are caused by the fact that only FSRxL is modified when
22046 using SMALL stack model, so no more than 256 bytes of stack can be used.
22047 This problem will disappear after LARGE model is fully implemented.
22053 In addition to the standard SDCC function keywords, PIC16
22054 \begin_inset LatexCommand \index{PIC16}
22058 port makes available two more:
22061 \labelwidthstring 00.00.0000
22063 \begin_inset LatexCommand \index{PIC16!wparam}
22067 Use the WREG to pass one byte of the first function argument.
22068 This improves speed but you may not use this for functions with arguments
22069 that are called via function pointers, otherwise the first byte of the
22070 first parameter will get lost.
22074 void func_wparam(int a) wparam
22080 /* WREG hold the lower part of a */
22083 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22093 \labelwidthstring 00.00.0000
22095 \begin_inset LatexCommand \index{PIC16!shadowregs}
22099 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22100 hardware shadow registers which hold the values of WREG, STATUS and BSR
22102 This can be done by adding the keyword
22110 keyword in the function's header.
22113 void isr_shadow(void) shadowregs interrupt 1
22129 instructs the code generator not to store/restore WREG, STATUS, BSR when
22130 entering/exiting the ISR.
22133 Function return values
22136 Return values from functions are placed to the appropriate registers following
22137 a modified Microchip policy optimized for SDCC.
22138 The following table shows these registers:
22142 \begin_inset Tabular
22143 <lyxtabular version="3" rows="6" columns="2">
22145 <column alignment="center" valignment="top" leftline="true" width="0">
22146 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22147 <row topline="true" bottomline="true">
22148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22160 destination register
22165 <row topline="true">
22166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22183 <row topline="true">
22184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22201 <row topline="true">
22202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22219 <row topline="true">
22220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22232 FSR0L:PRODH:PRODL:WREG
22237 <row topline="true" bottomline="true">
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22250 on stack, FSR0 points to the beginning
22266 \begin_inset LatexCommand \index{PIC16!interrupt}
22270 service routine (ISR) is declared using the
22277 void isr(void) interrupt
22295 is the interrupt number, which for PIC18F devices can be:
22299 \begin_inset Tabular
22300 <lyxtabular version="3" rows="4" columns="3">
22302 <column alignment="center" valignment="top" leftline="true" width="0">
22303 <column alignment="center" valignment="top" leftline="true" width="0">
22304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22305 <row topline="true" bottomline="true">
22306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22328 Interrupt Vector Address
22333 <row topline="true">
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22359 <row topline="true">
22360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22390 HIGH priority interrupts
22394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22403 <row topline="true" bottomline="true">
22404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22416 LOW priority interrupts
22420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22436 When generating assembly code for ISR the code generator places a
22442 Interrupt Vector Address
22444 which points at the genetated ISR.
22445 This single GOTO instruction is part of an automatically generated
22447 interrupt entry point
22450 The actuall ISR code is placed as normally would in the code space.
22451 Upon interrupt request, the GOTO instruction is executed which jumps to
22453 When declaring interrupt functions as _naked this GOTO instruction is
22458 The whole interrupt functions is therefore placed at the Interrupt Vector
22459 Address of the specific interrupt.
22460 This is not a problem for the LOW priority interrupts, but it is a problem
22461 for the RESET and the HIGH priority interrupts because code may be written
22462 at the next interrupt´s vector address and cause undeterminate program
22463 behaviour if that interrupt is raised.
22468 This is not a problem when
22471 this is a HIGH interrupt ISR and LOW interrupts are
22478 when the ISR is small enough not to reach the next interrupt´s vector address.
22489 is possible to be omitted.
22490 This way a function is generated similar to an ISR, but it is not assigned
22494 When entering an interrupt, currently the PIC16
22495 \begin_inset LatexCommand \index{PIC16}
22499 port automatically saves the following registers:
22511 PROD (PRODL and PRODH)
22514 FSR0 (FSR0L and FSR0H)
22517 These registers are restored upon return from the interrupt routine.
22522 NOTE that when the _naked attribute is specified for an interrupt routine,
22523 then NO registers are stored or restored.
22533 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
22534 There are 3 types of generic pointers currently implemented data, code
22535 and eeprom pointers.
22536 They are differentiated by the value of the 7th and 6th bits of the upper
22541 \begin_inset Tabular
22542 <lyxtabular version="3" rows="5" columns="5">
22544 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22545 <column alignment="center" valignment="top" width="0">
22546 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22547 <column alignment="center" valignment="top" width="0">
22548 <column alignment="left" valignment="top" rightline="true" width="0">
22549 <row topline="true" bottomline="true">
22550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22578 rest of the pointer
22582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22591 <row topline="true" bottomline="true">
22592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22624 uuuuuu uuuuxxxx xxxxxxxx
22628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22632 a 12-bit data pointer in data RAM memory
22637 <row bottomline="true">
22638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22670 uxxxxx xxxxxxxx xxxxxxxx
22674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22678 a 21-bit code pointer in FLASH memory
22683 <row bottomline="true">
22684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22716 uuuuuu uuuuuuxx xxxxxxxx
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22724 a 10-bit eeprom pointer in EEPROM memory
22729 <row bottomline="true">
22730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22762 xxxxxx xxxxxxxx xxxxxxxx
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22770 unimplemented pointer type
22782 Generic pointer are read and written with a set of library functions which
22783 read/write 1, 2, 3, 4 bytes.
22788 \layout Subsubsection
22789 Standard I/O Streams
22796 the type FILE is defined as:
22799 typedef char * FILE;
22802 This type is the stream type implemented I/O in the PIC18F devices.
22803 Also the standard input and output streams are declared in stdio.h:
22806 extern FILE * stdin;
22809 extern FILE * stdout;
22812 The FILE type is actually a generic pointer which defines one more type
22813 of generic pointers, the
22818 This new type has the format:
22822 \begin_inset Tabular
22823 <lyxtabular version="3" rows="2" columns="7">
22825 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22826 <column alignment="center" valignment="top" width="0">
22827 <column alignment="center" valignment="top" leftline="true" width="0">
22828 <column alignment="center" valignment="top" leftline="true" width="0">
22829 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22830 <column alignment="center" valignment="top" width="0">
22831 <column alignment="left" valignment="top" rightline="true" width="0">
22832 <row topline="true" bottomline="true">
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22877 rest of the pointer
22881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22890 <row topline="true" bottomline="true">
22891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22947 upper byte high nubble is 0x2n, the rest are zeroes
22959 Currently implemented there are 3 types of streams defined:
22963 \begin_inset Tabular
22964 <lyxtabular version="3" rows="4" columns="4">
22966 <column alignment="center" valignment="top" leftline="true" width="0">
22967 <column alignment="center" valignment="top" leftline="true" width="0">
22968 <column alignment="center" valignment="top" leftline="true" width="0">
22969 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22970 <row topline="true" bottomline="true">
22971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23004 <row topline="true">
23005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23035 Writes/Reads characters via the USART peripheral
23040 <row topline="true">
23041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23071 Writes/Reads characters via the MSSP peripheral
23076 <row topline="true" bottomline="true">
23077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23107 Writes/Reads characters via used defined functions
23119 The stream identifiers are declared as macros in the stdio.h header.
23122 In the libc library there exist the functions that are used to write to
23123 each of the above streams.
23127 \labelwidthstring 00.00.0000
23140 _stream_usart_putchar writes a character at the USART stream
23143 \labelwidthstring 00.00.0000
23156 _stream_mssp_putchar writes a character at the MSSP stream
23159 \labelwidthstring 00.00.0000
23160 putchar dummy function.
23161 This writes a character to a user specified manner.
23164 In order to increase performance
23168 is declared in stdio.h as having its parameter in WREG (it has the wparam
23170 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
23171 in a user-friendly way.
23176 is the name of the variable that holds the character to print.
23177 An example follows:
23180 #include <pic18fregs.h>
23192 PORTA = c; /* dump character c to PORTA */
23205 stdout = STREAM_USER; /* this is not necessary, since stdout points
23208 * by default to STREAM_USER */
23211 printf (¨This is a printf test
23221 \layout Subsubsection
23225 PIC16 contains an implementation of the printf-family of functions.
23226 There exist the following functions:
23229 extern unsigned int sprintf(char *buf, char *fmt, ...);
23232 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
23238 extern unsigned int printf(char *fmt, ...);
23241 extern unsigned int vprintf(char *fmt, va_lista ap);
23247 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
23250 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
23253 For sprintf and vsprintf
23257 should normally be a data pointer where the resulting string will be placed.
23258 No range checking is done so the user should allocate the necessery buffer.
23259 For fprintf and vfprintf
23263 should be a stream pointer (i.e.
23264 stdout, STREAM_MSSP, etc...).
23266 \layout Subsubsection
23270 The PIC18F family of microcontrollers supports a number of interrupt sources.
23271 A list of these interrupts is shown in the following table:
23275 \begin_inset Tabular
23276 <lyxtabular version="3" rows="11" columns="4">
23278 <column alignment="left" valignment="top" leftline="true" width="0">
23279 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23280 <column alignment="left" valignment="top" leftline="true" width="0">
23281 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23282 <row topline="true" bottomline="true">
23283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23316 <row topline="true">
23317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23325 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23329 PORTB change interrupt
23333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23345 EEPROM/FLASH write complete interrupt
23350 <row topline="true">
23351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23363 INT0 external interrupt
23367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23379 Bus collision interrupt
23384 <row topline="true">
23385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23397 INT1 external interrupt
23401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23413 Low voltage detect interrupt
23418 <row topline="true">
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">
23431 INT2 external interrupt
23435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23447 Parallel slave port interrupt
23452 <row topline="true">
23453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23465 CCP1 module interrupt
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">
23481 AD convertion complete interrupt
23486 <row topline="true">
23487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23499 CCP2 module interrupt
23503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23515 USART receive interrupt
23520 <row topline="true">
23521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23533 TMR0 overflow interrupt
23537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23549 USART transmit interrupt
23554 <row topline="true">
23555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23567 TMR1 overflow interrupt
23571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23583 SSP receive/transmit interrupt
23588 <row topline="true">
23589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23601 TMR2 matches PR2 interrupt
23605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23622 <row topline="true" bottomline="true">
23623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23635 TMR3 overflow interrupt
23639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23663 The prototypes for these names are defined in the header file
23670 In order to simplify signal handling, a number of macros is provided:
23673 \labelwidthstring 00.00.0000
23674 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
23675 high priority interrupts.
23680 is the function name to use.
23683 \labelwidthstring 00.00.0000
23684 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
23685 low priority interrupt.
23690 is the function name to use.
23693 \labelwidthstring 00.00.0000
23694 DEF_HANDLER(sig,handler) define a handler for signal
23699 \labelwidthstring 00.00.0000
23700 END_DEF end the declaration of the dispatch table.
23703 Additionally there are two more macros to simplify the declaration of the
23707 \labelwidthstring 00.00.0000
23710 SIGHANDLER(handler)
23712 this declares the function prototype for the
23719 \labelwidthstring 00.00.0000
23720 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
23723 An example of using the macros above is shown below:
23726 #include <pic18fregs.h>
23729 #include <signal.h>
23733 DEF_INTHIGH(high_int)
23736 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
23739 DEF_HANDLER(SIG_BCOL, _bcol_handler)
23746 SIGHANDLER(_tmr0_handler)
23752 /* action to be taken when timer 0 overflows */
23759 SIGHANDLERNAKED(_bcol_handler)
23768 /* action to be taken when bus collision occurs */
23784 Special care should be taken when using the above scheme:
23787 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
23790 when declaring SIGHANDLERNAKED handler never forget to use
23794 for proper returning.
23800 Here you can find some general tips for compiling programs with SDCC/pic16.
23802 \layout Subsubsection
23807 \begin_inset LatexCommand \index{PIC16!stack}
23811 size (that is 64 bytes) probably is enough for many programs.
23812 One must take care that when there are many levels of function nesting,
23813 or there is excessive usage of stack, its size should be extended.
23814 An example of such a case is the printf/sprintf family of functions.
23815 If you encounter problems like not being able to print integers, then you
23816 need to set the stack size around the maximum (256 for small stack model).
23817 The following diagram shows what happens when calling printf to print an
23821 printf () --> ltoa () --> ultoa () --> divschar ()
23824 It is should be understood that stack is easily consumed when calling complicate
23826 Using command line arguments like -
23838 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
23840 Other ways to reduce stack usage may exist.
23846 The PIC16 Port currently does not pass SDCC's regression test
23847 \begin_inset LatexCommand \index{Regression test (PIC16)}
23852 \begin_inset LatexCommand \ref{sec:Quality-control}
23856 ) and thus the nightly regression tests for the PIC16 target are currently
23857 disabled for all hosts except for
23862 This means you can see the result of the PIC16 regression tests f.e.
23863 by checking the log files in
23864 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
23868 (pick the most up to date file there, scroll down, lend a hand).
23874 There are several approaches to debugging your code.
23875 This chapter is meant to show your options and to give detail on some of
23880 When writing your code:
23883 write your code with debugging in mind (avoid duplicating code, put conceptually
23884 similar variables into structs, use structured code, have strategic points
23885 within your code where all variables are consistent, ...)
23888 run a syntax-checking tool like splint
23889 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23894 \begin_inset LatexCommand \index{lint (syntax checking tool)}
23911 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23918 for the high level code use a C-compiler (like f.e.
23919 GCC) to compile run and debug the code on your host.
23933 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23937 ) on howto handle syntax extensions like __xdata, __at(), ...
23941 use another C-compiler to compile code for your target.
23942 Always an option but not recommended:) And not very likely to help you.
23943 If you seriously consider walking this path you should at least occasionally
23944 check portability of your code.
23945 Most commercial compiler vendors will offer an evaluation version so you
23946 can test compile your code or snippets of your code.
23949 Debugging on a simulator:
23952 there is a separate section about SDCDB (section
23953 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
23960 or (8051 specific) use a freeware/commercial simulator which interfaces
23962 \begin_inset LatexCommand \index{AOMF, AOMF51}
23967 \begin_inset LatexCommand \ref{OMF file}
23971 ) optionally generated by SDCC.
23974 Debugging On-target:
23977 use a MCU port pin to serially output debug data to the RS232 port of your
23979 You'll probably want some level shifting device typically involving a MAX232
23981 If the hardware serial port of the MCU is not available search for 'Software
23982 UART' in your favourite search machine.
23985 use an on-target monitor.
23986 In this context a monitor is a small program which usually accepts commands
23987 via a serial line and allows to set program counter, to single step through
23988 a program and read/write memory locations.
23989 For the 8051 good examples of monitors are paulmon and cmon51 (see section
23991 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
23998 toggle MCU port pins at strategic points within your code and use an oscilloscop
24002 digital oscilloscope
24005 \begin_inset LatexCommand \index{Oscilloscope}
24009 with deep trace memory is really helpful especially if you have to debug
24010 a realtime application.
24011 If you need to monitor more pins than your oscilloscope provides you can
24012 sometimes get away with a small R-2R network.
24013 On a single channel oscilloscope you could f.e.
24014 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24016 \begin_inset Formula $\Omega$
24019 resistor and the other one by a 5\SpecialChar ~
24021 \begin_inset Formula $\Omega$
24024 resistor to the oscilloscope probe (check output drive capability of the
24025 pins you want to monitor).
24026 If you need to monitor many more pins a
24046 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24051 Usually very expensive.
24052 And very nice to have too.
24053 And usually locks you (for years...) to the devices the ICE can emulate.
24057 use a remote debugger.
24058 In most 8-bit systems the symbol information is not available on the target,
24059 and a complete debugger is too bulky for the target system.
24060 Therefore usually a debugger on the host system connects to an on-target
24061 debugging stub which accepts only primitive commands.
24064 Terms to enter into your favourite search engine could be 'remote debugging',
24065 'gdb stub' or 'inferior debugger'.
24069 use an on target hardware debugger.
24070 Some of the more modern MCUs include hardware support for setting break
24071 points and monitoring/changing variables by using dedicated hardware pins.
24072 This facility doesn't require additional code to run on the target and
24077 doesn't affect runtime behaviour until a breakpoint is hit.
24078 For the mcs51 most hardware debuggers use the AOMF
24079 \begin_inset LatexCommand \index{AOMF, AOMF51}
24084 \begin_inset LatexCommand \ref{OMF file}
24095 if you are not familiar with any of the following terms you're likely to
24096 run into problems rather sooner than later:
24113 As an embedded programmer you
24117 to know them so why not look them up
24121 you have problems?)
24124 tell someone else about your problem (actually this is a surprisingly effective
24125 means to hunt down the bug even if the listener is not familiar with your
24127 As 'failure to communicate' is probably one of the job-induced deformations
24128 of an embedded programmer this is highly encouraged.
24131 Debugging with SDCDB
24132 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24137 \begin_inset LatexCommand \index{SDCDB (debugger)}
24144 SDCC is distributed with a source level debugger
24145 \begin_inset LatexCommand \index{Debugger}
24150 The debugger uses a command line interface, the command repertoire of the
24151 debugger has been kept as close to gdb
24152 \begin_inset LatexCommand \index{gdb}
24156 (the GNU debugger) as possible.
24157 The configuration and build process is part of the standard compiler installati
24158 on, which also builds and installs the debugger in the target directory
24159 specified during configuration.
24160 The debugger allows you debug BOTH at the C source and at the ASM source
24164 Compiling for Debugging
24180 \begin_inset LatexCommand \index{-\/-debug}
24184 option must be specified for all files for which debug information is to
24186 The compiler generates a .adb file for each of these files.
24187 The linker creates the .cdb
24188 \begin_inset LatexCommand \index{<file>.cdb}
24193 \begin_inset LatexCommand \index{<file>.adb}
24197 files and the address information.
24198 This .cdb is used by the debugger.
24201 How the Debugger Works
24216 -debug option is specified the compiler generates extra symbol information
24217 some of which are put into the assembler source and some are put into the
24219 Then the linker creates the .cdb file from the individual .adb files with
24220 the address information for the symbols.
24221 The debugger reads the symbolic information generated by the compiler &
24222 the address information generated by the linker.
24223 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
24224 execution is controlled by the debugger.
24225 When a command is issued for the debugger, it translates it into appropriate
24226 commands for the simulator.
24227 (Currently SDCDM only connects to the simulator but
24232 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
24236 is an effort to connect directly to the hardware.)
24239 Starting the Debugger SDCDB
24242 The debugger can be started using the following command line.
24243 (Assume the file you are debugging has the file name foo).
24257 The debugger will look for the following files.
24260 foo.c - the source file.
24263 foo.cdb - the debugger symbol information file.
24266 foo.ihx - the Intel hex format
24267 \begin_inset LatexCommand \index{Intel hex format}
24274 SDCDB Command Line Options
24289 -directory=<source file directory> this option can used to specify the directory
24291 The debugger will look into the directory list specified for source, cdb
24293 The items in the directory list must be separated by ':', e.g.
24294 if the source files can be in the directories /home/src1 and /home/src2,
24307 -directory option should be -
24319 -directory=/home/src1:/home/src2.
24320 Note there can be no spaces in the option.
24324 -cd <directory> - change to the <directory>.
24327 -fullname - used by GUI front ends.
24330 -cpu <cpu-type> - this argument is passed to the simulator please see the
24331 simulator docs for details.
24334 -X <Clock frequency > this options is passed to the simulator please see
24335 the simulator docs for details.
24338 -s <serial port file> passed to simulator see the simulator docs for details.
24341 -S <serial in,out> passed to simulator see the simulator docs for details.
24344 -k <port number> passed to simulator see the simulator docs for details.
24347 SDCDB Debugger Commands
24350 As mentioned earlier the command interface for the debugger has been deliberatel
24351 y kept as close the GNU debugger gdb, as possible.
24352 This will help the integration with existing graphical user interfaces
24353 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
24354 If you use a graphical user interface for the debugger you can skip this
24357 \layout Subsubsection*
24358 break [line | file:line | function | file:function]
24361 Set breakpoint at specified line or function:
24370 sdcdb>break foo.c:100
24372 sdcdb>break funcfoo
24374 sdcdb>break foo.c:funcfoo
24376 \layout Subsubsection*
24377 clear [line | file:line | function | file:function ]
24380 Clear breakpoint at specified line or function:
24389 sdcdb>clear foo.c:100
24391 sdcdb>clear funcfoo
24393 sdcdb>clear foo.c:funcfoo
24395 \layout Subsubsection*
24399 Continue program being debugged, after breakpoint.
24401 \layout Subsubsection*
24405 Execute till the end of the current function.
24407 \layout Subsubsection*
24411 Delete breakpoint number 'n'.
24412 If used without any option clear ALL user defined break points.
24414 \layout Subsubsection*
24415 info [break | stack | frame | registers ]
24418 info break - list all breakpoints
24421 info stack - show the function call stack.
24424 info frame - show information about the current execution frame.
24427 info registers - show content of all registers.
24429 \layout Subsubsection*
24433 Step program until it reaches a different source line.
24434 Note: pressing <return> repeats the last command.
24436 \layout Subsubsection*
24440 Step program, proceeding through subroutine calls.
24442 \layout Subsubsection*
24446 Start debugged program.
24448 \layout Subsubsection*
24452 Print type information of the variable.
24454 \layout Subsubsection*
24458 print value of variable.
24460 \layout Subsubsection*
24464 load the given file name.
24465 Note this is an alternate method of loading file for debugging.
24467 \layout Subsubsection*
24471 print information about current frame.
24473 \layout Subsubsection*
24477 Toggle between C source & assembly source.
24479 \layout Subsubsection*
24480 ! simulator command
24483 Send the string following '!' to the simulator, the simulator response is
24485 Note the debugger does not interpret the command being sent to the simulator,
24486 so if a command like 'go' is sent the debugger can loose its execution
24487 context and may display incorrect values.
24489 \layout Subsubsection*
24495 My name is Bobby Brown"
24498 Interfacing SDCDB with DDD
24505 The screenshot was converted from png to eps with:
24506 \begin_inset Quotes sld
24509 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
24510 \begin_inset Quotes srd
24513 which produces a pretty compact eps file which is free from compression
24517 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
24518 as this broke the build system on Sourceforge (pdf-file was broken.
24519 pdflatex does not accept eps files).
24541 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
24547 shows a screenshot of a debugging session with DDD
24548 \begin_inset LatexCommand \index{DDD (debugger)}
24552 (Unix only) on a simulated 8032.
24553 The debugging session might not run as smoothly as the screenshot suggests.
24554 The debugger allows setting of breakpoints, displaying and changing variables,
24555 single stepping through C and assembler code.
24558 The source was compiled with
24583 -debug ddd_example.c
24596 and DDD was invoked with
24603 ddd -debugger "sdcdb -cpu 8032 ddd_example"
24610 Check that the double quotes or an apostroph within the command line survive
24611 the LyX tool chain.
24612 Previously the apostrophs got slanted in the PDF output so a cut and paste
24620 Interfacing SDCDB with XEmacs
24621 \begin_inset LatexCommand \index{XEmacs}
24626 \begin_inset LatexCommand \index{Emacs}
24633 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
24634 sdcdb.el and sdcdbsrc.el.
24635 These two files can be found in the $(prefix)/bin directory after the installat
24637 These files need to be loaded into XEmacs for the interface to work.
24638 This can be done at XEmacs startup time by inserting the following into
24639 your '.xemacs' file (which can be found in your HOME directory):
24645 (load-file sdcdbsrc.el)
24651 .xemacs is a lisp file so the () around the command is REQUIRED.
24652 The files can also be loaded dynamically while XEmacs is running, set the
24653 environment variable 'EMACSLOADPATH' to the installation bin directory
24654 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
24655 To start the interface enter the following command:
24669 You will prompted to enter the file name to be debugged.
24674 The command line options that are passed to the simulator directly are
24675 bound to default values in the file sdcdbsrc.el.
24676 The variables are listed below, these values maybe changed as required.
24679 sdcdbsrc-cpu-type '51
24682 sdcdbsrc-frequency '11059200
24685 sdcdbsrc-serial nil
24688 The following is a list of key mapping for the debugger interface.
24700 ;;key\SpecialChar ~
24714 binding\SpecialChar ~
24738 ;;---\SpecialChar ~
24752 -------\SpecialChar ~
24795 m-src\SpecialChar ~
24823 sdcdb-back-from-src\SpecialChar ~
24852 rom-src\SpecialChar ~
24862 SDCDB continue command
24880 sdcdb-step-from-src\SpecialChar ~
24909 hatis-c-sexp\SpecialChar ~
24919 SDCDB ptypecommand for data at
24986 sdcdbsrc-delete\SpecialChar ~
25001 B Delete all breakpoints if no arg
25050 given or delete arg (C-u arg x)
25069 -frame\SpecialChar ~
25084 SDCDB Display current frame if no arg,
25133 given or display frame arg
25201 sdcdbsrc-goto-sdcdb\SpecialChar ~
25211 Goto the SDCDB output buffer
25230 t-c-sexp\SpecialChar ~
25241 SDCDB print command for data at
25308 sdcdbsrc-goto-sdcdb\SpecialChar ~
25319 o the SDCDB output buffer
25337 sdcdbsrc-mode\SpecialChar ~
25353 Toggles Sdcdbsrc mode (turns it
25369 sdcdb-finish-from-src\SpecialChar ~
25377 SDCDB finish command
25411 Set break for line with point
25426 sdcdbsrc-mode\SpecialChar ~
25442 Toggle Sdcdbsrc mode
25458 dbsrc-srcmode\SpecialChar ~
25482 Here are a few guidelines that will help the compiler generate more efficient
25483 code, some of the tips are specific to this compiler others are generally
25484 good programming practice.
25487 Use the smallest data type to represent your data-value.
25488 If it is known in advance that the value is going to be less than 256 then
25489 use an 'unsigned char' instead of a 'short' or 'int'.
25490 Please note, that ANSI C requires both signed and unsigned chars to be
25491 promoted to 'signed int'
25492 \begin_inset LatexCommand \index{promotion to signed int}
25497 \begin_inset Marginal
25508 before doing any operation.
25510 \begin_inset LatexCommand \index{type promotion}
25515 \begin_inset LatexCommand \label{type promotion}
25519 can be omitted, if the result is the same.
25520 The effect of the promotion rules together with the sign-extension is often
25527 unsigned char uc = 0xfe;
25529 if (uc * uc < 0) /* this is true! */
25548 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
25558 (unsigned char) -12 / (signed char) -3 = ...
25561 No, the result is not 4:
25566 (int) (unsigned char) -12 / (int) (signed char) -3 =
25568 (int) (unsigned char)
25569 0xf4 / (int) (signed char) 0xfd =
25571 (int) 0x00f4 / (int) 0xfffd =
25576 (int) 244 / (int) -3 =
25578 (int) -81 = (int) 0xffaf;
25581 Don't complain, that gcc gives you a different result.
25582 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
25583 Therefore the results are different.
25586 \begin_inset Quotes sld
25590 \begin_inset Quotes srd
25598 If well-defined overflow characteristics are important and negative values
25599 are not, or if you want to steer clear of sign-extension problems when
25600 manipulating bits or bytes, use one of the corresponding unsigned types.
25601 (Beware when mixing signed and unsigned values in expressions, though.)
25604 character types (especially unsigned char) can be used as "tiny" integers,
25605 doing so is sometimes more trouble than it's worth, due to unpredictable
25606 sign extension and increased code size.
25610 Use unsigned when it is known in advance that the value is not going to
25612 This helps especially if you are doing division or multiplication, bit-shifting
25613 or are using an array index.
25616 NEVER jump into a LOOP.
25619 Declare the variables to be local
25620 \begin_inset LatexCommand \index{local variables}
25624 whenever possible, especially loop control variables (induction).
25627 Have a look at the assembly listing to get a
25628 \begin_inset Quotes sld
25632 \begin_inset Quotes srd
25635 for the code generation.
25638 Porting code from or to other compilers
25639 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
25646 check whether endianness of the compilers differs and adapt where needed.
25649 check the device specific header files
25650 \begin_inset LatexCommand \index{Header files}
25655 \begin_inset LatexCommand \index{Include files}
25659 for compiler specific syntax.
25660 Eventually include the file <compiler.h
25661 \begin_inset LatexCommand \index{compiler.h (include file)}
25666 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
25670 to allow using common header files.
25673 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
25680 check whether the startup code contains the correct initialization (watchdog,
25684 check whether the sizes of short, int, long match.
25687 check if some 16 or 32 bit hardware registers require a specific addressing
25688 order (least significant or most significant byte first) and adapt if needed
25697 relate to time and not to lower/upper memory location here, so this is
25702 the same as endianness).
25705 check whether the keyword
25709 is used where needed.
25710 The compilers might differ in their optimization characteristics (as different
25711 versions of the same compiler might also use more clever optimizations
25712 this is good idea anyway).
25714 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
25721 check that the compilers are not told to supress warnings.
25724 check and convert compiler specific extensions (interrupts, memory areas,
25728 check for differences in type promotion.
25729 Especially check for math operations on
25738 For the sake of C99 compatibility SDCC will probably promote these to
25742 more often than other compilers.
25743 Eventually insert explicit casts to
25752 Also check that the ~\SpecialChar ~
25754 \begin_inset LatexCommand \index{\~\/ Operator}
25761 \begin_inset LatexCommand \index{bit}
25767 variables, use the !\SpecialChar ~
25770 \begin_inset LatexCommand \ref{type promotion}
25775 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25782 check the assembly code generated for interrupt routines (f.e.
25783 for calls to possibly non-reentrant library functions).
25786 check whether timing loops result in proper timing (or preferably consider
25787 a rewrite of the code with timer based delays instead).
25790 check for differences in printf parameters (some compilers push (va_arg
25791 \begin_inset LatexCommand \index{vararg, va\_arg}
25795 ) char variables as
25799 others push them as
25805 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25812 check the resulting memory map
25813 \begin_inset LatexCommand \index{Memory map}
25818 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
25819 ly idata, pdata, xdata).
25820 Eventually check if unexpected library functions are included.
25824 \begin_inset LatexCommand \index{Tools}
25828 included in the distribution
25832 \begin_inset Tabular
25833 <lyxtabular version="3" rows="12" columns="3">
25835 <column alignment="left" valignment="top" leftline="true" width="0pt">
25836 <column alignment="left" valignment="top" leftline="true" width="0pt">
25837 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25838 <row topline="true" bottomline="true">
25839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25870 <row topline="true">
25871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25876 \begin_inset LatexCommand \index{uCsim}
25884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25888 Simulator for various architectures
25892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25901 <row topline="true">
25902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25915 \begin_inset LatexCommand \index{Header files}
25920 \begin_inset LatexCommand \index{Include files}
25928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25932 sdcc/support/scripts
25937 <row topline="true">
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25950 header file conversion
25954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25958 sdcc/support/scripts
25963 <row topline="true">
25964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25998 <row topline="true">
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26033 <row topline="true">
26034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26068 <row topline="true">
26069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26103 <row topline="true">
26104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26138 <row topline="true">
26139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26173 <row topline="true">
26174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26208 <row topline="true" bottomline="true">
26209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26222 \begin_inset LatexCommand \index{packihx (tool)}
26230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26258 \begin_inset LatexCommand \index{Documentation}
26262 included in the distribution
26266 \begin_inset Tabular
26267 <lyxtabular version="3" rows="10" columns="2">
26269 <column alignment="block" valignment="top" leftline="true" width="40col%">
26270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
26271 <row topline="true" bottomline="true" endhead="true">
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26288 Filename / Where to get
26293 <row topline="true">
26294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 SDCC Compiler User Guide
26302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26306 You're reading it right now
26318 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
26327 <row topline="true">
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26352 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26361 <row topline="true">
26362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26367 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
26372 \begin_inset LatexCommand \index{Assembler documentation}
26379 \begin_inset LatexCommand \index{aslink}
26384 \begin_inset LatexCommand \index{Linker documentation}
26392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26396 sdcc/as/doc/asxhtm.html
26408 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
26417 <row topline="true">
26418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26422 SDCC regression test
26423 \begin_inset LatexCommand \index{Regression test}
26431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26435 sdcc/doc/test_suite_spec.pdf
26447 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26456 <row topline="true">
26457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
26490 <row topline="true">
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26495 Notes on debugging with SDCDB
26496 \begin_inset LatexCommand \index{SDCDB (debugger)}
26504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26508 sdcc/debugger/README
26520 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
26529 <row topline="true">
26530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26535 \begin_inset LatexCommand \index{uCsim}
26539 Software simulator for microcontrollers
26543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26576 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
26585 <row topline="true">
26586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26590 Temporary notes on the pic16
26591 \begin_inset LatexCommand \index{PIC16}
26599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26603 sdcc/src/pic16/NOTES
26615 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
26624 <row topline="true" bottomline="true">
26625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26629 SDCC internal documentation (debugging file format)
26633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26666 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
26684 Related open source tools
26685 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
26690 \begin_inset LatexCommand \index{Related tools}
26698 \begin_inset Tabular
26699 <lyxtabular version="3" rows="14" columns="3">
26701 <column alignment="left" valignment="top" leftline="true" width="0pt">
26702 <column alignment="block" valignment="top" leftline="true" width="30line%">
26703 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26704 <row topline="true" bottomline="true">
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26736 <row topline="true">
26737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26742 \begin_inset LatexCommand \index{gpsim (pic simulator)}
26750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26762 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
26771 <row topline="true">
26772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26777 \begin_inset LatexCommand \index{gputils (pic tools)}
26785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26797 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26806 <row topline="true">
26807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26827 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
26836 <row topline="true">
26837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26849 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26858 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
26867 <row topline="true">
26868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26873 \begin_inset LatexCommand \index{indent (source formatting tool)}
26881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26885 Formats C source - Master of the white spaces
26889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26893 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
26902 <row topline="true">
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26908 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
26916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26920 Object file conversion, checksumming, ...
26924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26928 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
26937 <row topline="true">
26938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26943 \begin_inset LatexCommand \index{objdump (tool)}
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26955 Object file conversion, ...
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26963 Part of binutils (should be there anyway)
26968 <row topline="true">
26969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26981 8051 monitor (hex up-/download, single step, disassemble)
26985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26989 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
26998 <row topline="true">
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27004 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27016 Source code documentation system
27020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27024 \begin_inset LatexCommand \url{http://www.doxygen.org}
27033 <row topline="true">
27034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27046 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27054 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27063 <row topline="true">
27064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27076 8051 monitor (hex up-/download, single step, disassemble)
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27084 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27093 <row topline="true">
27094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27099 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27111 Statically checks c sources (see
27112 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27124 \begin_inset LatexCommand \url{http://www.splint.org}
27133 <row topline="true" bottomline="true">
27134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27139 \begin_inset LatexCommand \index{DDD (debugger)}
27147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27151 Debugger, serves nicely as GUI to SDCDB
27152 \begin_inset LatexCommand \index{SDCDB (debugger)}
27160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27164 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
27182 Related documentation / recommended reading
27186 \begin_inset Tabular
27187 <lyxtabular version="3" rows="7" columns="3">
27189 <column alignment="left" valignment="top" leftline="true" width="0pt">
27190 <column alignment="left" valignment="top" leftline="true" width="0">
27191 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27192 <row topline="true" bottomline="true">
27193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27224 <row topline="true">
27225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27247 \begin_inset LatexCommand \index{C Reference card}
27255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27259 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
27268 <row topline="true">
27269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27282 \begin_inset LatexCommand \index{C FAQ}
27290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27294 \begin_inset LatexCommand \url{http://www.c-faq.com}
27303 <row topline="true">
27304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27316 \begin_inset Quotes sld
27320 \begin_inset Quotes srd
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27333 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27342 <row topline="true">
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27355 \begin_inset Quotes sld
27358 Extensions for Embedded C
27359 \begin_inset Quotes srd
27366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27372 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
27381 <row topline="true">
27382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27394 Latest datasheet of target CPU
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27407 <row topline="true" bottomline="true">
27408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27420 Revision history of datasheet
27424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27442 Application notes specifically for SDCC
27445 SDCC makes no claims about the completeness of this list and about up-to-datenes
27446 s or correctness of the application notes
27447 \begin_inset LatexCommand \index{Application notes}
27457 \begin_inset Tabular
27458 <lyxtabular version="3" rows="7" columns="3">
27460 <column alignment="block" valignment="top" leftline="true" width="17col%">
27461 <column alignment="block" valignment="top" leftline="true" width="27col%">
27462 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
27463 <row topline="true" bottomline="true">
27464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27475 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27498 <row topline="true">
27499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27515 Using the SDCC Compiler for the DS80C400
27516 \begin_inset LatexCommand \index{DS80C400}
27524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27530 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
27539 <row topline="true">
27540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27550 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
27556 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
27557 \begin_inset LatexCommand \index{DS89C4x0}
27561 Family of Microcontrollers
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27571 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
27580 <row topline="true">
27581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27587 Silicon Laboratories / Cygnal
27591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27597 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
27598 \begin_inset LatexCommand \index{IDE}
27606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27612 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
27621 <row topline="true">
27622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27628 Ramtron / Goal Semiconductor
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27638 Interfacing SDCC to Syn and Textpad
27642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27648 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27657 <row topline="true">
27658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27664 Ramtron / Goal Semiconductor
27668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27674 Installing and Configuring SDCC and Crimson Editor
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27684 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27693 <row topline="true" bottomline="true">
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27710 MSC12xx Programming with SDCC
27714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27720 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
27739 Some questions answered, some pointers given - it might be time to in turn
27747 can you solve your project with the selected microcontroller? Would you
27748 find out early or rather late that your target is too small/slow/whatever?
27749 Can you switch to a slightly better device if it doesn't fit?
27752 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
27753 and/or another programming language be more adequate? Would an operating
27754 system on the target device help?
27757 if you solved the problem, will the marketing department be happy?
27760 if the marketing department is happy, will customers be happy?
27763 if you're the project manager, marketing department and maybe even the customer
27764 in one person, have you tried to see the project from the outside?
27767 is the project done if you think it is done? Or is just that other interface/pro
27768 tocol/feature/configuration/option missing? How about website, manual(s),
27769 internationali(z|s)ation, packaging, labels, 2nd source for components,
27770 electromagnetic compatability/interference, documentation for production,
27771 production test software, update mechanism, patent issues?
27774 is your project adequately positioned in that magic triangle: fame, fortune,
27778 Maybe not all answers to these questions are known and some answers may
27783 , nevertheless knowing these questions may help you to avoid burnout
27788 burnout is bad for electronic devices, programmers and motorcycle tyres
27793 Chances are you didn't want to hear some of them...
27797 \begin_inset LatexCommand \index{Support}
27804 SDCC has grown to be a large project.
27805 The compiler alone (without the preprocessor, assembler and linker) is
27806 well over 150,000 lines of code (blank stripped).
27807 The open source nature of this project is a key to its continued growth
27809 You gain the benefit and support of many active software developers and
27811 Is SDCC perfect? No, that's why we need your help.
27812 The developers take pride in fixing reported bugs.
27813 You can help by reporting the bugs and helping other SDCC users.
27814 There are lots of ways to contribute, and we encourage you to take part
27815 in making SDCC a great software package.
27819 The SDCC project is hosted on the SDCC sourceforge site at
27820 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
27825 You'll find the complete set of mailing lists
27826 \begin_inset LatexCommand \index{Mailing list(s)}
27830 , forums, bug reporting system, patch submission
27831 \begin_inset LatexCommand \index{Patch submission}
27836 \begin_inset LatexCommand \index{download}
27840 area and Subversion code repository
27841 \begin_inset LatexCommand \index{Subversion code repository}
27849 \begin_inset LatexCommand \index{Bug reporting}
27854 \begin_inset LatexCommand \index{Reporting bugs}
27861 The recommended way of reporting bugs is using the infrastructure of the
27863 You can follow the status of bug reports there and have an overview about
27867 Bug reports are automatically forwarded to the developer mailing list and
27868 will be fixed ASAP.
27869 When reporting a bug, it is very useful to include a small test program
27870 (the smaller the better) which reproduces the problem.
27871 If you can isolate the problem by looking at the generated assembly code,
27872 this can be very helpful.
27873 Compiling your program with the -
27886 \begin_inset LatexCommand \index{-\/-dumpall}
27890 option can sometimes be useful in locating optimization problems.
27891 When reporting a bug please make sure you:
27894 Attach the code you are compiling with SDCC.
27898 Specify the exact command you use to run SDCC, or attach your Makefile.
27902 Specify the SDCC version (type "
27908 "), your platform, and operating system.
27912 Provide an exact copy of any error message or incorrect output.
27916 Put something meaningful in the subject of your message.
27919 Please attempt to include these 5 important parts, as applicable, in all
27920 requests for support or when reporting any problems or bugs with SDCC.
27921 Though this will make your message lengthy, it will greatly improve your
27922 chance that SDCC users and developers will be able to help you.
27923 Some SDCC developers are frustrated by bug reports without code provided
27924 that they can use to reproduce and ultimately fix the problem, so please
27925 be sure to provide sample code if you are reporting a bug!
27928 Please have a short check that you are using a recent version of SDCC and
27929 the bug is not yet known.
27930 This is the link for reporting bugs:
27931 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
27936 With SDCC on average having more than 200 downloads
27937 \begin_inset LatexCommand \index{download}
27941 on sourceforge per day
27946 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
27947 between 2002 and 2005.
27948 This does not include other methods of distribution.
27952 there must be some users.
27953 So it's not exactly easy to find a new bug.
27954 If you find one we need it:
27956 reporting bugs is good
27961 Requesting Features
27962 \begin_inset LatexCommand \label{sub:Requesting-Features}
27967 \begin_inset LatexCommand \index{Feature request}
27972 \begin_inset LatexCommand \index{Requesting features}
27979 Like bug reports feature requests are forwarded to the developer mailing
27981 This is the link for requesting features:
27982 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
27992 Like bug reports contributed patches are forwarded to the developer mailing
27994 This is the link for submitting patches
27995 \begin_inset LatexCommand \index{Patch submission}
28000 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28007 You need to specify some parameters to the
28011 command for the patches to be useful.
28012 If you modified more than one file a patch created f.e.
28017 \begin_inset Quotes sld
28020 diff -Naur unmodified_directory modified_directory >my_changes.patch
28021 \begin_inset Quotes srd
28027 will be fine, otherwise
28031 \begin_inset Quotes sld
28034 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28035 \begin_inset Quotes srd
28048 These links should take you directly to the
28049 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28058 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28059 automated messages (mid 2003)
28064 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28069 \begin_inset LatexCommand \index{Mailing list(s)}
28073 and forums are archived and searchable so if you are lucky someone already
28074 had a similar problem.
28075 While mails to the lists themselves are delivered promptly their web front
28076 end on sourceforge sometimes shows a severe time lag (up to several weeks),
28077 if you're seriously using SDCC please consider subscribing to the lists.
28083 You can follow the status of the Subversion version
28084 \begin_inset LatexCommand \index{version}
28088 of SDCC by watching the Changelog
28089 \begin_inset LatexCommand \index{Changelog}
28093 in the Subversion repository
28096 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28103 Subversion Source Code Repository
28112 or the filenames of the snapshot versions of SDCC include date and its
28114 \begin_inset LatexCommand \index{Subversion code repository}
28119 Subversion allows to download the source of recent or previous versions
28121 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28125 (by number or by date).
28126 An on-line source code browser and detailled instructions are also available
28128 SDCC versions starting from 1999 up to now are available (currently the
28129 versions prior to the conversion from cvs
28130 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28134 to Subversion (April 2006) are either by accessible by Subversion or by
28139 \begin_inset LatexCommand \index{Release policy}
28146 Historically there often were long delays between official releases and
28147 the sourceforge download area tends to get not updated at all.
28148 Excuses in the past might have referred to problems with live range analysis,
28149 but as this was fixed a while ago, the current problem is that another
28150 excuse has to be found.
28151 Kidding aside, we have to get better there! On the other hand there are
28152 daily snapshots available at
28153 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
28157 , and you can always build the very last version (hopefully with many bugs
28158 fixed, and features added) from the source code available at
28159 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
28165 \begin_inset LatexCommand \index{wiki}
28170 \begin_inset LatexCommand \index{Release wiki}
28175 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
28179 also holds some information about past and future releases.
28183 \begin_inset LatexCommand \index{Examples}
28190 You'll find some small examples in the directory
28192 sdcc/device/examples/.
28195 More examples and libraries are available at
28197 The SDCC Open Knowledge Resource
28198 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
28205 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
28216 I did insert a reference to Paul's web site here although it seems rather
28217 dedicated to a specific 8032 board (I think it's okay because it f.e.
28218 shows LCD/Harddisc interface and has a free 8051 monitor.
28219 Independent 8032 board vendors face hard competition of heavily subsidized
28220 development boards anyway).
28223 Maybe we should include some links to real world applications.
28224 Preferably pointer to pointers (one for each architecture) so this stays
28233 \begin_inset LatexCommand \label{sec:Quality-control}
28238 \begin_inset LatexCommand \index{Quality control}
28245 The compiler is passed through nightly compile and build checks.
28251 \begin_inset LatexCommand \index{Regression test}
28255 check that SDCC itself compiles flawlessly on several host platforms (i386,
28256 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
28257 the quality of the code generated by SDCC by running the code for several
28258 target platforms through simulators.
28259 The regression test suite comprises more than 100 files which expand to
28260 more than 500 test cases which include more than 4500 tests.
28261 The results of these tests are published daily on SDCC's snapshot page
28262 (click on the red or green symbols on the right side of
28263 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
28270 There is a separate document
28273 \begin_inset LatexCommand \index{Test suite}
28280 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28284 about the regression test suite.
28287 You'll find the test code in the directory
28289 sdcc/support/regression
28292 You can run these tests manually by running
28296 in this directory (or f.e.
28301 \begin_inset Quotes sld
28305 \begin_inset Quotes srd
28311 if you don't want to run the complete tests).
28312 The test code might also be interesting if you want to look for examples
28313 \begin_inset LatexCommand \index{Examples}
28317 checking corner cases of SDCC or if you plan to submit patches
28318 \begin_inset LatexCommand \index{Patch submission}
28325 The 14bit pic port uses a different set of regression tests
28326 \begin_inset LatexCommand \index{Regression test (PIC14)}
28330 , you'll find them in the directory
28332 sdcc/src/regression
28337 Use of SDCC in Education
28349 the phrase "use in education" might evoke the association "
28353 fit for use in education".
28354 This connotation is not intended but nevertheless risked as the licensing
28355 of SDCC makes it difficult to offer educational discounts
28360 If your rationales are to:
28363 give students a chance to understand the
28367 steps of code generation
28370 have a curriculum that can be extended for years.
28371 Then you could use an fpga board as target and your curriculum will seamlessly
28372 extend from logic synthesis (
28373 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
28378 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
28382 ), over assembly programming, to C to FPGA compilers (
28383 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
28390 be able to insert excursions about skills like using a revision control
28391 system, submitting/applying patches, using a type-setting (as opposed to
28392 word-processing) engine LyX/LaTeX, using
28393 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
28398 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
28402 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
28403 Source Software, CPU simulation, compiler regression tests
28404 \begin_inset LatexCommand \index{Regression test}
28411 And if there should be a shortage of ideas then you can always point students
28412 to the ever-growing feature request list
28413 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28420 not tie students to a specific host platform and instead allow them to use
28425 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
28427 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
28434 not encourage students to use illegal copies of educational software
28437 be immune to licensing/availability/price changes of the chosen tool chain
28440 be able to change to a new target platform without having to adopt a new
28444 have complete control over and insight into the tool chain
28447 make your students aware about the pros and cons of open source software
28451 give back to the public as you are probably at least partially publically
28455 give students a chance to publically prove their skills and to possibly
28456 see a world wide impact
28459 then SDCC is probably among the first choices.
28461 Well, probably SDCC might be the only choice.
28465 SDCC Technical Data
28469 \begin_inset LatexCommand \index{Optimizations}
28476 SDCC performs a host of standard optimizations in addition to some MCU specific
28481 Sub-expression Elimination
28482 \begin_inset LatexCommand \index{Subexpression elimination}
28489 The compiler does local and
28515 will be translated to
28527 Some subexpressions are not as obvious as the above example, e.g.:
28537 In this case the address arithmetic a->b[i] will be computed only once;
28538 the equivalent code in C would be.
28550 The compiler will try to keep these temporary variables in registers.
28553 Dead-Code Elimination
28554 \begin_inset LatexCommand \index{Dead-code elimination}
28575 i = 1; \SpecialChar ~
28584 global = 1;\SpecialChar ~
28598 global = 3;\SpecialChar ~
28623 \begin_inset LatexCommand \index{Copy propagation}
28679 Note: the dead stores created by this copy propagation will be eliminated
28680 by dead-code elimination.
28684 \begin_inset LatexCommand \index{Loop optimization}
28689 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
28696 Two types of loop optimizations are done by SDCC
28704 of loop induction variables.
28705 In addition to the strength reduction the optimizer marks the induction
28706 variables and the register allocator tries to keep the induction variables
28707 in registers for the duration of the loop.
28708 Because of this preference of the register allocator
28709 \begin_inset LatexCommand \index{Register allocation}
28713 , loop induction optimization causes an increase in register pressure, which
28714 may cause unwanted spilling of other temporary variables into the stack
28715 \begin_inset LatexCommand \index{stack}
28720 The compiler will generate a warning message when it is forced to allocate
28721 extra space either on the stack or data space.
28722 If this extra space allocation is undesirable then induction optimization
28723 can be eliminated either for the entire source file (with -
28735 -noinduction option) or for a given function only using #pragma\SpecialChar ~
28737 \begin_inset LatexCommand \index{\#pragma noinduction}
28750 for (i = 0 ; i < 100 ; i ++)
28766 for (i = 0; i < 100; i++)
28775 As mentioned previously some loop invariants are not as apparent, all static
28776 address computations are also moved out of the loop.
28781 \begin_inset LatexCommand \index{Strength reduction}
28785 , this optimization substitutes an expression by a cheaper expression:
28790 for (i=0;i < 100; i++)
28808 for (i=0;i< 100;i++) {
28814 ar[itemp1] = itemp2;
28832 The more expensive multiplication
28833 \begin_inset LatexCommand \index{Multiplication}
28837 is changed to a less expensive addition.
28841 \begin_inset LatexCommand \index{Loop reversing}
28848 This optimization is done to reduce the overhead of checking loop boundaries
28849 for every iteration.
28850 Some simple loops can be reversed and implemented using a
28851 \begin_inset Quotes eld
28854 decrement and jump if not zero
28855 \begin_inset Quotes erd
28859 SDCC checks for the following criterion to determine if a loop is reversible
28860 (note: more sophisticated compilers use data-dependency analysis to make
28861 this determination, SDCC uses a more simple minded analysis).
28864 The 'for' loop is of the form
28870 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
28880 The <for body> does not contain
28881 \begin_inset Quotes eld
28885 \begin_inset Quotes erd
28889 \begin_inset Quotes erd
28895 All goto's are contained within the loop.
28898 No function calls within the loop.
28901 The loop control variable <sym> is not assigned any value within the loop
28904 The loop control variable does NOT participate in any arithmetic operation
28908 There are NO switch statements in the loop.
28911 Algebraic Simplifications
28914 SDCC does numerous algebraic simplifications, the following is a small sub-set
28915 of these optimizations.
28920 i = j + 0;\SpecialChar ~
28924 /* changed to: */\SpecialChar ~
28930 i /= 2;\SpecialChar ~
28937 /* changed to: */\SpecialChar ~
28944 = j - j;\SpecialChar ~
28948 /* changed to: */\SpecialChar ~
28954 i = j / 1;\SpecialChar ~
28958 /* changed to: */\SpecialChar ~
28965 Note the subexpressions
28966 \begin_inset LatexCommand \index{Subexpression}
28970 given above are generally introduced by macro expansions or as a result
28971 of copy/constant propagation.
28974 'switch' Statements
28975 \begin_inset LatexCommand \label{sub:'switch'-Statements}
28980 \begin_inset LatexCommand \index{switch statement}
28987 SDCC can optimize switch statements to jump tables
28988 \begin_inset LatexCommand \index{jump tables}
28993 It makes the decision based on an estimate of the generated code size.
28994 SDCC is quite liberal in the requirements for jump table generation:
28997 The labels need not be in order, and the starting number need not be one
28998 or zero, the case labels are in numerical sequence or not too many case
28999 labels are missing.
29005 switch(i) {\SpecialChar ~
29036 case 4: ...\SpecialChar ~
29068 case 5: ...\SpecialChar ~
29100 case 3: ...\SpecialChar ~
29131 case 6: ...\SpecialChar ~
29163 case 7: ...\SpecialChar ~
29195 case 8: ...\SpecialChar ~
29227 case 9: ...\SpecialChar ~
29259 case 10: ...\SpecialChar ~
29290 case 11: ...\SpecialChar ~
29357 Both the above switch statements will be implemented using a jump-table.
29358 The example to the right side is slightly more efficient as the check for
29359 the lower boundary of the jump-table is not needed.
29363 The number of case labels is not larger than supported by the target architectur
29367 If the case labels are not in numerical sequence ('gaps' between cases)
29368 SDCC checks whether a jump table with additionally inserted dummy cases
29369 is still attractive.
29373 If the starting number is not zero and a check for the lower boundary of
29374 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
29379 Switch statements which have large gaps in the numeric sequence or those
29380 that have too many case labels can be split into more than one switch statement
29381 for efficient code generation, e.g.:
29461 If the above switch statement is broken down into two switch statements
29551 then both the switch statements will be implemented using jump-tables whereas
29552 the unmodified switch statement will not be.
29559 There might be reasons which SDCC cannot know about to either favour or
29560 not favour jump tables.
29561 If the target system has to be as quick for the last switch case as for
29562 the first (pro jump table), or if the switch argument is known to be zero
29563 in the majority of the cases (contra jump table).
29570 The pragma nojtbound
29571 \begin_inset LatexCommand \index{\#pragma nojtbound}
29575 can be used to turn off checking the
29588 It has no effect if a default label is supplied.
29589 Use of this pragma is dangerous: if the switch
29590 \begin_inset LatexCommand \index{switch statement}
29594 argument is not matched by a case statement the processor will happily
29598 Bit-shifting Operations
29599 \begin_inset LatexCommand \index{Bit shifting}
29606 Bit shifting is one of the most frequently used operation in embedded programmin
29608 SDCC tries to implement bit-shift operations in the most efficient way
29624 generates the following code:
29641 In general SDCC will never setup a loop if the shift count is known.
29684 \begin_inset LatexCommand \index{Bit rotation}
29691 A special case of the bit-shift operation is bit rotation
29692 \begin_inset LatexCommand \index{rotating bits}
29696 , SDCC recognizes the following expression to be a left bit-rotation:
29706 char i;\SpecialChar ~
29717 /* unsigned is needed for rotation */
29722 i = ((i << 1) | (i >> 7));
29731 will generate the following code:
29750 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
29751 ns of this case will also be recognized as bit-rotation, i.e.:
29756 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
29759 Nibble and Byte Swapping
29762 Other special cases of the bit-shift operations are nibble or byte swapping
29763 \begin_inset LatexCommand \index{swapping nibbles/bytes}
29767 , SDCC recognizes the following expressions:
29790 i = ((i << 4) | (i >> 4));
29796 j = ((j << 8) | (j >> 8));
29799 and generates a swap instruction for the nibble swapping
29800 \begin_inset LatexCommand \index{Nibble swapping}
29804 or move instructions for the byte swapping
29805 \begin_inset LatexCommand \index{Byte swapping}
29811 \begin_inset Quotes sld
29815 \begin_inset Quotes srd
29818 example can be used to convert from little to big-endian or vice versa.
29819 If you want to change the endianness of a
29823 integer you have to cast to
29830 Note that SDCC stores numbers in little-endian
29835 Usually 8-bit processors don't care much about endianness.
29836 This is not the case for the standard 8051 which only has an instruction
29842 \begin_inset LatexCommand \index{DPTR}
29850 so little-endian is the more efficient byte order.
29855 \begin_inset LatexCommand \index{little-endian}
29860 \begin_inset LatexCommand \index{Endianness}
29865 lowest order first).
29869 \begin_inset LatexCommand \index{Highest Order Bit}
29874 \begin_inset LatexCommand \index{Any Order Bit}
29881 It is frequently required to obtain the highest order bit of an integral
29882 type (long, int, short or char types).
29883 Also obtaining any other order bit is not uncommon.
29884 SDCC recognizes the following expressions to yield the highest order bit
29885 and generates optimized code for it, e.g.:
29898 unsigned char hob1, aob1;
29902 bit hob2, hob3, aob2,
29912 hob1 = (gint >> 15) & 1;
29916 hob2 = (gint >> 15) & 1;
29920 hob3 = gint & 0x8000;
29925 aob1 = (gint >> 9) & 1;
29929 aob2 = (gint >> 8) & 1;
29933 aob3 = gint & 0x0800;
29943 will generate the following code:
29976 000A E5*01\SpecialChar ~
30003 000C 23\SpecialChar ~
30034 000D 54 01\SpecialChar ~
30062 000F F5*02\SpecialChar ~
30117 0011 E5*01\SpecialChar ~
30145 0013 33\SpecialChar ~
30175 0014 92*00\SpecialChar ~
30231 0016 E5*01\SpecialChar ~
30258 0018 33\SpecialChar ~
30288 0019 92*01\SpecialChar ~
30344 001B E5*01\SpecialChar ~
30403 001E 54 01\SpecialChar ~
30430 0020 F5*03\SpecialChar ~
30486 0022 E5*01\SpecialChar ~
30513 0024 13\SpecialChar ~
30543 0025 92*02\SpecialChar ~
30599 0027 E5*01\SpecialChar ~
30627 A2 E3\SpecialChar ~
30654 002B 92*03\SpecialChar ~
30682 Other variations of these cases however will
30687 They are standard C expressions, so I heartily recommend these be the only
30688 way to get the highest order bit, (it is portable).
30689 Of course it will be recognized even if it is embedded in other expressions,
30695 xyz = gint + ((gint >> 15) & 1);
30698 will still be recognized.
30702 \begin_inset LatexCommand \index{Higher Order Byte}
30706 / Higher Order Word
30707 \begin_inset LatexCommand \index{Higher Order Word}
30714 It is also frequently required to obtain a higher order byte or word of
30715 a larger integral type (long, int or short types).
30716 SDCC recognizes the following expressions to yield the higher order byte
30717 or word and generates optimized code for it, e.g.:
30724 unsigned long int glong;
30732 unsigned char hob1,
30737 unsigned int how1, how2;
30746 hob1 = (gint >> 8) & 0xFF;
30750 hob2 = glong >> 24;
30754 how1 = (glong >> 16) & 0xFFFF;
30769 will generate the following code:
30802 0037 85*01*06\SpecialChar ~
30824 _foo_hob1_1_1,(_gint + 1)
30855 003A 85*05*07\SpecialChar ~
30877 _foo_hob2_1_1,(_glong + 3)
30907 003D 85*04*08\SpecialChar ~
30930 _foo_how1_1_1,(_glong + 2)
30932 0040 85*05*09\SpecialChar ~
30957 0043 85*03*0A\SpecialChar ~
30979 _foo_how2_1_1,(_glong + 1)
30981 0046 85*04*0B\SpecialChar ~
31004 (_foo_how2_1_1 + 1),(_glong + 2)
31007 Again, variations of these cases may
31012 They are standard C expressions, so I heartily recommend these be the only
31013 way to get the higher order byte/word, (it is portable).
31014 Of course it will be recognized even if it is embedded in other expressions,
31020 xyz = gint + ((gint >> 8) & 0xFF);
31023 will still be recognized.
31027 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31032 \begin_inset LatexCommand \index{Peephole optimizer}
31039 The compiler uses a rule based, pattern matching and re-writing mechanism
31040 for peep-hole optimization.
31045 a peep-hole optimizer by Christopher W.
31046 Fraser (cwfraser\SpecialChar ~
31049 A default set of rules are compiled into the compiler, additional rules
31050 may be added with the
31065 \begin_inset LatexCommand \index{-\/-peep-file}
31072 The rule language is best illustrated with examples.
31096 The above rule will change the following assembly
31097 \begin_inset LatexCommand \index{Assembler routines}
31119 Note: All occurrences of a
31123 (pattern variable) must denote the same string.
31124 With the above rule, the assembly sequence:
31134 will remain unmodified.
31138 Other special case optimizations may be added by the
31157 some variants of the 8051 MCU
31158 \begin_inset LatexCommand \index{MCS51 variants}
31171 The following two rules will change all
31190 replace { lcall %1 } by { acall %1 }
31192 replace { ljmp %1 } by { ajmp %1 }
31197 inline-assembler code
31199 is also passed through the peep hole optimizer, thus the peephole optimizer
31200 can also be used as an assembly level macro expander.
31201 The rules themselves are MCU dependent whereas the rule language infra-structur
31202 e is MCU independent.
31203 Peephole optimization rules for other MCU can be easily programmed using
31208 The syntax for a rule is as follows:
31213 rule := replace [ restart ] '{' <assembly sequence> '
31251 <assembly sequence> '
31269 '}' [if <functionName> ] '
31274 <assembly sequence> := assembly instruction (each instruction including
31275 labels must be on a separate line).
31279 The optimizer will apply to the rules
31280 one by one from the top in the sequence of their appearance, it will terminate
31281 when all rules are exhausted.
31282 If the 'restart' option is specified, then the optimizer will start matching
31283 the rules again from the top, this option for a rule is expensive (performance)
31284 , it is intended to be used in situations where a transformation will trigger
31285 the same rule again.
31286 An example of this (not a good one, it has side effects) is the following
31309 Note that the replace pattern cannot be a blank, but can be a comment line.
31310 Without the 'restart' option only the innermost 'pop' 'push' pair would
31311 be eliminated, i.e.:
31341 the restart option the rule will be applied again to the resulting code
31342 and then all the pop-push pairs will be eliminated to yield:
31352 A conditional function can be attached to a rule.
31353 Attaching rules are somewhat more involved, let me illustrate this with
31380 The optimizer does a look-up of a function name table defined in function
31385 in the source file SDCCpeeph.c, with the name
31390 If it finds a corresponding entry the function is called.
31391 Note there can be no parameters specified for these functions, in this
31396 is crucial, since the function
31400 expects to find the label in that particular variable (the hash table containin
31401 g the variable bindings is passed as a parameter).
31402 If you want to code more such functions, take a close look at the function
31403 labelInRange and the calling mechanism in source file SDCCpeeph.c.
31404 Currently implemented are
31406 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
31407 24bitMode, portIsDS390, 24bitModeAndPortDS390
31416 I know this whole thing is a little kludgey, but maybe some day we will
31417 have some better means.
31418 If you are looking at this file, you will see the default rules that are
31419 compiled into the compiler, you can add your own rules in the default set
31420 there if you get tired of specifying the -
31436 \begin_inset LatexCommand \index{ANSI-compliance}
31441 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
31448 The latest publically available version of the standard
31450 ISO/IEC 9899 - Programming languages - C
31452 should be available at:
31453 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31462 Deviations from the compliance:
31465 functions are not reentrant
31466 \begin_inset LatexCommand \index{reentrant}
31470 unless explicitly declared as such or the
31485 \begin_inset LatexCommand \index{-\/-stack-auto}
31491 command line option is specified.
31495 \begin_inset LatexCommand \index{struct}
31500 \begin_inset LatexCommand \index{union}
31504 cannot be assigned values directly, cannot be passed as function parameters
31505 or assigned to each other and cannot be a return value
31506 \begin_inset LatexCommand \index{return value}
31510 from a function, e.g.:
31536 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
31555 s parms) /* invalid in SDCC although allowed in ANSI */
31577 return rets; /* is invalid in SDCC although allowed in ANSI */
31583 initialization of structure arrays must be fully braced.
31589 struct s { char x } a[] = {1, 2};\SpecialChar ~
31594 /* invalid in SDCC */
31597 } a[] = {{1}, {2}}; /* OK */
31602 \begin_inset LatexCommand \index{long long (not supported)}
31607 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
31615 \begin_inset LatexCommand \index{double (not supported)}
31619 ' precision floating point
31620 \begin_inset LatexCommand \index{Floating point support}
31628 \begin_inset LatexCommand \index{K\&R style}
31632 function declarations are NOT allowed.
31638 foo(i,j) /* this old style of function declarations */
31640 int i,j; /* are valid
31641 in ANSI but not valid in SDCC */
31656 Most enhancements in C99 are not supported, f.e.:
31664 \begin_inset LatexCommand \index{inline (not supported)}
31670 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
31676 can be used as a work around */
31684 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
31688 Certain words that are valid identifiers in the standard may be reserved
31689 words in SDCC unless the
31704 \begin_inset LatexCommand \index{-\/-std-c89}
31721 \begin_inset LatexCommand \index{-\/-std-c99}
31727 command line options are used.
31728 These may include (depending on the selected processor): 'at', 'banked',
31729 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
31730 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
31731 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
31733 Compliant equivalents of these keywords are always available in a form
31734 that begin with two underscores
31735 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
31740 '__data' instead of 'data'.
31743 Cyclomatic Complexity
31744 \begin_inset LatexCommand \index{Cyclomatic complexity}
31751 Cyclomatic complexity of a function is defined as the number of independent
31752 paths the program can take during execution of the function.
31753 This is an important number since it defines the number test cases you
31754 have to generate to validate the function.
31755 The accepted industry standard for complexity number is 10, if the cyclomatic
31756 complexity reported by SDCC exceeds 10 you should think about simplification
31757 of the function logic.
31758 Note that the complexity level is not related to the number of lines of
31759 code in a function.
31760 Large functions can have low complexity, and small functions can have large
31766 SDCC uses the following formula to compute the complexity:
31771 complexity = (number of edges in control flow graph) - (number of nodes
31772 in control flow graph) + 2;
31776 Having said that the industry standard is 10,
31777 you should be aware that in some cases it be may unavoidable to have a
31778 complexity level of less than 10.
31779 For example if you have switch statement with more than 10 case labels,
31780 each case label adds one to the complexity level.
31781 The complexity level is by no means an absolute measure of the algorithmic
31782 complexity of the function, it does however provide a good starting point
31783 for which functions you might look at for further optimization.
31786 Retargetting for other Processors
31789 The issues for retargetting the compiler are far too numerous to be covered
31791 What follows is a brief description of each of the seven phases of the
31792 compiler and its MCU dependency.
31795 Parsing the source and building the annotated parse tree.
31796 This phase is largely MCU independent (except for the language extensions).
31797 Syntax & semantic checks are also done in this phase, along with some initial
31798 optimizations like back patching labels and the pattern matching optimizations
31799 like bit-rotation etc.
31802 The second phase involves generating an intermediate code which can be easy
31803 manipulated during the later phases.
31804 This phase is entirely MCU independent.
31805 The intermediate code generation assumes the target machine has unlimited
31806 number of registers, and designates them with the name iTemp.
31807 The compiler can be made to dump a human readable form of the code generated
31823 This phase does the bulk of the standard optimizations and is also MCU independe
31825 This phase can be broken down into several sub-phases:
31829 Break down intermediate
31830 code (iCode) into basic blocks.
31832 Do control flow & data flow analysis on the
31835 Do local common subexpression elimination, then global subexpressio
31838 Dead code elimination
31842 If loop optimizations
31843 caused any changes then do 'global subexpression elimination' and 'dead
31844 code elimination' again.
31847 This phase determines the live-ranges; by live range I mean those iTemp
31848 variables defined by the compiler that still survive after all the optimization
31850 Live range analysis
31851 \begin_inset LatexCommand \index{Live range analysis}
31855 is essential for register allocation, since these computation determines
31856 which of these iTemps will be assigned to registers, and for how long.
31859 Phase five is register allocation.
31860 There are two parts to this process.
31864 The first part I call 'register packing'
31865 (for lack of a better term).
31866 In this case several MCU specific expression folding is done to reduce
31871 The second part is more MCU independent and deals with
31872 allocating registers to the remaining live ranges.
31873 A lot of MCU specific code does creep into this phase because of the limited
31874 number of index registers available in the 8051.
31877 The Code generation phase is (unhappily), entirely MCU dependent and very
31878 little (if any at all) of this code can be reused for other MCU.
31879 However the scheme for allocating a homogenized assembler operand for each
31880 iCode operand may be reused.
31883 As mentioned in the optimization section the peep-hole optimizer is rule
31884 based system, which can reprogrammed for other MCUs.
31887 More information is available in a wiki
31888 \begin_inset LatexCommand \index{wiki}
31893 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
31897 ) and in the thread
31898 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
31906 \begin_inset LatexCommand \index{Compiler internals}
31913 The anatomy of the compiler
31914 \begin_inset LatexCommand \label{sub:The-anatomy-of}
31923 This is an excerpt from an article published in Circuit Cellar Magazine
31929 It's a little outdated (the compiler is much more efficient now and user/develo
31930 per friendly), but pretty well exposes the guts of it all.
31936 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
31937 It is fairly easy to retarget for other 8-bit MCU.
31938 Here we take a look at some of the internals of the compiler.
31943 \begin_inset LatexCommand \index{Parsing}
31950 Parsing the input source file and creating an AST (Annotated Syntax Tree
31951 \begin_inset LatexCommand \index{Annotated syntax tree}
31956 This phase also involves propagating types (annotating each node of the
31957 parse tree with type information) and semantic analysis.
31958 There are some MCU specific parsing rules.
31959 For example the storage classes, the extended storage classes are MCU specific
31960 while there may be a xdata storage class for 8051 there is no such storage
31961 class for z80 or Atmel AVR.
31962 SDCC allows MCU specific storage class extensions, i.e.
31963 xdata will be treated as a storage class specifier when parsing 8051 C
31964 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
31969 \begin_inset LatexCommand \index{iCode}
31976 Intermediate code generation.
31977 In this phase the AST is broken down into three-operand form (iCode).
31978 These three operand forms are represented as doubly linked lists.
31979 ICode is the term given to the intermediate form generated by the compiler.
31980 ICode example section shows some examples of iCode generated for some simple
31981 C source functions.
31985 \begin_inset LatexCommand \index{Optimizations}
31992 Bulk of the target independent optimizations is performed in this phase.
31993 The optimizations include constant propagation, common sub-expression eliminati
31994 on, loop invariant code movement, strength reduction of loop induction variables
31995 and dead-code elimination.
31998 Live range analysis
31999 \begin_inset LatexCommand \index{Live range analysis}
32006 During intermediate code generation phase, the compiler assumes the target
32007 machine has infinite number of registers and generates a lot of temporary
32009 The live range computation determines the lifetime of each of these compiler-ge
32010 nerated temporaries.
32011 A picture speaks a thousand words.
32012 ICode example sections show the live range annotations for each of the
32014 It is important to note here, each iCode is assigned a number in the order
32015 of its execution in the function.
32016 The live ranges are computed in terms of these numbers.
32017 The from number is the number of the iCode which first defines the operand
32018 and the to number signifies the iCode which uses this operand last.
32021 Register Allocation
32022 \begin_inset LatexCommand \index{Register allocation}
32029 The register allocation determines the type and number of registers needed
32031 In most MCUs only a few registers can be used for indirect addressing.
32032 In case of 8051 for example the registers R0 & R1 can be used to indirectly
32033 address the internal ram and DPTR to indirectly address the external ram.
32034 The compiler will try to allocate the appropriate register to pointer variables
32036 ICode example section shows the operands annotated with the registers assigned
32038 The compiler will try to keep operands in registers as much as possible;
32039 there are several schemes the compiler uses to do achieve this.
32040 When the compiler runs out of registers the compiler will check to see
32041 if there are any live operands which is not used or defined in the current
32042 basic block being processed, if there are any found then it will push that
32043 operand and use the registers in this block, the operand will then be popped
32044 at the end of the basic block.
32048 There are other MCU specific considerations in this phase.
32049 Some MCUs have an accumulator; very short-lived operands could be assigned
32050 to the accumulator instead of a general-purpose register.
32056 Figure II gives a table of iCode
32057 \begin_inset LatexCommand \index{iCode}
32061 operations supported by the compiler.
32062 The code generation involves translating these operations into corresponding
32063 assembly code for the processor.
32064 This sounds overly simple but that is the essence of code generation.
32065 Some of the iCode operations are generated on a MCU specific manner for
32066 example, the z80 port does not use registers to pass parameters so the
32067 SEND and RECV iCode operations will not be generated, and it also does
32068 not support JUMPTABLES.
32077 \begin_inset Tabular
32078 <lyxtabular version="3" rows="39" columns="4">
32079 <features islongtable="true" headBottomDL="true">
32080 <column alignment="block" valignment="top" leftline="true" width="13col%">
32081 <column alignment="left" valignment="top" leftline="true" width="13col%">
32082 <column alignment="block" valignment="top" leftline="true" width="22col%">
32083 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32084 <row topline="true" bottomline="true" endhead="true">
32085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32094 \begin_inset LatexCommand \index{iCode}
32102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32133 <row topline="true">
32134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32150 IC_LEFT() IC_RESULT()
32154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32170 IC_RESULT = ! IC_LEFT;
32175 <row topline="true">
32176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32192 IC_LEFT() IC_RESULT()
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32202 Bitwise complement of
32206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32212 IC_RESULT = ~IC_LEFT;
32217 <row topline="true">
32218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32234 IC_LEFT() IC_RESULT()
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32244 Rotate right with carry
32248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32254 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
32259 <row topline="true">
32260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32276 IC_LEFT() IC_RESULT()
32280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32286 Rotate left with carry
32290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32296 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
32301 <row topline="true">
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32318 IC_LEFT() IC_RESULT()
32322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 Get the highest order bit of IC_LEFT
32332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32338 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
32343 <row topline="true">
32344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32360 IC_LEFT() IC_RESULT()
32364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32380 IC_RESULT = - IC_LEFT;
32385 <row topline="true">
32386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32412 Push the operand into stack
32416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32427 <row topline="true">
32428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32454 Pop the operand from the stack
32458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32469 <row topline="true">
32470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32486 IC_LEFT() IC_RESULT()
32490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32496 Call the function represented by IC_LEFT
32500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32506 IC_RESULT = IC_LEFT();
32511 <row topline="true">
32512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32528 IC_LEFT() IC_RESULT()
32532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32538 Call via function pointer
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32548 IC_RESULT = (*IC_LEFT)();
32553 <row topline="true">
32554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32580 Return the value in operand IC_LEFT
32584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32595 <row topline="true">
32596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32637 <row topline="true">
32638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32679 <row topline="true">
32680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32696 IC_LEFT() IC_RIGHT() IC_RESULT()
32700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32716 IC_RESULT = IC_LEFT + IC_RIGHT
32721 <row topline="true">
32722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32738 IC_LEFT() IC_RIGHT() IC_RESULT()
32742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32758 IC_RESULT = IC_LEFT - IC_RIGHT
32763 <row topline="true">
32764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32780 IC_LEFT() IC_RIGHT() IC_RESULT()
32784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32800 IC_RESULT = IC_LEFT * IC_RIGHT;
32805 <row topline="true">
32806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32822 IC_LEFT() IC_RIGHT() IC_RESULT()
32826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32842 IC_RESULT = IC_LEFT / IC_RIGHT;
32847 <row topline="true">
32848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32864 IC_LEFT() IC_RIGHT() IC_RESULT()
32868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32884 IC_RESULT = IC_LEFT % IC_RIGHT;
32889 <row topline="true">
32890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32906 IC_LEFT() IC_RIGHT() IC_RESULT()
32910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32926 IC_RESULT = IC_LEFT < IC_RIGHT;
32931 <row topline="true">
32932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32948 IC_LEFT() IC_RIGHT() IC_RESULT()
32952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32968 IC_RESULT = IC_LEFT > IC_RIGHT;
32973 <row topline="true">
32974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32990 IC_LEFT() IC_RIGHT() IC_RESULT()
32994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33010 IC_RESULT = IC_LEFT == IC_RIGHT;
33015 <row topline="true">
33016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33032 IC_LEFT() IC_RIGHT() IC_RESULT()
33036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33042 Logical and operation
33046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33052 IC_RESULT = IC_LEFT && IC_RIGHT;
33057 <row topline="true">
33058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33074 IC_LEFT() IC_RIGHT() IC_RESULT()
33078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33084 Logical or operation
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33094 IC_RESULT = IC_LEFT || IC_RIGHT;
33099 <row topline="true">
33100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33116 IC_LEFT() IC_RIGHT() IC_RESULT()
33120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33136 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33141 <row topline="true">
33142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33158 IC_LEFT() IC_RIGHT() IC_RESULT()
33162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33178 IC_RESULT = IC_LEFT | IC_RIGHT;
33183 <row topline="true">
33184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33200 IC_LEFT() IC_RIGHT() IC_RESULT()
33204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33220 IC_RESULT = IC_LEFT & IC_RIGHT;
33225 <row topline="true">
33226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33242 IC_LEFT() IC_RIGHT() IC_RESULT()
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33262 IC_RESULT = IC_LEFT << IC_RIGHT
33267 <row topline="true">
33268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33284 IC_LEFT() IC_RIGHT() IC_RESULT()
33288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33304 IC_RESULT = IC_LEFT >> IC_RIGHT
33309 <row topline="true">
33310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33328 IC_LEFT() IC_RESULT()
33332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33348 IC_RESULT = (*IC_LEFT);
33353 <row topline="true">
33354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33370 IC_RIGHT() IC_RESULT()
33374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33390 (*IC_RESULT) = IC_RIGHT;
33395 <row topline="true">
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33412 IC_RIGHT() IC_RESULT()
33416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33432 IC_RESULT = IC_RIGHT;
33437 <row topline="true">
33438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33454 IC_COND IC_TRUE IC_LABEL
33458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33465 If true label is present then jump to true label if condition is true else
33466 jump to false label if condition is false
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33476 if (IC_COND) goto IC_TRUE;
33482 If (!IC_COND) goto IC_FALSE;
33487 <row topline="true">
33488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33504 IC_LEFT() IC_RESULT()
33508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33524 IC_RESULT = &IC_LEFT();
33529 <row topline="true">
33530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33546 IC_JTCOND IC_JTLABELS
33550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33556 Jump to list of labels depending on the value of JTCOND
33560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33571 <row topline="true">
33572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33588 IC_RIGHT() IC_LEFT() IC_RESULT()
33592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33608 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
33613 <row topline="true">
33614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33640 This is used for passing parameters in registers;
33642 move IC_LEFT to the next
33643 available parameter register.
33647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33658 <row topline="true">
33659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33685 This is used for receiving parameters passed in registers;
33688 in the next parameter register to IC_RESULT
33692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33703 <row topline="true" bottomline="true">
33704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33711 (some more have been added)
33715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33761 In the original article Figure II was announced to be downloadable on
33766 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
33774 \begin_inset LatexCommand \index{iCode}
33781 This section shows some details of iCode.
33782 The example C code does not do anything useful; it is used as an example
33783 to illustrate the intermediate code generated by the compiler.
33795 /* This function does nothing useful.
33802 for the purpose of explaining iCode */
33805 short function (data
33814 short i=10; \SpecialChar ~
33816 /* dead initialization eliminated */
33822 /* dead initialization eliminated */
33850 /* compiler detects i,j to be induction
33855 for (i = 0, j = 10 ; i < 10 ; i++, j
33883 mul += i * 3; \SpecialChar ~
33885 /* this multiplication remains */
33892 j * 3;\SpecialChar ~
33894 /* this multiplication changed to addition */
33908 In addition to the operands each iCode contains information about the filename
33909 and line it corresponds to in the source file.
33910 The first field in the listing should be interpreted as follows:
33915 Filename(linenumber: iCode Execution sequence number : ICode hash table
33916 key : loop depth of the iCode).
33921 Then follows the human readable form of the ICode operation.
33922 Each operand of this triplet form can be of three basic types a) compiler
33923 generated temporary b) user defined variable c) a constant value.
33924 Note that local variables and parameters are replaced by compiler generated
33927 \begin_inset LatexCommand \index{Live range analysis}
33931 are computed only for temporaries (i.e.
33932 live ranges are not computed for global variables).
33934 \begin_inset LatexCommand \index{Register allocation}
33938 are allocated for temporaries only.
33939 Operands are formatted in the following manner:
33944 Operand Name [lr live-from : live-to ] { type information } [ registers
33950 As mentioned earlier the live ranges are computed in terms of the execution
33951 sequence number of the iCodes, for example
33953 the iTemp0 is live from (i.e.
33954 first defined in iCode with execution sequence number 3, and is last used
33955 in the iCode with sequence number 5).
33956 For induction variables such as iTemp21 the live range computation extends
33957 the lifetime from the start to the end of the loop.
33959 The register allocator
33960 used the live range information to allocate registers, the same registers
33961 may be used for different temporaries if their live ranges do not overlap,
33962 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
33963 ranges do not overlap.
33964 In addition the allocator also takes into consideration the type and usage
33965 of a temporary, for example itemp6 is a pointer to near space and is used
33966 as to fetch data from (i.e.
33967 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
33968 Some short lived temporaries are allocated to special registers which have
33969 meaning to the code generator e.g.
33970 iTemp13 is allocated to a pseudo register CC which tells the back end that
33971 the temporary is used only for a conditional jump the code generation makes
33972 use of this information to optimize a compare and jump ICode.
33976 \begin_inset LatexCommand \index{Loop optimization}
33980 performed by the compiler.
33981 It can detect induction variables iTemp21(i) and iTemp23(j).
33982 Also note the compiler does selective strength reduction
33983 \begin_inset LatexCommand \index{Strength reduction}
33988 the multiplication of an induction variable in line 18 (gint = j * 3) is
33989 changed to addition, a new temporary iTemp17 is allocated and assigned
33990 a initial value, a constant 3 is then added for each iteration of the loop.
33991 The compiler does not change the multiplication
33992 \begin_inset LatexCommand \index{Multiplication}
33996 in line 17 however since the processor does support an 8 * 8 bit multiplication.
33999 Note the dead code elimination
34000 \begin_inset LatexCommand \index{Dead-code elimination}
34004 optimization eliminated the dead assignments in line 7 & 8 to I and sum
34012 Sample.c (5:1:0:0) _entry($9) :
34017 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34022 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
34027 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34032 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34038 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34043 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34049 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34054 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34060 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34066 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34072 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34078 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34079 * int}[r0] + 0x2 {short}
34084 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34089 Sample.c(11:17:21:0)_whilebreak_0($3) :
34094 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34099 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34104 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34109 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34114 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34119 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34124 Sample.c(15:24:26:1)_forcond_0($4) :
34129 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34135 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34140 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34141 + ITemp21 [lr21:38]{short}[r4]
34146 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
34152 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
34153 + iTemp15 [lr29:30]{short}[r1]
34158 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
34164 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
34170 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
34176 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
34182 Sample.c(19:38:47:1) goto _forcond_0($4)
34187 Sample.c(19:39:48:0)_forbreak_0($7) :
34192 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
34193 + ITemp11 [lr19:40]{short}[r3]
34198 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
34203 Sample.c(20:42:51:0)_return($8) :
34208 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
34214 Finally the code generated for this function:
34255 ; ----------------------------------------------
34260 ; function function
34265 ; ----------------------------------------------
34275 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
34287 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
34299 ;_whilecontinue_0($1) :
34309 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
34314 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34373 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
34392 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
34439 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
34479 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
34505 ; iTemp6 [lr5:16]{_near * int}[r0] =
34510 ; iTemp6 [lr5:16]{_near * int}[r0] +
34527 ; goto _whilecontinue_0($1)
34539 ; _whilebreak_0($3) :
34549 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34561 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34573 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34585 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34604 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34633 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
34638 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34683 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
34688 ; iTemp21 [lr21:38]{short}[r4]
34714 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
34747 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
34752 ; iTemp15 [lr29:30]{short}[r1]
34771 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
34818 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
34865 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
34877 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
34891 cjne r5,#0xff,00104$
34903 ; goto _forcond_0($4)
34915 ; _forbreak_0($7) :
34925 ; ret iTemp24 [lr40:41]{short}
34968 A few words about basic block successors, predecessors and dominators
34971 Successors are basic blocks
34972 \begin_inset LatexCommand \index{Basic blocks}
34976 that might execute after this basic block.
34978 Predecessors are basic blocks
34979 that might execute before reaching this basic block.
34981 Dominators are basic
34982 blocks that WILL execute before reaching this basic block.
35015 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35018 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35021 c) domVect of [BB4] = BB1 ...
35022 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35029 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35039 Thanks to all the other volunteer developers who have helped with coding,
35040 testing, web-page creation, distribution sets, etc.
35041 You know who you are :-)
35049 Also thanks to Sourceforge
35050 \begin_inset LatexCommand \url{http://www.sf.net}
35054 which has hosted the project since 1999 and donates significant download
35055 bandwidth and probably more than
35065 CPU cycles per day.
35072 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35073 minutes for (configure+make+regression test), and there is (i386, amd64,
35074 alpha, ppc64, (mingw32), sparc, macosx).
35082 This document was initially written by Sandeep Dutta
35085 All product names mentioned herein may be trademarks
35086 \begin_inset LatexCommand \index{Trademarks}
35090 of their respective companies.
35097 To avoid confusion, the installation and building options for SDCC itself
35098 (chapter 2) are not part of the index.
35101 \begin_inset LatexCommand \printindex{}