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{-\/-main-return}
8605 This option can be used if the code generated is called by a monitor program
8606 or if the main routine includes an endless loop.
8607 This option results in slightly smaller code and saves two bytes of stack
8609 The return from the 'main'
8610 \begin_inset LatexCommand \index{main return}
8614 function will return to the function calling main.
8615 The default setting is to lock up i.e.
8623 \labelwidthstring 00.00.0000
8639 \begin_inset LatexCommand \index{-\/-nostdinc}
8645 This will prevent the compiler from passing on the default include path
8646 to the preprocessor.
8649 \labelwidthstring 00.00.0000
8665 \begin_inset LatexCommand \index{-\/-nostdlib}
8671 This will prevent the compiler from passing on the default library
8672 \begin_inset LatexCommand \index{Libraries}
8679 \labelwidthstring 00.00.0000
8695 \begin_inset LatexCommand \index{-\/-verbose}
8701 Shows the various actions the compiler is performing.
8704 \labelwidthstring 00.00.0000
8708 \begin_inset LatexCommand \index{-V}
8714 Shows the actual commands the compiler is executing.
8717 \labelwidthstring 00.00.0000
8733 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8739 Hides your ugly and inefficient c-code from the asm file, so you can always
8740 blame the compiler :)
8743 \labelwidthstring 00.00.0000
8759 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8765 Will not include peep-hole comments in the generated files.
8768 \labelwidthstring 00.00.0000
8784 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8790 Include i-codes in the asm file.
8791 Sounds like noise but is most helpful for debugging the compiler itself.
8794 \labelwidthstring 00.00.0000
8810 \begin_inset LatexCommand \index{-\/-less-pedantic}
8816 Disable some of the more pedantic warnings
8817 \begin_inset LatexCommand \index{Warnings}
8821 (jwk burps: please be more specific here, please!).
8824 \labelwidthstring 00.00.0000
8839 -disable-warning\SpecialChar ~
8841 \begin_inset LatexCommand \index{-\/-disable-warning}
8847 Disable specific warning with number <nnnn>.
8850 \labelwidthstring 00.00.0000
8866 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8872 Display the directories in the compiler's search path
8875 \labelwidthstring 00.00.0000
8891 \begin_inset LatexCommand \index{-\/-vc}
8897 Display errors and warnings using MSVC style, so you can use SDCC with
8898 the visual studio IDE
8899 \begin_inset LatexCommand \index{IDE}
8904 With SDCC both offering a GCC-like (the default) and a MSVC-like
8905 \begin_inset LatexCommand \index{MSVC output style}
8909 output style, integration into most programming editors should be straightforwa
8913 \labelwidthstring 00.00.0000
8929 \begin_inset LatexCommand \index{-\/-use-stdout}
8935 Send errors and warnings to stdout instead of stderr.
8938 \labelwidthstring 00.00.0000
8942 asmOption[,asmOption]
8945 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8950 Pass the asmOption to the assembler
8951 \begin_inset LatexCommand \index{Options assembler}
8956 \begin_inset LatexCommand \index{Assembler options}
8961 See file sdcc/as/doc/asxhtm.html for assembler options.cd
8964 \labelwidthstring 00.00.0000
8980 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8986 Generally follow the C89 standard, but allow SDCC features that conflict
8987 with the standard (default).
8990 \labelwidthstring 00.00.0000
9006 \begin_inset LatexCommand \index{-\/-std-c89}
9012 Follow the C89 standard and disable SDCC features that conflict with the
9016 \labelwidthstring 00.00.0000
9032 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9038 Generally follow the C99 standard, but allow SDCC features that conflict
9039 with the standard (incomplete support).
9042 \labelwidthstring 00.00.0000
9058 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9064 Follow the C99 standard and disable SDCC features that conflict with the
9065 standard (incomplete support).
9068 \labelwidthstring 00.00.0000
9086 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9091 <Name> The name to be used for the code
9092 \begin_inset LatexCommand \index{code}
9096 segment, default CSEG.
9097 This is useful if you need to tell the compiler to put the code in a special
9098 segment so you can later on tell the linker to put this segment in a special
9100 Can be used for instance when using bank switching to put the code in a
9104 \labelwidthstring 00.00.0000
9122 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9127 <Name> The name to be used for the const
9128 \begin_inset LatexCommand \index{code}
9132 segment, default CONST.
9133 This is useful if you need to tell the compiler to put the const data in
9134 a special segment so you can later on tell the linker to put this segment
9135 in a special place in memory.
9136 Can be used for instance when using bank switching to put the const data
9140 \labelwidthstring 00.00.0000
9155 -fdollars-in-identifiers
9156 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9162 Permit '$' as an identifier character
9165 \labelwidthstring 00.00.0000
9166 \added_space_bottom bigskip
9177 a SDCC compiler option but if you want
9181 warnings you can use a separate tool dedicated to syntax checking like
9183 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9188 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9193 \begin_inset LatexCommand \url{http://www.splint.org}
9198 To make your source files parseable by splint you will have to include
9204 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9208 in your source file and add brackets around extended keywords (like
9211 \begin_inset Quotes sld
9224 \begin_inset Quotes srd
9232 \begin_inset Quotes sld
9235 __interrupt\SpecialChar ~
9237 \begin_inset Quotes srd
9245 Splint has an excellent on line manual at
9246 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9250 and it's capabilities go beyond pure syntax checking.
9251 You'll need to tell splint the location of SDCC's include files so a typical
9252 command line could look like this:
9256 splint\SpecialChar ~
9258 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9264 Intermediate Dump Options
9265 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9270 \begin_inset LatexCommand \index{Options intermediate dump}
9275 \begin_inset LatexCommand \index{Intermediate dump options}
9282 The following options are provided for the purpose of retargetting and debugging
9284 They provide a means to dump the intermediate code (iCode
9285 \begin_inset LatexCommand \index{iCode}
9289 ) generated by the compiler in human readable form at various stages of
9290 the compilation process.
9291 More on iCodes see chapter
9292 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9297 \begin_inset Quotes srd
9300 The anatomy of the compiler
9301 \begin_inset Quotes srd
9307 \labelwidthstring 00.00.0000
9323 \begin_inset LatexCommand \index{-\/-dumpraw}
9329 This option will cause the compiler to dump the intermediate code into
9332 <source filename>.dumpraw
9334 just after the intermediate code has been generated for a function, i.e.
9335 before any optimizations are done.
9337 \begin_inset LatexCommand \index{Basic blocks}
9341 at this stage ordered in the depth first number, so they may not be in
9342 sequence of execution.
9345 \labelwidthstring 00.00.0000
9361 \begin_inset LatexCommand \index{-\/-dumpgcse}
9367 Will create a dump of iCode's, after global subexpression elimination
9368 \begin_inset LatexCommand \index{Global subexpression elimination}
9374 <source filename>.dumpgcse.
9377 \labelwidthstring 00.00.0000
9393 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9399 Will create a dump of iCode's, after deadcode elimination
9400 \begin_inset LatexCommand \index{Dead-code elimination}
9406 <source filename>.dumpdeadcode.
9409 \labelwidthstring 00.00.0000
9425 \begin_inset LatexCommand \index{-\/-dumploop}
9434 Will create a dump of iCode's, after loop optimizations
9435 \begin_inset LatexCommand \index{Loop optimization}
9441 <source filename>.dumploop.
9444 \labelwidthstring 00.00.0000
9460 \begin_inset LatexCommand \index{-\/-dumprange}
9469 Will create a dump of iCode's, after live range analysis
9470 \begin_inset LatexCommand \index{Live range analysis}
9476 <source filename>.dumprange.
9479 \labelwidthstring 00.00.0000
9495 \begin_inset LatexCommand \index{-\/-dumlrange}
9501 Will dump the life ranges
9502 \begin_inset LatexCommand \index{Live range analysis}
9509 \labelwidthstring 00.00.0000
9525 \begin_inset LatexCommand \index{-\/-dumpregassign}
9534 Will create a dump of iCode's, after register assignment
9535 \begin_inset LatexCommand \index{Register assignment}
9541 <source filename>.dumprassgn.
9544 \labelwidthstring 00.00.0000
9560 \begin_inset LatexCommand \index{-\/-dumplrange}
9566 Will create a dump of the live ranges of iTemp's
9569 \labelwidthstring 00.00.0000
9570 \added_space_bottom bigskip
9586 \begin_inset LatexCommand \index{-\/-dumpall}
9597 Will cause all the above mentioned dumps to be created.
9601 Redirecting output on Windows Shells
9604 \added_space_bottom bigskip
9605 By default SDCC writes it's error messages to
9606 \begin_inset Quotes sld
9610 \begin_inset Quotes srd
9614 To force all messages to
9615 \begin_inset Quotes sld
9619 \begin_inset Quotes srd
9645 \begin_inset LatexCommand \index{-\/-use-stdout}
9650 Additionally, if you happen to have visual studio installed in your windows
9651 machine, you can use it to compile your sources using a custom build and
9669 \begin_inset LatexCommand \index{-\/-vc}
9674 Something like this should work:
9722 -model-large -c $(InputPath)
9729 Environment variables
9730 \begin_inset LatexCommand \index{Environment variables}
9737 SDCC recognizes the following environment variables:
9740 \labelwidthstring 00.00.0000
9744 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9750 SDCC installs a signal handler
9751 \begin_inset LatexCommand \index{signal handler}
9755 to be able to delete temporary files after an user break (^C) or an exception.
9756 If this environment variable is set, SDCC won't install the signal handler
9757 in order to be able to debug SDCC.
9760 \labelwidthstring 00.00.0000
9766 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9772 Path, where temporary files will be created.
9773 The order of the variables is the search order.
9774 In a standard *nix environment these variables are not set, and there's
9775 no need to set them.
9776 On Windows it's recommended to set one of them.
9779 \labelwidthstring 00.00.0000
9783 \begin_inset LatexCommand \index{SDCC\_HOME}
9790 \begin_inset LatexCommand \ref{sub:Install-paths}
9796 \begin_inset Quotes sld
9800 \begin_inset Quotes srd
9806 \labelwidthstring 00.00.0000
9810 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9817 \begin_inset LatexCommand \ref{sub:Search-Paths}
9823 \begin_inset Quotes sld
9827 \begin_inset Quotes srd
9833 \labelwidthstring 00.00.0000
9837 \begin_inset LatexCommand \index{SDCC\_LIB}
9844 \begin_inset LatexCommand \ref{sub:Search-Paths}
9850 \begin_inset Quotes sld
9854 \begin_inset Quotes srd
9860 \added_space_bottom bigskip
9861 There are some more environment variables recognized by SDCC, but these
9862 are solely used for debugging purposes.
9863 They can change or disappear very quickly, and will never be documented.
9868 Storage Class Language Extensions
9871 MCS51/DS390 Storage Class
9872 \begin_inset LatexCommand \index{Storage class}
9879 In addition to the ANSI storage classes SDCC allows the following MCS51
9880 specific storage classes:
9882 \layout Subsubsection
9884 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9889 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9894 \begin_inset LatexCommand \index{near (storage class)}
9899 \begin_inset LatexCommand \index{\_\_near (storage class)}
9910 storage class for the Small Memory model (
9918 or the more ANSI-C compliant forms
9926 can be used synonymously).
9927 Variables declared with this storage class will be allocated in the directly
9928 addressable portion of the internal RAM of a 8051, e.g.:
9933 __data unsigned char test_data;
9936 Writing 0x01 to this variable generates the assembly code:
9941 75*00 01\SpecialChar ~
9948 \layout Subsubsection
9950 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9955 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9960 \begin_inset LatexCommand \index{far (storage class)}
9965 \begin_inset LatexCommand \index{\_\_far (storage class)}
9972 Variables declared with this storage class will be placed in the external
9978 storage class for the Large Memory model, e.g.:
9983 __xdata unsigned char test_xdata;
9986 Writing 0x01 to this variable generates the assembly code:
9991 90s00r00\SpecialChar ~
10021 \layout Subsubsection
10023 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10028 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10035 Variables declared with this storage class will be allocated into the indirectly
10036 addressable portion of the internal ram of a 8051, e.g.:
10041 __idata unsigned char test_idata;
10044 Writing 0x01 to this variable generates the assembly code:
10049 78r00\SpecialChar ~
10073 Please note, the first 128 byte of idata physically access the same RAM
10074 as the data memory.
10075 The original 8051 had 128 byte idata memory, nowadays most devices have
10076 256 byte idata memory.
10078 \begin_inset LatexCommand \index{stack}
10082 is located in idata memory.
10084 \layout Subsubsection
10086 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10091 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10098 Paged xdata access is just as straightforward as using the other addressing
10100 It is typically located at the start of xdata and has a maximum size of
10102 The following example writes 0x01 to the pdata variable.
10103 Please note, pdata access physically accesses xdata memory.
10104 The high byte of the address is determined by port P2
10105 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10109 (or in case of some 8051 variants by a separate Special Function Register,
10111 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10120 storage class for the Medium Memory model, e.g.:
10125 __pdata unsigned char test_pdata;
10128 Writing 0x01 to this variable generates the assembly code:
10133 78r00\SpecialChar ~
10139 mov r0,#_test_pdata
10141 74 01\SpecialChar ~
10174 \begin_inset LatexCommand \index{-\/-xstack}
10178 option is used the pdata memory area is followed by the xstack memory area
10179 and the sum of their sizes is limited to 256 bytes.
10181 \layout Subsubsection
10183 \begin_inset LatexCommand \index{code}
10188 \begin_inset LatexCommand \index{\_\_code}
10195 'Variables' declared with this storage class will be placed in the code
10201 __code unsigned char test_code;
10204 Read access to this variable generates the assembly code:
10209 90s00r6F\SpecialChar ~
10212 mov dptr,#_test_code
10241 indexed arrays of characters in code memory can be accessed efficiently:
10246 __code char test_array[] = {'c','h','e','a','p'};
10249 Read access to this array using an 8-bit unsigned index generates the assembly
10255 E5*00\SpecialChar ~
10266 90s00r41\SpecialChar ~
10269 mov dptr,#_test_array
10285 \layout Subsubsection
10287 \begin_inset LatexCommand \index{bit}
10292 \begin_inset LatexCommand \index{\_\_bit}
10299 This is a data-type and a storage class specifier.
10300 When a variable is declared as a bit, it is allocated into the bit addressable
10301 memory of 8051, e.g.:
10309 Writing 1 to this variable generates the assembly code:
10314 D2*00\SpecialChar ~
10325 The bit addressable memory consists of 128 bits which are located from 0x20
10326 to 0x2f in data memory.
10329 Apart from this 8051 specific storage class most architectures support
10331 \begin_inset LatexCommand \index{bitfields}
10340 Not really meant as examples, but nevertheless showing what bitfields are
10341 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10346 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10347 signed modifier are implemented as unsigned.
10349 \layout Subsubsection
10351 \begin_inset LatexCommand \index{sfr}
10356 \begin_inset LatexCommand \index{\_\_sfr}
10361 \begin_inset LatexCommand \index{sfr16}
10366 \begin_inset LatexCommand \index{\_\_sfr16}
10371 \begin_inset LatexCommand \index{sfr32}
10376 \begin_inset LatexCommand \index{\_\_sfr32}
10381 \begin_inset LatexCommand \index{\_\_sbit}
10386 \begin_inset LatexCommand \index{sbit}
10393 Like the bit keyword,
10395 sfr / sfr16 / sfr32 / sbit
10397 signify both a data-type and storage class, they are used to describe the
10418 variables of a 8051, eg:
10424 \begin_inset LatexCommand \index{at}
10429 \begin_inset LatexCommand \index{\_\_at}
10433 (0x80) P0;\SpecialChar ~
10434 /* special function register P0 at location 0x80 */
10439 special function register combination for timer 0
10443 with the high byte at
10444 location 0x8C and the low byte at location 0x8A */
10446 __sfr16 __at (0x8C8A)
10452 \begin_inset LatexCommand \index{at}
10457 \begin_inset LatexCommand \index{\_\_at}
10461 (0xd7) CY;\SpecialChar ~
10463 \begin_inset LatexCommand \index{Flags}
10468 \begin_inset LatexCommand \index{Carry flag}
10475 Special function registers which are located on an address dividable by
10476 8 are bit-addressable, an
10480 addresses a specific bit within these sfr.
10482 16 Bit and 32 bit special function
10483 register combinations which require a certain access order are better not
10493 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10494 this is not guaranteed.
10499 Please note, if you use a header file which was written for another compiler
10500 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10506 Specifically the syntax
10509 sfr P0 = 0x80;\SpecialChar ~
10516 by SDCC to an assignment of 0x80 to a variable called P0
10519 \begin_inset Marginal
10533 Nevertheless it is possible to write header files
10534 \begin_inset LatexCommand \index{Header files}
10539 \begin_inset LatexCommand \index{Include files}
10543 which can be shared among different compilers (see section
10544 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10551 \layout Subsubsection
10553 \begin_inset LatexCommand \index{Pointer}
10557 to MCS51/DS390 specific memory spaces
10560 SDCC allows (via language extensions) pointers to explicitly point to any
10561 of the memory spaces
10562 \begin_inset LatexCommand \index{Memory model}
10567 In addition to the explicit pointers, the compiler uses (by default) generic
10568 pointers which can be used to point to any of the memory spaces.
10573 declaration examples:
10578 /* pointer physically in internal ram pointing to object in external ram
10581 __xdata unsigned char * __data p;
10585 /* pointer physically in external ram
10586 pointing to object in internal ram */
10588 __data unsigned char * __xdata p;
10593 pointer physically in code rom pointing to data in xdata space */
10596 unsigned char * __code p;
10600 /* pointer physically in code space pointing to
10601 data in code space */
10603 __code unsigned char * __code p;
10608 physically located in xdata space */
10610 unsigned char * __xdata p;
10615 pointer physically located in default memory space */
10622 the following is a function pointer
10623 \begin_inset LatexCommand \index{function pointer}
10627 physically located in data space */
10629 char (* __data fp)(void);
10632 Well you get the idea.
10637 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10650 The highest order byte of the
10654 pointers contains the data space information.
10655 Assembler support routines are called whenever data is stored or retrieved
10661 These are useful for developing reusable library
10662 \begin_inset LatexCommand \index{Libraries}
10667 Explicitly specifying the pointer
10668 \begin_inset LatexCommand \index{pointer}
10672 type will generate the most efficient code.
10674 \layout Subsubsection
10675 Notes on MCS51 memory
10676 \begin_inset LatexCommand \index{MCS51 memory}
10683 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10684 RAM memory which is structured as follows:
10688 - Bytes 00-1F - 32 bytes to hold
10689 up to 4 banks of the registers R0 to R7,
10691 - Bytes 20-2F - 16 bytes to hold
10693 \begin_inset LatexCommand \index{bit}
10699 - Bytes 30-7F - 80 bytes for general purpose use.
10704 Additionally some members of the MCS51 family may have up to 128 bytes of
10705 additional, indirectly addressable, internal RAM memory (
10710 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10715 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10720 Furthermore, some chips may have some built in external memory (
10725 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10730 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10734 ) which should not be confused with the internal, directly addressable RAM
10740 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10745 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10750 Sometimes this built in
10754 memory has to be activated before using it (you can probably find this
10755 information on the datasheet of the microcontroller your are using, see
10757 \begin_inset LatexCommand \ref{sub:Startup-Code}
10765 Normally SDCC will only use the first bank
10766 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10770 of registers (register bank 0), but it is possible to specify that other
10771 banks of registers (keyword
10778 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10783 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10789 ) should be used in interrupt
10790 \begin_inset LatexCommand \index{interrupt}
10795 \begin_inset LatexCommand \index{\_\_interrupt}
10800 By default, the compiler will place the stack after the last byte of allocated
10801 memory for variables.
10802 For example, if the first 2 banks of registers are used, and only four
10807 variables, it will position the base of the internal stack at address 20
10809 This implies that as the stack
10810 \begin_inset LatexCommand \index{stack}
10814 grows, it will use up the remaining register banks, and the 16 bytes used
10815 by the 128 bit variables, and 80 bytes for general purpose use.
10816 If any bit variables are used, the data variables will be placed in unused
10817 register banks and after the byte holding the last bit variable.
10818 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10823 variables will be placed starting from address 0x10 to 0x20 and continue
10838 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10842 to specify the start address of the
10859 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10863 to specify the size of the total internal RAM (
10877 By default the 8051 linker will place the stack after the last byte of (i)data
10892 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10896 allows you to specify the start of the stack, i.e.
10897 you could start it after any data in the general purpose area.
10898 If your microcontroller has additional indirectly addressable internal
10903 ) you can place the stack on it.
10904 You may also need to use -
10917 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10921 to set the start address of the external RAM (
10938 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10942 to specify its size.
10943 Same goes for the code memory, using -
10956 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10973 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10978 If in doubt, don't specify any options and see if the resulting memory
10979 layout is appropriate, then you can adjust it.
10982 \added_space_bottom bigskip
10983 The linker generates two files with memory allocation information.
10984 The first, with extension .map
10985 \begin_inset LatexCommand \index{<file>.map}
10989 shows all the variables and segments.
10990 The second with extension .mem
10991 \begin_inset LatexCommand \index{<file>.mem}
10995 shows the final memory layout.
10996 The linker will complain either if memory segments overlap, there is not
10997 enough memory, or there is not enough space for stack.
10998 If you get any linking warnings and/or errors related to stack or segments
10999 allocation, take a look at either the .map or .mem files to find out what
11001 The .mem file may even suggest a solution to the problem.
11006 Z80/Z180 Storage Class
11007 \begin_inset LatexCommand \index{Z80!Storage class}
11011 Language Extensions
11013 \layout Subsubsection
11015 \begin_inset LatexCommand \index{sfr}
11020 \begin_inset LatexCommand \index{\_\_sfr}
11024 (in/out to 8-bit addresses)
11028 \begin_inset LatexCommand \index{Z80}
11032 family has separate address spaces for memory and
11042 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11047 \begin_inset LatexCommand \index{Z80!I/O memory}
11052 \begin_inset LatexCommand \index{Z180!I/O memory}
11056 is accessed with special instructions, e.g.:
11061 sfr at 0x78 IoPort;\SpecialChar ~
11063 /* define a var in I/O space at 78h called IoPort */
11067 Writing 0x01 to this variable generates the assembly code:
11072 3E 01\SpecialChar ~
11080 D3 78\SpecialChar ~
11088 \layout Subsubsection
11090 \begin_inset LatexCommand \index{sfr}
11095 \begin_inset LatexCommand \index{\_\_sfr}
11099 (in/out to 16-bit addresses)
11106 is used to support 16 bit addresses in I/O memory e.g.:
11112 \begin_inset LatexCommand \index{at}
11117 \begin_inset LatexCommand \index{\_\_at}
11124 Writing 0x01 to this variable generates the assembly code:
11129 01 23 01\SpecialChar ~
11134 3E 01\SpecialChar ~
11142 ED 79\SpecialChar ~
11150 \layout Subsubsection
11152 \begin_inset LatexCommand \index{sfr}
11157 \begin_inset LatexCommand \index{\_\_sfr}
11161 (in0/out0 to 8 bit addresses on Z180
11162 \begin_inset LatexCommand \index{Z180}
11167 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11174 \added_space_bottom bigskip
11175 The compiler option -
11188 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11192 =180 (80) and a compiler #pragma\SpecialChar ~
11194 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11198 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11208 If you include the file z180.h this will be set automatically.
11214 \begin_inset LatexCommand \index{HC08!Storage class}
11218 Language Extensions
11220 \layout Subsubsection
11222 \begin_inset LatexCommand \index{data (hc08 storage class)}
11227 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11234 The data storage class declares a variable that resides in the first 256
11235 bytes of memory (the direct page).
11237 \begin_inset LatexCommand \index{HC08}
11241 is most efficient at accessing variables (especially pointers) stored here.
11243 \layout Subsubsection
11245 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11250 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11257 \added_space_bottom bigskip
11258 The xdata storage class declares a variable that can reside anywhere in
11260 This is the default if no storage class is specified.
11266 Absolute Addressing
11267 \begin_inset LatexCommand \index{Absolute addressing}
11274 Data items can be assigned an absolute address with the
11277 \begin_inset LatexCommand \index{at}
11282 \begin_inset LatexCommand \index{\_\_at}
11288 keyword, in addition to a storage class, e.g.:
11294 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11299 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11304 \begin_inset LatexCommand \index{at}
11309 \begin_inset LatexCommand \index{\_\_at}
11313 0x7ffe unsigned int chksum;
11316 or, better conforming to ISO/IEC 9899 C:
11321 __xdata __at (0x7ffe) unsigned int chksum;
11324 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11325 of the external ram.
11330 reserve any space for variables declared in this way
11331 \begin_inset Marginal
11342 (they are implemented with an equate in the assembler).
11343 Thus it is left to the programmer to make sure there are no overlaps with
11344 other variables that are declared without the absolute address.
11345 The assembler listing file (.lst
11346 \begin_inset LatexCommand \index{<file>.lst}
11350 ) and the linker output files (.rst
11351 \begin_inset LatexCommand \index{<file>.rst}
11356 \begin_inset LatexCommand \index{<file>.map}
11360 ) are good places to look for such overlaps.
11361 Variables with an absolute address are
11364 \begin_inset Marginal
11378 \begin_inset LatexCommand \index{Variable initialization}
11385 In case of memory mapped I/O devices the keyword
11389 has to be used to tell the compiler that accesses might not be removed:
11395 \begin_inset LatexCommand \index{volatile}
11400 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11405 \begin_inset LatexCommand \index{at}
11409 (0x8000) unsigned char PORTA_8255;
11412 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11417 \begin_inset LatexCommand \index{Aligned array}
11424 starts at a block (256 byte) boundary
11425 \begin_inset LatexCommand \index{block boundary}
11430 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11436 Absolute addresses can be specified for variables in all
11437 storage classes, e.g.:
11443 \begin_inset LatexCommand \index{bit}
11448 \begin_inset LatexCommand \index{at}
11455 The above example will allocate the variable at offset 0x02 in the bit-addressab
11457 There is no real advantage to assigning absolute addresses to variables
11458 in this manner, unless you want strict control over all the variables allocated.
11459 One possible use would be to write hardware portable code.
11460 For example, if you have a routine that uses one or more of the microcontroller
11461 I/O pins, and such pins are different for two different hardwares, you
11462 can declare the I/O pins in your routine using:
11468 \begin_inset LatexCommand \index{volatile}
11472 __bit MOSI;\SpecialChar ~
11476 /* master out, slave in */
11478 extern volatile __bit MISO;\SpecialChar ~
11485 extern volatile __bit MCLK;\SpecialChar ~
11494 Output of a byte on a 3-wire serial bus.
11499 If needed adapt polarity of clock,
11500 polarity of data and bit order
11505 unsigned char spi_io(unsigned char out_byte)
11530 MOSI = out_byte & 0x80;
11561 /* _asm nop _endasm; */\SpecialChar ~
11569 /* for slow peripherals */
11621 Then, someplace in the code for the first hardware you would use
11627 \begin_inset LatexCommand \index{at}
11632 \begin_inset LatexCommand \index{\_\_at}
11636 (0x80) MOSI;\SpecialChar ~
11640 /* I/O port 0, bit 0 */
11642 __bit __at (0x81) MISO;\SpecialChar ~
11649 __bit __at (0x82) MCLK;\SpecialChar ~
11653 /* I/O port 0, bit 2 */
11656 Similarly, for the second hardware you would use
11661 __bit __at (0x83) MOSI;\SpecialChar ~
11665 /* I/O port 0, bit 3 */
11667 __bit __at (0x91) MISO;\SpecialChar ~
11672 I/O port 1, bit 1 */
11675 \begin_inset LatexCommand \index{bit}
11679 __at (0x92) MCLK;\SpecialChar ~
11683 /* I/O port 1, bit 2 */
11686 \added_space_bottom bigskip
11687 and you can use the same hardware dependent routine without changes, as
11688 for example in a library.
11689 This is somehow similar to sbit, but only one absolute address has to be
11690 specified in the whole project.
11696 \begin_inset LatexCommand \index{Parameters}
11701 \begin_inset LatexCommand \index{function parameter}
11706 \begin_inset LatexCommand \index{local variables}
11711 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11718 Automatic (local) variables and parameters to functions can either be placed
11719 on the stack or in data-space.
11720 The default action of the compiler is to place these variables in the internal
11721 RAM (for small model) or external RAM (for large model).
11722 This in fact makes them similar to
11725 \begin_inset LatexCommand \index{static}
11731 so by default functions are non-reentrant
11732 \begin_inset LatexCommand \index{reentrant}
11741 They can be placed on the stack
11742 \begin_inset LatexCommand \index{stack}
11761 \begin_inset LatexCommand \index{-\/-stack-auto}
11769 #pragma\SpecialChar ~
11773 \begin_inset LatexCommand \index{\#pragma stackauto}
11780 \begin_inset LatexCommand \index{reentrant}
11786 keyword in the function declaration, e.g.:
11791 unsigned char foo(char i) __reentrant
11805 Since stack space on 8051 is limited, the
11825 option should be used sparingly.
11826 Note that the reentrant keyword just means that the parameters & local
11827 variables will be allocated to the stack, it
11831 mean that the function is register bank
11832 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11841 \begin_inset LatexCommand \index{local variables}
11845 can be assigned storage classes and absolute
11846 \begin_inset LatexCommand \index{Absolute addressing}
11855 unsigned char foo()
11863 __xdata unsigned char i;
11876 \begin_inset LatexCommand \index{at}
11880 (0x31) unsigned char j;
11892 In the above example the variable
11896 will be allocated in the external ram,
11900 in bit addressable space and
11921 or when a function is declared as
11925 this should only be done for static variables.
11929 \begin_inset LatexCommand \index{function parameter}
11933 however are not allowed any storage class
11934 \begin_inset LatexCommand \index{Storage class}
11938 , (storage classes for parameters will be ignored), their allocation is
11939 governed by the memory model in use, and the reentrancy options.
11942 It is however allowed to use bit parameters in reentrant functions and also
11943 non-static local bit variables are supported.
11944 Efficient use is limited to 8 semi-bitregisters in bit space.
11945 They are pushed and popped to stack
11946 \begin_inset LatexCommand \index{stack}
11950 as a single byte just like the normal registers.
11954 \begin_inset LatexCommand \label{sub:Overlaying}
11959 \begin_inset LatexCommand \index{Overlaying}
11967 \begin_inset LatexCommand \index{reentrant}
11971 functions SDCC will try to reduce internal ram space usage by overlaying
11972 parameters and local variables of a function (if possible).
11973 Parameters and local variables
11974 \begin_inset LatexCommand \index{local variables}
11978 of a function will be allocated to an overlayable segment if the function
11981 no other function calls and the function is non-reentrant and the memory
11983 \begin_inset LatexCommand \index{Memory model}
11990 If an explicit storage class
11991 \begin_inset LatexCommand \index{Storage class}
11995 is specified for a local variable, it will NOT be overlayed.
11998 Note that the compiler (not the linkage editor) makes the decision for overlayin
12000 Functions that are called from an interrupt service routine
12001 \begin_inset Marginal
12011 should be preceded by a #pragma\SpecialChar ~
12013 \begin_inset LatexCommand \index{\#pragma nooverlay}
12017 if they are not reentrant.
12020 Also note that the compiler does not do any processing of inline assembler
12021 code, so the compiler might incorrectly assign local variables and parameters
12022 of a function into the overlay segment if the inline assembler code calls
12023 other c-functions that might use the overlay.
12024 In that case the #pragma\SpecialChar ~
12025 nooverlay should be used.
12028 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12030 \begin_inset LatexCommand \index{Multiplication}
12035 \begin_inset LatexCommand \index{Division}
12039 will NOT be overlayed since these are implemented using external functions,
12048 \begin_inset LatexCommand \index{\#pragma nooverlay}
12054 void set_error(unsigned char errcd)
12071 some_isr () __interrupt
12072 \begin_inset LatexCommand \index{interrupt}
12102 \added_space_bottom bigskip
12103 In the above example the parameter
12111 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12113 not present, this could cause unpredictable runtime behavior when called
12114 from an interrupt service routine.
12115 The #pragma\SpecialChar ~
12116 nooverlay ensures that the parameters and local variables for
12117 the function are NOT overlayed.
12122 Interrupt Service Routines
12123 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12130 General Information
12145 outines to be coded in C, with some extended keywords.
12150 void timer_isr (void) __interrupt (1) __using (1)
12164 The optional number following the
12167 \begin_inset LatexCommand \index{interrupt}
12172 \begin_inset LatexCommand \index{\_\_interrupt}
12178 keyword is the interrupt number this routine will service.
12179 When present, the compiler will insert a call to this routine in the interrupt
12181 \begin_inset LatexCommand \index{interrupt vector table}
12185 for the interrupt number specified.
12186 If you have multiple source files in your project, interrupt service routines
12187 can be present in any of them, but a prototype of the isr MUST be present
12188 or included in the file that contains the function
12193 The optional (8051 specific) keyword
12196 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12201 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12207 can be used to tell the compiler to use the specified register bank when
12208 generating code for this function.
12211 Interrupt service routines open the door for some very interesting bugs:
12213 \layout Subsubsection
12214 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12218 Common interrupt pitfall: variable not declared
12223 If an interrupt service routine changes variables which are accessed by
12224 other functions these variables have to be declared
12229 \begin_inset LatexCommand \index{volatile}
12235 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12241 \layout Subsubsection
12242 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12246 Common interrupt pitfall:
12251 If the access to these variables is not
12254 \begin_inset LatexCommand \index{atomic}
12261 the processor needs more than one instruction for the access and could
12262 be interrupted while accessing the variable) the interrupt must be disabled
12263 during the access to avoid inconsistent data.
12266 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12267 and should be protected by disabling interrupts.
12268 You're not automatically on the safe side if you use 8 bit variables though.
12269 We need an example here: f.e.
12270 on the 8051 the harmless looking
12271 \begin_inset Quotes srd
12276 flags\SpecialChar ~
12281 \begin_inset Quotes sld
12290 \begin_inset Quotes srd
12295 flags\SpecialChar ~
12300 \begin_inset Quotes sld
12303 from within an interrupt routine might get lost if the interrupt occurs
12306 \begin_inset Quotes sld
12311 counter\SpecialChar ~
12316 \begin_inset Quotes srd
12319 is not atomic on the 8051 even if
12323 is located in data memory.
12325 Bugs like these are hard to reproduce and can
12326 cause a lot of trouble.
12329 \layout Subsubsection
12330 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12334 Common interrupt pitfall:
12339 The return address and the registers used in the interrupt service routine
12340 are saved on the stack
12341 \begin_inset LatexCommand \index{stack}
12345 so there must be sufficient stack space.
12346 If there isn't variables or registers (or even the return address itself)
12353 \begin_inset LatexCommand \index{stack overflow}
12357 is most likely to happen if the interrupt occurs during the
12358 \begin_inset Quotes sld
12362 \begin_inset Quotes srd
12365 subroutine when the stack is already in use for f.e.
12366 many return addresses.
12368 \layout Subsubsection
12369 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12373 Common interrupt pitfall:
12375 use of non-reentrant functions
12378 A special note here, int (16 bit) and long (32 bit) integer division
12379 \begin_inset LatexCommand \index{Division}
12384 \begin_inset LatexCommand \index{Multiplication}
12389 \begin_inset LatexCommand \index{Modulus}
12394 \begin_inset LatexCommand \index{Floating point support}
12398 operations are implemented using external support routines.
12399 If an interrupt service routine needs to do any of these operations then
12400 the support routines (as mentioned in a following section) will have to
12401 be recompiled using the
12416 \begin_inset LatexCommand \index{-\/-stack-auto}
12422 option and the source file will need to be compiled using the
12439 \begin_inset LatexCommand \index{-\/-int-long-reent}
12446 Note, the type promotion
12447 \begin_inset LatexCommand \index{type promotion}
12451 required by ANSI C can cause 16 bit routines to be used
12452 \begin_inset Marginal
12463 without the programmer being aware of it.
12467 (unsigned char)(tail-1)
12469 within the if clause in section
12470 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12477 \added_space_bottom bigskip
12478 Calling other functions from an interrupt service routine is not recommended,
12479 avoid it if possible.
12480 Note that when some function is called from an interrupt service routine
12481 it should be preceded by a #pragma\SpecialChar ~
12483 \begin_inset LatexCommand \index{\#pragma nooverlay}
12487 if it is not reentrant.
12488 Furthermore nonreentrant functions should not be called from the main program
12489 while the interrupt service routine might be active.
12490 They also must not be called from low priority interrupt service routines
12491 while a high priority interrupt service routine might be active.
12492 You could use semaphores or make the function
12496 if all parameters are passed in registers.
12499 \begin_inset LatexCommand \ref{sub:Overlaying}
12504 about Overlaying and section
12505 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12510 about Functions using private register banks.
12515 MCS51/DS390 Interrupt Service Routines
12519 \begin_inset LatexCommand \index{interrupt}
12523 numbers and the corresponding address & descriptions for the Standard 8051/8052
12525 SDCC will automatically adjust the
12526 \begin_inset LatexCommand \index{interrupt vector table}
12530 to the maximum interrupt number specified.
12536 \begin_inset Tabular
12537 <lyxtabular version="3" rows="9" columns="3">
12539 <column alignment="center" valignment="top" leftline="true" width="0in">
12540 <column alignment="left" valignment="top" leftline="true" width="0in">
12541 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12542 <row topline="true" bottomline="true">
12543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12568 <row topline="true">
12569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12594 <row topline="true">
12595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12620 <row topline="true">
12621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12646 <row topline="true">
12647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12672 <row topline="true">
12673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12698 <row topline="true">
12699 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12724 <row topline="true">
12725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12750 <row topline="true" bottomline="true">
12751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12785 If the interrupt service routine is defined without
12788 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12793 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12799 a register bank or with register bank 0 (
12803 0), the compiler will save the registers used by itself on the stack upon
12804 entry and restore them at exit, however if such an interrupt service routine
12805 calls another function then the entire register bank will be saved on the
12807 This scheme may be advantageous for small interrupt service routines which
12808 have low register usage.
12811 \added_space_bottom bigskip
12812 If the interrupt service routine is defined to be using a specific register
12817 & psw are saved and restored, if such an interrupt service routine calls
12818 another function (using another register bank) then the entire register
12819 bank of the called function will be saved on the stack
12820 \begin_inset LatexCommand \index{stack}
12825 This scheme is recommended for larger interrupt service routines.
12831 \begin_inset LatexCommand \index{HC08}
12835 Interrupt Service Routines
12838 \added_space_bottom bigskip
12839 Since the number of interrupts
12840 \begin_inset LatexCommand \index{HC08!interrupt}
12844 available is chip specific and the interrupt vector table always ends at
12845 the last byte of memory, the interrupt numbers corresponds to the interrupt
12846 vectors in reverse order of address.
12847 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12848 2 will use the interrupt vector at 0xfffa, and so on.
12849 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12850 this way; instead see section
12851 \begin_inset LatexCommand \ref{sub:Startup-Code}
12855 for details on customizing startup.
12860 Z80 Interrupt Service Routines
12864 \begin_inset LatexCommand \index{Z80}
12868 uses several different methods for determining the correct interrupt
12869 \begin_inset LatexCommand \index{Z80!interrupt}
12873 vector depending on the hardware implementation.
12874 Therefore, SDCC ignores the optional interrupt number and does not attempt
12875 to generate an interrupt vector table.
12878 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12879 instruction to return from the interrupt.
12880 To write an interrupt handler for the non-maskable interrupt, which needs
12881 a RETN instruction instead, add the
12890 void nmi_isr (void) critical interrupt
12904 \added_space_bottom bigskip
12905 However if you need to create a non-interruptable interrupt service routine
12906 you would also require the
12911 To distinguish between this and an nmi_isr you must provide an interrupt
12917 Enabling and Disabling Interrupts
12920 Critical Functions and Critical Statements
12923 A special keyword may be associated with a block or a function declaring
12929 SDCC will generate code to disable all interrupts
12930 \begin_inset LatexCommand \index{interrupt}
12934 upon entry to a critical function and restore the interrupt enable to the
12935 previous state before returning.
12936 Nesting critical functions will need one additional byte on the stack
12937 \begin_inset LatexCommand \index{stack}
12946 int foo () __critical
12947 \begin_inset LatexCommand \index{critical}
12952 \begin_inset LatexCommand \index{\_\_critical}
12977 The critical attribute maybe used with other attributes like
12987 may also be used to disable interrupts more locally:
12995 More than one statement could have been included in the block.
12998 Enabling and Disabling Interrupts directly
13002 \begin_inset LatexCommand \index{interrupt}
13006 can also be disabled and enabled directly (8051):
13011 EA = 0;\SpecialChar ~
13074 EA = 1;\SpecialChar ~
13141 On other architectures which have seperate opcodes for enabling and disabling
13142 interrupts you might want to make use of defines with inline assembly
13143 \begin_inset LatexCommand \index{Assembler routines}
13148 \begin_inset LatexCommand \index{HC08!interrupt}
13158 \begin_inset LatexCommand \index{\_asm}
13167 \begin_inset LatexCommand \index{\_endasm}
13176 #define SEI _asm\SpecialChar ~
13188 Note: it is sometimes sufficient to disable only a specific interrupt source
13190 a timer or serial interrupt by manipulating an
13193 \begin_inset LatexCommand \index{interrupt mask}
13203 Usually the time during which interrupts are disabled should be kept as
13205 This minimizes both
13210 \begin_inset LatexCommand \index{interrupt latency}
13214 (the time between the occurrence of the interrupt and the execution of
13215 the first code in the interrupt routine) and
13220 \begin_inset LatexCommand \index{interrupt jitter}
13224 (the difference between the shortest and the longest interrupt latency).
13225 These really are something different, f.e.
13226 a serial interrupt has to be served before its buffer overruns so it cares
13227 for the maximum interrupt latency, whereas it does not care about jitter.
13228 On a loudspeaker driven via a digital to analog converter which is fed
13229 by an interrupt a latency of a few milliseconds might be tolerable, whereas
13230 a much smaller jitter will be very audible.
13233 You can reenable interrupts within an interrupt routine and on some architecture
13234 s you can make use of two (or more) levels of
13236 interrupt priorities
13239 \begin_inset LatexCommand \index{interrupt priority}
13244 On some architectures which don't support interrupt priorities these can
13245 be implemented by manipulating the interrupt mask and reenabling interrupts
13246 within the interrupt routine.
13247 Check there is sufficient space on the stack
13248 \begin_inset LatexCommand \index{stack}
13252 and don't add complexity unless you have to.
13257 \begin_inset LatexCommand \index{semaphore}
13261 locking (mcs51/ds390)
13264 Some architectures (mcs51/ds390) have an atomic
13265 \begin_inset LatexCommand \index{atomic}
13278 These type of instructions are typically used in preemptive multitasking
13279 systems, where a routine f.e.
13280 claims the use of a data structure ('acquires a lock
13281 \begin_inset LatexCommand \index{lock}
13285 on it'), makes some modifications and then releases the lock when the data
13286 structure is consistent again.
13287 The instruction may also be used if interrupt and non-interrupt code have
13288 to compete for a resource.
13289 With the atomic bit test and clear instruction interrupts
13290 \begin_inset LatexCommand \index{interrupt}
13294 don't have to be disabled for the locking operation.
13298 SDCC generates this instruction if the source follows this pattern:
13304 \begin_inset LatexCommand \index{volatile}
13308 bit resource_is_free;
13312 if (resource_is_free)
13322 resource_is_free=0;
13335 resource_is_free=1;
13342 Note, mcs51 and ds390 support only an atomic
13343 \begin_inset LatexCommand \index{atomic}
13351 instruction (as opposed to atomic bit test and
13356 Functions using private register banks
13357 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13364 Some architectures have support for quickly changing register sets.
13365 SDCC supports this feature with the
13368 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13373 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13379 attribute (which tells the compiler to use a register bank
13380 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13384 other than the default bank zero).
13385 It should only be applied to
13388 \begin_inset LatexCommand \index{interrupt}
13394 functions (see footnote below).
13395 This will in most circumstances make the generated ISR code more efficient
13396 since it will not have to save registers on the stack.
13403 attribute will have no effect on the generated code for a
13407 function (but may occasionally be useful anyway
13412 possible exception: if a function is called ONLY from 'interrupt' functions
13413 using a particular bank, it can be declared with the same 'using' attribute
13414 as the calling 'interrupt' functions.
13415 For instance, if you have several ISRs using bank one, and all of them
13416 call memcpy(), it might make sense to create a specialized version of memcpy()
13417 'using 1', since this would prevent the ISR from having to save bank zero
13418 to the stack on entry and switch to bank zero before calling the function
13426 (pending: Note, nowadays the
13430 attribute has an effect on
13434 the generated code for a
13449 function using a non-zero bank will assume that it can trash that register
13450 bank, and will not save it.
13451 Since high-priority interrupts
13452 \begin_inset LatexCommand \index{interrupts}
13457 \begin_inset LatexCommand \index{interrupt priority}
13461 can interrupt low-priority ones on the 8051 and friends, this means that
13462 if a high-priority ISR
13466 a particular bank occurs while processing a low-priority ISR
13470 the same bank, terrible and bad things can happen.
13471 To prevent this, no single register bank should be
13475 by both a high priority and a low priority ISR.
13476 This is probably most easily done by having all high priority ISRs use
13477 one bank and all low priority ISRs use another.
13478 If you have an ISR which can change priority at runtime, you're on your
13479 own: I suggest using the default bank zero and taking the small performance
13483 \added_space_bottom bigskip
13484 It is most efficient if your ISR calls no other functions.
13485 If your ISR must call other functions, it is most efficient if those functions
13486 use the same bank as the ISR (see note 1 below); the next best is if the
13487 called functions use bank zero.
13488 It is very inefficient to call a function using a different, non-zero bank
13496 \begin_inset LatexCommand \label{sub:Startup-Code}
13501 \begin_inset LatexCommand \index{Startup code}
13508 MCS51/DS390 Startup Code
13511 The compiler inserts a call to the C routine
13513 _sdcc_external_startup()
13514 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13523 at the start of the CODE area.
13524 This routine is in the runtime library
13525 \begin_inset LatexCommand \index{Runtime library}
13530 By default this routine returns 0, if this routine returns a non-zero value,
13531 the static & global variable initialization will be skipped and the function
13532 main will be invoked.
13533 Otherwise static & global variables will be initialized before the function
13537 _sdcc_external_startup()
13539 routine to your program to override the default if you need to setup hardware
13540 or perform some other critical operation prior to static & global variable
13542 \begin_inset LatexCommand \index{Variable initialization}
13547 On some mcs51 variants xdata
13548 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13552 memory has to be explicitly enabled before it can be accessed or if the
13554 \begin_inset LatexCommand \index{watchdog}
13558 needs to be disabled, this is the place to do it.
13559 The startup code clears all internal data memory, 256 bytes by default,
13560 but from 0 to n-1 if
13575 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13582 (recommended for Chipcon CC1010).
13585 \added_space_bottom bigskip
13586 See also the compiler options
13607 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13628 \begin_inset LatexCommand \index{-\/-main-return}
13633 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13637 about MCS51-variants.
13645 \added_space_bottom bigskip
13647 \begin_inset LatexCommand \index{HC08}
13651 startup code follows the same scheme as the MCS51 startup code.
13659 \added_space_bottom bigskip
13661 \begin_inset LatexCommand \index{Z80}
13665 the startup code is inserted by linking with crt0.o which is generated from
13666 sdcc/device/lib/z80/crt0.s.
13667 If you need a different startup code you can use the compiler option
13690 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13694 and provide your own crt0.o.
13700 Inline Assembler Code
13701 \begin_inset LatexCommand \index{Assembler routines}
13708 A Step by Step Introduction
13709 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13716 Starting from a small snippet of c-code this example shows for the MCS51
13717 how to use inline assembly, access variables, a function parameter and
13718 an array in xdata memory.
13719 The example uses an MCS51 here but is easily adapted for other architectures.
13720 This is a buffer routine which should be optimized:
13726 unsigned char __far
13727 \begin_inset LatexCommand \index{far (storage class)}
13732 \begin_inset LatexCommand \index{\_\_far (storage class)}
13737 \begin_inset LatexCommand \index{at}
13742 \begin_inset LatexCommand \index{\_\_at}
13746 (0x7f00) buf[0x100];
13747 \begin_inset LatexCommand \index{Aligned array}
13753 unsigned char head, tail;\SpecialChar ~
13771 \begin_inset LatexCommand \index{interrupt}
13823 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13835 void to_buffer( unsigned char c )
13843 if( head != (unsigned char)(tail-1)
13850 \begin_inset LatexCommand \index{promotion to signed int}
13855 \begin_inset LatexCommand \index{type promotion}
13860 \begin_inset Marginal
13881 buf[ head++ ] = c;\SpecialChar ~
13897 /* access to a 256 byte aligned array */
13902 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13903 then a corresponding buffer.asm file is generated.
13904 We define a new function
13908 in file buffer.c in which we cut and paste the generated code, removing
13909 unwanted comments and some ':'.
13911 \begin_inset Quotes sld
13915 \begin_inset Quotes srd
13919 \begin_inset Quotes sld
13923 \begin_inset Quotes srd
13926 to the beginning and the end of the function body:
13932 /* With a cut and paste from the .asm file, we have something to start with.
13938 function is not yet OK! (registers aren't saved) */
13940 void to_buffer_asm(
13950 \begin_inset LatexCommand \index{\_asm}
13955 \begin_inset LatexCommand \index{\_\_asm}
13969 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
13975 \begin_inset LatexCommand \index{promotion to signed int}
13980 \begin_inset LatexCommand \index{type promotion}
14033 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14034 \begin_inset LatexCommand \index{Aligned array}
14100 \begin_inset LatexCommand \index{\_endasm}
14105 \begin_inset LatexCommand \index{\_\_endasm}
14114 The new file buffer.c should compile with only one warning about the unreferenced
14115 function argument 'c'.
14116 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14117 (1) and finally have:
14123 unsigned char __far __at(0x7f00) buf[0x100];
14125 unsigned char head, tail;
14136 void to_buffer( unsigned char c )
14145 head != (unsigned char)(tail-1) )
14174 c; // to avoid warning: unreferenced function argument
14181 \begin_inset LatexCommand \index{\_asm}
14186 \begin_inset LatexCommand \index{\_\_asm}
14200 ; save used registers here.
14211 ; If we were still using r2,r3 we would have to push them here.
14214 ; if( head != (unsigned char)(tail-1) )
14258 could do an ANL a,#0x0f here to use a smaller buffer (see below)
14294 a,dpl \SpecialChar ~
14301 ; dpl holds lower byte of function argument
14313 dpl,_head \SpecialChar ~
14316 ; buf is 0x100 byte aligned so head can be used directly
14359 ; we could do an ANL _head,#0x0f here to use a
14360 smaller buffer (see above)
14372 ; restore used registers here
14379 \begin_inset LatexCommand \index{\_endasm}
14384 \begin_inset LatexCommand \index{\_\_endasm}
14395 The inline assembler code can contain any valid code understood by the assembler
14396 , this includes any assembler directives and comment lines.
14397 The assembler does not like some characters like ':' or ''' in comments.
14398 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
14399 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
14404 \begin_inset LatexCommand \index{Assembler documentation}
14409 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
14417 The compiler does not do any validation of the code within the
14420 \begin_inset LatexCommand \index{\_asm}
14425 \begin_inset LatexCommand \index{\_\_asm}
14433 \begin_inset LatexCommand \index{\_endasm}
14438 \begin_inset LatexCommand \index{\_\_endasm}
14447 Specifically it will not know which registers are used and thus register
14449 \begin_inset LatexCommand \index{push/pop}
14453 has to be done manually.
14457 It is recommended that each assembly instruction (including labels) be placed
14458 in a separate line (as the example shows).
14474 \begin_inset LatexCommand \index{-\/-peep-asm}
14480 command line option is used, the inline assembler code will be passed through
14481 the peephole optimizer
14482 \begin_inset LatexCommand \index{Peephole optimizer}
14487 There are only a few (if any) cases where this option makes sense, it might
14488 cause some unexpected changes in the inline assembler code.
14489 Please go through the peephole optimizer rules defined in file
14493 before using this option.
14497 \begin_inset LatexCommand \label{sub:Naked-Functions}
14502 \begin_inset LatexCommand \index{Naked functions}
14509 A special keyword may be associated with a function declaring it as
14512 \begin_inset LatexCommand \index{\_naked}
14517 \begin_inset LatexCommand \index{\_\_naked}
14528 function modifier attribute prevents the compiler from generating prologue
14529 \begin_inset LatexCommand \index{function prologue}
14534 \begin_inset LatexCommand \index{function epilogue}
14538 code for that function.
14539 This means that the user is entirely responsible for such things as saving
14540 any registers that may need to be preserved, selecting the proper register
14541 bank, generating the
14545 instruction at the end, etc.
14546 Practically, this means that the contents of the function must be written
14547 in inline assembler.
14548 This is particularly useful for interrupt functions, which can have a large
14549 (and often unnecessary) prologue/epilogue.
14550 For example, compare the code generated by these two functions:
14556 \begin_inset LatexCommand \index{volatile}
14560 data unsigned char counter;
14564 void simpleInterrupt(void) __interrupt
14565 \begin_inset LatexCommand \index{interrupt}
14570 \begin_inset LatexCommand \index{\_\_interrupt}
14588 void nakedInterrupt(void) __interrupt (2) __naked
14597 \begin_inset LatexCommand \index{\_asm}
14602 \begin_inset LatexCommand \index{\_\_asm}
14619 _counter ; does not change flags, no need to save psw
14632 include ret or reti in _naked function.
14639 \begin_inset LatexCommand \index{\_endasm}
14644 \begin_inset LatexCommand \index{\_\_endasm}
14653 For an 8051 target, the generated simpleInterrupt looks like:
14662 example, recent versions of SDCC generate
14668 code for simpleInterrupt() and nakedInterrupt()!
14809 whereas nakedInterrupt looks like:
14824 _counter ; does not change flags, no need to save psw
14843 MUST explicitly include ret or reti in _naked function
14846 The related directive #pragma exclude
14847 \begin_inset LatexCommand \index{\#pragma exclude}
14851 allows a more fine grained control over pushing & popping
14852 \begin_inset LatexCommand \index{push/pop}
14859 While there is nothing preventing you from writing C code inside a
14863 function, there are many ways to shoot yourself in the foot doing this,
14864 and it is recommended that you stick to inline assembler.
14867 Use of Labels within Inline Assembler
14870 SDCC allows the use of in-line assembler with a few restrictions regarding
14872 In older versions of the compiler all labels defined within inline assembler
14881 where nnnn is a number less than 100 (which implies a limit of utmost 100
14882 inline assembler labels
14896 \begin_inset LatexCommand \index{\_asm}
14901 \begin_inset LatexCommand \index{\_\_asm}
14931 \begin_inset LatexCommand \index{\_endasm}
14936 \begin_inset LatexCommand \index{\_\_endasm}
14943 Inline assembler code cannot reference any C-Labels, however it can reference
14945 \begin_inset LatexCommand \index{Labels}
14949 defined by the inline assembler, e.g.:
14974 ; some assembler code
14995 /* some more c code */
14997 clabel:\SpecialChar ~
14999 /* inline assembler cannot reference this
15012 $0003: ;label (can be referenced by inline assembler only)
15020 \begin_inset LatexCommand \index{\_endasm}
15025 \begin_inset LatexCommand \index{\_\_endasm}
15035 /* some more c code */
15040 In other words inline assembly code can access labels defined in inline
15041 assembly within the scope of the function.
15042 The same goes the other way, i.e.
15043 labels defines in inline assembly can not be accessed by C statements.
15046 Interfacing with Assembler Code
15047 \begin_inset LatexCommand \index{Assembler routines}
15054 Global Registers used for Parameter Passing
15055 \begin_inset LatexCommand \index{Parameter passing}
15062 The compiler always uses the global registers
15065 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15070 \begin_inset LatexCommand \index{DPTR}
15075 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15084 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15090 to pass the first parameter to a routine.
15091 The second parameter onwards is either allocated on the stack (for reentrant
15104 -stack-auto is used) or in data / xdata memory (depending on the memory
15109 Assembler Routine (non-reentrant)
15112 In the following example
15113 \begin_inset LatexCommand \index{reentrant}
15118 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15122 the function c_func calls an assembler routine asm_func, which takes two
15124 \begin_inset LatexCommand \index{function parameter}
15133 extern int asm_func(unsigned char, unsigned char);
15137 int c_func (unsigned char
15138 i, unsigned char j)
15146 return asm_func(i,j);
15160 return c_func(10,9);
15165 The corresponding assembler function is:
15170 .globl _asm_func_PARM_2
15272 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15289 Note here that the return values
15290 \begin_inset LatexCommand \index{return value}
15294 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
15296 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
15297 b' & 'acc' for four byte values.
15300 The parameter naming convention is _<function_name>_PARM_<n>, where n is
15301 the parameter number starting from 1, and counting from the left.
15302 The first parameter is passed in
15303 \begin_inset Quotes eld
15307 \begin_inset Quotes erd
15310 for a one byte parameter,
15311 \begin_inset Quotes eld
15315 \begin_inset Quotes erd
15319 \begin_inset Quotes eld
15323 \begin_inset Quotes erd
15326 for three bytes and
15327 \begin_inset Quotes eld
15331 \begin_inset Quotes erd
15334 for a four bytes parameter.
15335 The variable name for the second parameter will be _<function_name>_PARM_2.
15340 ble the assembler routine with the following command:
15347 asx8051 -losg asmfunc.asm
15354 Then compile and link the assembler routine to the C source file with the
15362 sdcc cfunc.c asmfunc.rel
15365 Assembler Routine (reentrant)
15369 \begin_inset LatexCommand \index{reentrant}
15374 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
15378 the second parameter
15379 \begin_inset LatexCommand \index{function parameter}
15383 onwards will be passed on the stack, the parameters are pushed from right
15385 after the call the leftmost parameter will be on the top of the stack.
15386 Here is an example:
15391 extern int asm_func(unsigned char, unsigned char);
15395 int c_func (unsigned char
15396 i, unsigned char j) reentrant
15404 return asm_func(i,j);
15424 The corresponding assembler routine is:
15526 \added_space_bottom bigskip
15527 The compiling and linking procedure remains the same, however note the extra
15528 entry & exit linkage required for the assembler code, _bp is the stack
15529 frame pointer and is used to compute the offset into the stack for parameters
15530 and local variables.
15536 \begin_inset LatexCommand \index{int (16 bit)}
15541 \begin_inset LatexCommand \index{long (32 bit)}
15548 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15549 multiplication and modulus operations are implemented by support routines.
15550 These support routines are all developed in ANSI-C to facilitate porting
15551 to other MCUs, although some model specific assembler optimizations are
15553 The following files contain the described routines, all of them can be
15554 found in <installdir>/share/sdcc/lib.
15560 \begin_inset Tabular
15561 <lyxtabular version="3" rows="11" columns="2">
15563 <column alignment="left" valignment="top" leftline="true" width="0">
15564 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15565 <row topline="true" bottomline="true">
15566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15587 <row topline="true">
15588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15600 16 bit multiplication
15605 <row topline="true">
15606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15618 signed 16 bit division (calls _divuint)
15623 <row topline="true">
15624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15636 unsigned 16 bit division
15641 <row topline="true">
15642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15654 signed 16 bit modulus (calls _moduint)
15659 <row topline="true">
15660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15672 unsigned 16 bit modulus
15677 <row topline="true">
15678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15690 32 bit multiplication
15695 <row topline="true">
15696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15708 signed 32 division (calls _divulong)
15713 <row topline="true">
15714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15726 unsigned 32 division
15731 <row topline="true">
15732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15744 signed 32 bit modulus (calls _modulong)
15749 <row topline="true" bottomline="true">
15750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15762 unsigned 32 bit modulus
15776 Since they are compiled as
15781 \begin_inset LatexCommand \index{reentrant}
15786 \begin_inset LatexCommand \index{interrupt}
15790 service routines should not do any of the above operations.
15791 If this is unavoidable then the above routines will need to be compiled
15807 \begin_inset LatexCommand \index{-\/-stack-auto}
15813 option, after which the source program will have to be compiled with
15828 \begin_inset LatexCommand \index{-\/-int-long-reent}
15835 Notice that you don't have to call these routines directly.
15836 The compiler will use them automatically every time an integer operation
15840 Floating Point Support
15841 \begin_inset LatexCommand \index{Floating point support}
15848 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15849 The floating point support routines are derived from gcc's floatlib.c and
15850 consist of the following routines:
15858 \begin_inset Tabular
15859 <lyxtabular version="3" rows="17" columns="2">
15861 <column alignment="left" valignment="top" leftline="true" width="0">
15862 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15863 <row topline="true" bottomline="true">
15864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15890 <row topline="true">
15891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15921 add floating point numbers
15926 <row topline="true">
15927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15957 subtract floating point numbers
15962 <row topline="true">
15963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15993 divide floating point numbers
15998 <row topline="true">
15999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16029 multiply floating point numbers
16034 <row topline="true">
16035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16065 convert floating point to unsigned char
16070 <row topline="true">
16071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16101 convert floating point to signed char
16106 <row topline="true">
16107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16137 convert floating point to unsigned int
16142 <row topline="true">
16143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16173 convert floating point to signed int
16178 <row topline="true">
16179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16217 convert floating point to unsigned long
16222 <row topline="true">
16223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16253 convert floating point to signed long
16258 <row topline="true">
16259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16289 convert unsigned char to floating point
16294 <row topline="true">
16295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16325 convert char to floating point number
16330 <row topline="true">
16331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16361 convert unsigned int to floating point
16366 <row topline="true">
16367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16397 convert int to floating point numbers
16402 <row topline="true">
16403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16433 convert unsigned long to floating point number
16438 <row topline="true" bottomline="true">
16439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16469 convert long to floating point number
16483 \added_space_bottom bigskip
16484 These support routines are developed in ANSI-C so there is room for space
16485 and speed improvement
16490 These floating point routines (
16494 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
16500 Note if all these routines are used simultaneously the data space might
16502 For serious floating point usage the large model might be needed.
16503 Also notice that you don't have to call this routines directly.
16504 The compiler will use them automatically every time a floating point operation
16511 \begin_inset LatexCommand \index{Libraries}
16520 <pending: this is messy and incomplete - a little more information is in
16521 sdcc/doc/libdoc.txt
16526 Compiler support routines (_gptrget, _mulint etc.)
16529 Stdclib functions (puts, printf, strcat etc.)
16531 \layout Subsubsection
16535 getchar(), putchar()
16538 \begin_inset LatexCommand \index{<stdio.h>}
16542 As usual on embedded systems you have to provide your own
16545 \begin_inset LatexCommand \index{getchar()}
16554 \begin_inset LatexCommand \index{putchar()}
16561 SDCC does not know whether the system connects to a serial line with or
16562 without handshake, LCD, keyboard or other device.
16576 You'll find examples for serial routines f.e.
16577 in sdcc/device/lib.
16578 For the mcs51 this minimalistic polling
16582 routine might be a start:
16587 void putchar (char c) {
16593 while (!TI)\SpecialChar ~
16596 /* assumes UART is initialized */
16630 \begin_inset LatexCommand \index{printf()}
16640 does not support float (except on ds390).
16641 To enable this recompile it with the option
16656 \begin_inset LatexCommand \index{USE\_FLOATS}
16662 on the command line.
16678 \begin_inset LatexCommand \index{-\/-model-large}
16684 for the mcs51 port, since this uses a lot of memory.
16687 If you're short on code memory you might want to use
16690 \begin_inset LatexCommand \index{printf\_small()}
16705 For the mcs51 there additionally are assembly versions
16708 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16714 (subset of printf using less than 270 bytes) and
16717 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16726 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16732 (floating-point aware version of printf_fast) which should fit the requirements
16733 of many embedded systems (printf_fast() can be customized by unsetting
16738 support long variables and field widths).
16739 Be sure to only use only one of these printf options within a project.
16744 Feature matrix of different
16751 \begin_inset Tabular
16752 <lyxtabular version="3" rows="14" columns="7">
16753 <features islongtable="true">
16754 <column alignment="left" valignment="center" leftline="true" width="14col%">
16755 <column alignment="center" valignment="top" leftline="true" width="0">
16756 <column alignment="center" valignment="top" leftline="true" width="12col%">
16757 <column alignment="center" valignment="top" leftline="true" width="10col%">
16758 <column alignment="center" valignment="top" leftline="true" width="0">
16759 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
16760 <column alignment="center" valignment="top" rightline="true" width="0">
16761 <row topline="true" bottomline="true" endhead="true">
16762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16778 \begin_inset LatexCommand \index{printf}
16786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16829 <row topline="true" endhead="true">
16830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16899 <row topline="true" endhead="true">
16900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16904 \begin_inset Quotes sld
16908 \begin_inset Quotes srd
16918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16967 <row topline="true" endhead="true">
16968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16999 0.45k / 0.47k (+ _ltoa)
17003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17028 <row topline="true">
17029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17164 <row topline="true">
17165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17169 long (32 bit) support
17173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17231 <row topline="true">
17232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17236 byte arguments on stack
17240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17289 <row topline="true">
17290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17295 \begin_inset LatexCommand \index{Floating point support}
17303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17344 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17361 <row topline="true">
17362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17366 float formats %e %g
17370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17419 <row topline="true" bottomline="true">
17420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17477 <row bottomline="true">
17478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17487 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
17491 n'); standard 8051 @ 22.1184 MHz, empty putchar()
17502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17551 <row bottomline="true">
17552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17561 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17622 printf_tiny integer speed is data dependent, worst case is 0.33 ms
17631 <row bottomline="true">
17632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17641 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
17653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17702 <row bottomline="true">
17703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17712 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17779 \layout Subsubsection
17781 \begin_inset LatexCommand \index{malloc.h}
17788 As of SDCC 2.6.2 you no longer need to call an initialization routine before
17789 using dynamic memory allocation
17790 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
17795 \begin_inset LatexCommand \index{heap (malloc)}
17799 space of 1024 bytes is provided for malloc to allocate memory from.
17800 If you need a different heap size you need to recompile _heap.c with the
17801 required size defined in HEAP_SIZE.
17802 It is recommended to make a copy of this file into your project directory
17803 and compile it there with:
17808 sdcc -c _heap.c -D HEAD_SIZE=2048
17811 And then link it with:
17816 sdcc main.rel _heap.rel
17819 Math functions (sinf, powf, sqrtf etc.)
17821 \layout Subsubsection
17825 See definitions in file <math.h>.
17832 \begin_inset LatexCommand \index{Libraries}
17836 included in SDCC should have a license at least as liberal as the GNU Lesser
17837 General Public License
17838 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
17853 license statements for the libraries are missing.
17854 sdcc/device/lib/ser_ir.c
17858 come with a GPL (as opposed to LGPL) License - this will not be liberal
17859 enough for many embedded programmers.
17866 If you have ported some library or want to share experience about some code
17868 falls into any of these categories Busses (I
17869 \begin_inset Formula $^{\textrm{2}}$
17872 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
17873 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
17874 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
17875 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
17880 would certainly like to hear about it.
17883 \added_space_bottom bigskip
17884 Programmers coding for embedded systems are not especially famous for being
17885 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
17886 e these references are very valuable.
17887 Let's help to create a climate where information is shared.
17895 MCS51 Memory Models
17896 \begin_inset LatexCommand \index{Memory model}
17901 \begin_inset LatexCommand \index{MCS51 memory model}
17907 \layout Subsubsection
17908 Small, Medium and Large
17911 SDCC allows three memory models for MCS51 code,
17920 Modules compiled with different memory models should
17924 be combined together or the results would be unpredictable.
17925 The library routines supplied with the compiler are compiled as small,
17927 The compiled library modules are contained in separate directories as small,
17928 medium and large so that you can link to the appropriate set.
17931 When the medium or large model is used all variables declared without a
17932 storage class will be allocated into the external ram, this includes all
17933 parameters and local variables (for non-reentrant
17934 \begin_inset LatexCommand \index{reentrant}
17939 When the small model is used variables without storage class are allocated
17940 in the internal ram.
17943 Judicious usage of the processor specific storage classes
17944 \begin_inset LatexCommand \index{Storage class}
17948 and the 'reentrant' function type will yield much more efficient code,
17949 than using the large model.
17950 Several optimizations are disabled when the program is compiled using the
17951 large model, it is therefore recommended that the small model be used unless
17952 absolutely required.
17954 \layout Subsubsection
17956 \begin_inset LatexCommand \label{sub:External-Stack}
17961 \begin_inset LatexCommand \index{stack}
17966 \begin_inset LatexCommand \index{External stack (mcs51)}
17973 The external stack (-
17986 \begin_inset LatexCommand \index{-\/-xstack}
17990 ) is located in pdata
17991 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
17995 memory (usually at the start of the external ram segment) and uses all
17996 unused space in pdata (max.
18010 -xstack option is used to compile the program, the parameters and local
18012 \begin_inset LatexCommand \index{local variables}
18016 of all reentrant functions are allocated in this area.
18017 This option is provided for programs with large stack space requirements.
18018 When used with the -
18031 \begin_inset LatexCommand \index{-\/-stack-auto}
18035 option, all parameters and local variables are allocated on the external
18036 stack (note: support libraries will need to be recompiled with the same
18038 There is a predefined target in the library makefile).
18041 The compiler outputs the higher order address byte of the external ram segment
18043 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18048 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18052 ), therefore when using the External Stack option, this port
18056 be used by the application program.
18060 \begin_inset LatexCommand \index{Memory model}
18065 \begin_inset LatexCommand \index{DS390 memory model}
18072 The only model supported is Flat 24
18073 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18078 This generates code for the 24 bit contiguous addressing mode of the Dallas
18080 In this mode, up to four meg of external RAM or code space can be directly
18082 See the data sheets at www.dalsemi.com for further information on this part.
18087 that the compiler does not generate any code to place the processor into
18088 24 bitmode (although
18092 in the ds390 libraries will do that for you).
18098 \begin_inset LatexCommand \index{Tinibios (DS390)}
18102 , the boot loader or similar code must ensure that the processor is in 24
18103 bit contiguous addressing mode before calling the SDCC startup code.
18124 option, variables will by default be placed into the XDATA segment.
18129 Segments may be placed anywhere in the 4 meg address space using the usual
18143 Note that if any segments are located above 64K, the -r flag must be passed
18144 to the linker to generate the proper segment relocations, and the Intel
18145 HEX output format must be used.
18146 The -r flag can be passed to the linker by using the option
18150 on the SDCC command line.
18151 However, currently the linker can not handle code segments > 64k.
18155 \begin_inset LatexCommand \label{sec:Pragmas}
18160 \begin_inset LatexCommand \index{Pragmas}
18167 SDCC supports the following #pragma directives:
18175 \begin_inset LatexCommand \index{\#pragma save}
18179 - this will save most current options to the save/restore stack.
18180 See #pragma\SpecialChar ~
18189 \begin_inset LatexCommand \index{\#pragma restore}
18193 - will restore saved options from the last save.
18194 saves & restores can be nested.
18195 SDCC uses a save/restore stack: save pushes current options to the stack,
18196 restore pulls current options from the stack.
18197 See #pragma\SpecialChar ~
18208 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18213 \begin_inset LatexCommand \index{function prologue}
18217 function1[,function2[,function3...]] - The compiler by default uses a caller
18218 saves convention for register saving across function calls, however this
18219 can cause unnecessary register pushing & popping
18220 \begin_inset LatexCommand \index{push/pop}
18224 when calling small functions from larger functions.
18225 This option can be used to switch off the register saving convention for
18226 the function names specified.
18227 The compiler will not save registers when calling these functions, extra
18228 code need to be manually inserted at the entry & exit for these functions
18229 to save & restore the registers used by these functions, this can SUBSTANTIALLY
18230 reduce code & improve run time performance of the generated code.
18231 In the future the compiler (with inter procedural analysis) may be able
18232 to determine the appropriate scheme to use for each function call.
18245 -callee-saves command line option is used, the function names specified
18246 in #pragma\SpecialChar ~
18248 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18252 is appended to the list of functions specified in the command line.
18260 \begin_inset LatexCommand \index{\#pragma exclude}
18264 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
18265 of pairs of push/pop
18266 \begin_inset LatexCommand \index{push/pop}
18275 \begin_inset LatexCommand \index{interrupt}
18288 The directive should be placed immediately before the ISR function definition
18289 and it affects ALL ISR functions following it.
18290 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
18291 exclude\SpecialChar ~
18293 \begin_inset LatexCommand \index{\#pragma exclude}
18298 See also the related keyword _naked
18299 \begin_inset LatexCommand \index{\_naked}
18304 \begin_inset LatexCommand \index{\_\_naked}
18316 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
18320 - the compiler will not warn you anymore for obvious mistakes, you'r on
18329 \begin_inset LatexCommand \index{\#pragma disable\_warning}
18333 - the compiler will not warn you anymore about warning number <nnnn>.
18341 \begin_inset LatexCommand \index{\#pragma nogcse}
18345 - will stop global common subexpression elimination.
18353 \begin_inset LatexCommand \index{\#pragma noinduction}
18357 - will stop loop induction optimizations.
18365 \begin_inset LatexCommand \index{\#pragma noinvariant}
18369 - will not do loop invariant optimizations.
18370 For more details see Loop Invariants in section
18371 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
18383 \begin_inset LatexCommand \index{\#pragma noiv}
18387 - Do not generate interrupt
18388 \begin_inset LatexCommand \index{interrupt}
18393 \begin_inset LatexCommand \index{interrupt vector table}
18397 entries for all ISR functions defined after the pragma.
18398 This is useful in cases where the interrupt vector table must be defined
18399 manually, or when there is a secondary, manually defined interrupt vector
18401 for the autovector feature of the Cypress EZ-USB FX2).
18402 More elegantly this can be achieved by obmitting the optional interrupt
18403 number after the interrupt keyword, see section
18404 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
18417 \begin_inset LatexCommand \index{\#pragma nojtbound}
18421 - will not generate code for boundary value checking, when switch statements
18422 are turned into jump-tables (dangerous).
18423 For more details see section
18424 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
18436 \begin_inset LatexCommand \index{\#pragma noloopreverse}
18440 - Will not do loop reversal optimization
18448 \begin_inset LatexCommand \index{\#pragma nooverlay}
18452 - the compiler will not overlay the parameters and local variables of a
18461 \begin_inset LatexCommand \index{\#pragma stackauto}
18478 \begin_inset LatexCommand \index{-\/-stack-auto}
18483 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
18487 Parameters and Local Variables.
18495 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
18499 - The compiler will optimize code generation towards fast code, possibly
18500 at the expense of code size.
18501 Currently this has little effect.
18509 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
18513 - The compiler will optimize code generation towards compact code, possibly
18514 at the expense of code speed.
18515 Currently this has little effect.
18523 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
18527 - The compiler will attempt to generate code that is both compact and fast,
18528 as long as meeting one goal is not a detriment to the other (this is the
18538 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
18542 - Generally follow the C89 standard, but allow SDCC features that conflict
18543 with the standard (default).
18551 \begin_inset LatexCommand \index{\#pragma std\_c89}
18555 - Follow the C89 standard and disable SDCC features that conflict with the
18564 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
18568 - Generally follow the C99 standard, but allow SDCC features that conflict
18569 with the standard (incomplete support).
18577 \begin_inset LatexCommand \index{\#pragma std\_c99}
18581 - Follow the C99 standard and disable SDCC features that conflict with the
18582 standard (incomplete support).
18590 \begin_inset LatexCommand \index{\#pragma codeseg}
18594 - Use this name (max.
18595 8 characters) for the code segment.
18616 \begin_inset LatexCommand \index{\#pragma constseg}
18620 - Use this name (max.
18621 8 characters) for the const segment.
18637 The preprocessor SDCPP
18638 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
18642 supports the following #pragma directives:
18647 pedantic_parse_number
18650 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18654 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
18655 parsed properly and the macro LO_B(3) gets expanded.
18657 Below is an example on how to use this pragma.
18660 Note: this functionality is not in conformance with standard!
18665 #pragma pedantic_parse_number +
18666 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18674 #define LO_B(x) ((x) & 0xff)
18678 unsigned char foo(void)
18685 unsigned char c=0xfe-LO_B(3)
18705 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18709 (+ | -) - switch _asm _endasm block preprocessing on / off.
18711 You use this prama to define multilines of assembly code.
18712 This will prevent the preprocessor from changing the formating required
18714 Below is an example on how to use this pragma.
18719 #pragma preproc_asm -
18720 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18726 #define MYDELAY _asm
18731 nop ;my assembly comment...
18745 #pragma preproc_asm
18781 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18785 (+ | -) - Allow "naked" hash in macro definition, for example:
18789 #define DIR_LO(x) #(x & 0xff)
18794 Below is an example on how to use this pragma.
18799 #pragma preproc_asm +
18801 #pragma sdcc_hash +
18802 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18817 mov R6_B3, #(x & 0xff)
18824 mov R7_B3, #((x >> 8) & 0xff)
18848 The pragma's are intended to be used to turn-on or off certain optimizations
18849 which might cause the compiler to generate extra stack / data space to
18850 store compiler generated temporary variables.
18851 This usually happens in large functions.
18852 Pragma directives should be used as shown in the following example, they
18853 are used to control options & optimizations for a given function; pragmas
18854 should be placed before and/or after a function, placing pragma's inside
18855 a function body could have unpredictable results.
18861 \begin_inset LatexCommand \index{\#pragma save}
18872 /* save the current settings */
18875 \begin_inset LatexCommand \index{\#pragma nogcse}
18884 /* turnoff global subexpression elimination */
18886 #pragma noinduction
18887 \begin_inset LatexCommand \index{\#pragma noinduction}
18891 /* turn off induction optimizations */
18914 \begin_inset LatexCommand \index{\#pragma restore}
18918 /* turn the optimizations back on */
18921 The compiler will generate a warning message when extra space is allocated.
18922 It is strongly recommended that the save and restore pragma's be used when
18923 changing options for a function.
18932 Defines Created by the Compiler
18935 The compiler creates the following #defines
18936 \begin_inset LatexCommand \index{\#defines}
18941 \begin_inset LatexCommand \index{Defines created by the compiler}
18950 \begin_inset Tabular
18951 <lyxtabular version="3" rows="11" columns="2">
18953 <column alignment="left" valignment="top" leftline="true" width="3in">
18954 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
18955 <row topline="true" bottomline="true">
18956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18977 <row topline="true">
18978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18983 \begin_inset LatexCommand \index{SDCC}
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18996 Since version 2.5.6 the version number as an int (ex.
19002 <row topline="true">
19003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19008 \begin_inset LatexCommand \index{SDCC\_mcs51}
19013 \begin_inset LatexCommand \index{SDCC\_ds390}
19018 \begin_inset LatexCommand \index{SDCC\_z80}
19026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19030 depending on the model used (e.g.: -mds390)
19035 <row topline="true">
19036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19041 \begin_inset LatexCommand \index{\_\_mcs51}
19046 \begin_inset LatexCommand \index{\_\_ds390}
19051 \begin_inset LatexCommand \index{\_\_hc08}
19056 \begin_inset LatexCommand \index{\_\_z80}
19064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19068 depending on the model used (e.g.
19074 <row topline="true">
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19080 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19113 <row topline="true">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19119 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
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\_MEDIUM}
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\_LARGE}
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\_USE\_XSTACK}
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\_STACK\_TENBIT}
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19296 <row topline="true" bottomline="true">
19297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19302 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19330 Notes on supported Processors
19334 \begin_inset LatexCommand \label{sub:MCS51-variants}
19339 \begin_inset LatexCommand \index{MCS51 variants}
19346 MCS51 processors are available from many vendors and come in many different
19348 While they might differ considerably in respect to Special Function Registers
19349 the core MCS51 is usually not modified or is kept compatible.
19353 pdata access by SFR
19356 With the upcome of devices with internal xdata and flash memory devices
19358 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19362 as dedicated I/O port is becoming more popular.
19363 Switching the high byte for pdata
19364 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19368 access which was formerly done by port P2 is then achieved by a Special
19370 \begin_inset LatexCommand \index{sfr}
19375 In well-established MCS51 tradition the address of this
19379 is where the chip designers decided to put it.
19380 Needless to say that they didn't agree on a common name either.
19381 So that the startup code can correctly initialize xdata variables, you
19382 should define an sfr with the name _XPAGE
19385 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
19391 at the appropriate location if the default, port P2, is not used for this.
19397 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
19402 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19407 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19410 For more exotic implementations further customizations may be needed.
19412 \begin_inset LatexCommand \ref{sub:Startup-Code}
19416 for other possibilities.
19419 Other Features available by SFR
19422 \added_space_bottom bigskip
19423 Some MCS51 variants offer features like Double DPTR
19424 \begin_inset LatexCommand \index{DPTR}
19428 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19429 These are currently not used for the MCS51 port.
19430 If you absolutely need them you can fall back to inline assembly or submit
19439 \added_space_bottom bigskip
19441 \begin_inset LatexCommand \index{DS80C400}
19446 \begin_inset LatexCommand \index{DS400}
19450 microcontroller has a rich set of peripherals.
19451 In its built-in ROM library it includes functions to access some of the
19452 features, among them is a TCP stack with IP4 and IP6 support.
19453 Library headers (currently in beta status) and other files are provided
19457 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
19467 The Z80 and gbz80 port
19470 SDCC can target both the Zilog Z80
19471 \begin_inset LatexCommand \index{Z80}
19475 and the Nintendo Gameboy's Z80-like gbz80
19476 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19481 The Z80 port is passed through the same
19484 \begin_inset LatexCommand \index{Regression test}
19491 \begin_inset LatexCommand \ref{sec:Quality-control}
19495 ) as the MCS51 and DS390 ports, so floating point support, support for long
19496 variables and bitfield support is fine.
19497 See mailing lists and forums about interrupt routines.
19500 \added_space_bottom bigskip
19501 As always, the code is the authoritative reference - see z80/ralloc.c and
19504 \begin_inset LatexCommand \index{Z80!stack}
19508 frame is similar to that generated by the IAR Z80 compiler.
19509 IX is used as the base pointer, HL and IY are used as a temporary registers,
19510 and BC and DE are available for holding variables.
19512 \begin_inset LatexCommand \index{Z80!return value}
19516 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
19518 The gbz80 port use the same set of registers for the return values, but
19519 in a different order of significance: E (one byte), DE (two bytes), or
19528 The port to the Freescale/Motorola HC08
19529 \begin_inset LatexCommand \index{HC08}
19533 family has been added in October 2003, and is still undergoing some basic
19535 The code generator is complete, but the register allocation is still quite
19537 Some of the SDCC's standard C library functions have embedded non-HC08
19538 inline assembly and so are not yet usable.
19541 \added_space_bottom bigskip
19543 The HC08 port passes the regression test suite (see section
19544 \begin_inset LatexCommand \ref{sec:Quality-control}
19558 \begin_inset LatexCommand \index{PIC14}
19562 port still requires a major effort from the development community.
19563 However it can work for simple code.
19564 It passes its (smaller set of) regression tests
19565 \begin_inset LatexCommand \index{Regression test (PIC14)}
19571 sdcc/src/regression
19576 C code and 14bit PIC code page
19577 \begin_inset LatexCommand \index{code page (pic14)}
19582 \begin_inset LatexCommand \index{RAM bank (pic14)}
19589 The linker organizes allocation for the code page and RAM banks.
19590 It does not have intimate knowledge of the code flow.
19591 It will put all the code section of a single asm file into a single code
19593 In order to make use of multiple code pages, separate asm files must be
19595 The compiler treats all functions of a single C file as being in the same
19596 code page unless it is non static.
19600 To get the best follow these guide lines:
19603 Make local functions static, as non static functions require code page selection
19607 For devices that have multiple code pages it is more efficient to use the
19608 same number of files as pages, i.e.
19609 for the 16F877 use 4 separate files and i.e.
19610 for the 16F874 use 2 separate files.
19611 This way the linker can put the code for each file into different code
19612 pages and there's less page selection overhead.
19615 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19616 instruction set), use 'unsigned char' whereever possible instead of 'int'.
19619 Creating a device include file
19622 For generating a device include file
19623 \begin_inset LatexCommand \index{PIC14!Header files}
19627 use the support perl script inc2h.pl kept in directory support/script.
19633 For the interrupt function, use the keyword '__interrupt'
19634 \begin_inset LatexCommand \index{PIC14!interrupt}
19638 with level number of 0 (PIC14 only has 1 interrupt so this number is only
19639 there to avoid a syntax error - it ought to be fixed).
19645 void Intr(void) __interrupt 0
19651 T0IF = 0; /* Clear timer interrupt */
19656 Linking and assembling
19659 For assembling you can use either GPUTILS'
19660 \begin_inset LatexCommand \index{gputils (pic tools)}
19664 gpasm.exe or MPLAB's mpasmwin.exe.
19665 GPUTILS is available from
19666 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19671 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19672 If you use MPLAB and an interrupt function then the linker script file
19673 vectors section will need to be enlarged to link with mplink.
19696 sdcc -S -V -mpic14 -p16F877 $<
19710 $(PRJ).hex: $(OBJS)
19721 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
19743 sdcc -S -V -mpic14 -p16F877 $<
19753 mpasmwin /q /o $*.asm
19757 $(PRJ).hex: $(OBJS)
19768 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
19771 Please note that indentations within a
19775 have to be done with a tabulator character.
19778 Command-line options
19781 Besides the switches common to all SDCC backends, the PIC14 port accepts
19782 the following options (for an updated list see sdcc -
19797 \labelwidthstring 00.00.0000
19811 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
19815 emit debug info in assembly output
19818 \labelwidthstring 00.00.0000
19832 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
19836 disable (slightly faulty) optimization on pCode
19839 \labelwidthstring 00.00.0000
19853 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
19857 sets the lowest address of the argument passing stack (defaults to a suitably
19858 large shared databank to reduce BANKSEL overhead)
19861 \labelwidthstring 00.00.0000
19875 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
19879 sets the size if the argument passing stack (default: 16, minimum: 4)
19884 \layout Subsubsection
19885 error: missing definition for symbol
19886 \begin_inset Quotes sld
19890 \begin_inset Quotes srd
19896 The PIC14 port uses library routines to provide more complex operations
19897 like multiplication, division/modulus and (generic) pointer dereferencing.
19898 In order to add these routines to your project, you must link with PIC14's
19904 For single source file projects this is done automatically, more complex
19909 to the linker's arguments.
19910 Make sure you also add an include path for the library (using the -I switch
19913 \layout Subsubsection
19914 Processor mismatch in file
19915 \begin_inset Quotes sld
19919 \begin_inset Quotes srd
19925 This warning can usually be ignored due to the very good compatibility amongst
19927 \begin_inset LatexCommand \index{PIC14}
19934 You might also consider recompiling the library for your specific device
19935 by changing the ARCH=p16f877 (default target) entry in
19937 device/lib/pic/Makefile.in
19941 device/lib/pic/Makefile
19943 to reflect your device.
19944 This might even improve performance for smaller devices as unneccesary
19945 BANKSELs migth be removed.
19950 \layout Subsubsection
19954 Currently, data can only be initialized if it resides in the source file
19961 Data in other source files will silently
19969 \begin_inset Marginal
19985 \begin_inset LatexCommand \index{PIC16}
19993 \begin_inset LatexCommand \index{PIC16}
19997 port is the portion of SDCC that is responsible to produce code for the
19999 \begin_inset LatexCommand \index{Microchip}
20003 (TM) microcontrollers with 16 bit core.
20004 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20005 Currently supported devices are:
20009 \begin_inset Tabular
20010 <lyxtabular version="3" rows="4" columns="6">
20012 <column alignment="center" valignment="top" leftline="true" width="0">
20013 <column alignment="center" valignment="top" leftline="true" width="0">
20014 <column alignment="center" valignment="top" leftline="true" width="0">
20015 <column alignment="center" valignment="top" leftline="true" width="0">
20016 <column alignment="center" valignment="top" leftline="true" width="0">
20017 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20018 <row topline="true">
20019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20068 <row topline="true">
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20118 <row topline="true">
20119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20168 <row topline="true" bottomline="true">
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20228 PIC16 port supports the standard command line arguments as supposed, with
20229 the exception of certain cases that will be mentioned in the following
20233 \labelwidthstring 00.00.0000
20247 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
20266 \labelwidthstring 00.00.0000
20280 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
20284 All function arguments are passed on stack by default.
20287 There is no need to specify this in the command line.
20290 \labelwidthstring 00.00.0000
20303 -fommit-frame-pointer
20304 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
20308 Frame pointer will be omitted when the function uses no local variables.
20311 Port Specific Options
20312 \begin_inset LatexCommand \index{Options PIC16}
20319 The port specific options appear after the global options in the sdcc --help
20322 \layout Subsubsection
20326 General options enable certain port features and optimizations.
20329 \labelwidthstring 00.00.0000
20342 -pstack-model=[model] Used in conjuction with the command above.
20343 Defines the stack model to be used, valid stack models are :
20347 \labelwidthstring 00.00.0000
20352 Selects small stack model.
20353 8 bit stack and frame pointers.
20354 Supports 256 bytes stack size.
20357 \labelwidthstring 00.00.0000
20362 Selects large stack model.
20363 16 bit stack and frame pointers.
20364 Supports 65536 bytes stack size.
20368 \labelwidthstring 00.00.0000
20381 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
20382 unitialized data variables with [kword].
20383 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
20386 \labelwidthstring 00.00.0000
20399 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
20400 Useful for bootloaders.
20403 \labelwidthstring 00.00.0000
20416 -asm= sets the full path and name of an external assembler to call.
20419 \labelwidthstring 00.00.0000
20432 -link= sets the full path and name of an external linker to call.
20435 \labelwidthstring 00.00.0000
20449 \begin_inset LatexCommand \index{PIC16!MPLAB}
20453 compatibility option.
20454 Currently only suppresses special gpasm directives.
20456 \layout Subsubsection
20457 Optimization Options
20460 \labelwidthstring 00.00.0000
20473 -optimize-goto Try to use (conditional) BRA instead of GOTO
20476 \labelwidthstring 00.00.0000
20489 -optimize-cmp Try to optimize some compares.
20492 \labelwidthstring 00.00.0000
20505 -optimize-df Analyze the dataflow of the generated code and improve it.
20508 \labelwidthstring 00.00.0000
20521 -obanksel=nn Set optimization level for inserting BANKSELs.
20527 \labelwidthstring 00.00.0000
20531 \labelwidthstring 00.00.0000
20532 1 checks previous used register and if it is the same then does not emit
20533 BANKSEL, accounts only for labels.
20536 \labelwidthstring 00.00.0000
20537 2 tries to check the location of (even different) symbols and removes BANKSELs
20538 if they are in the same bank.
20543 Important: There might be problems if the linker script has data sections
20544 across bank borders!
20547 \layout Subsubsection
20551 \labelwidthstring 00.00.0000
20564 -nodefaultlibs do not link default libraries when linking
20567 \labelwidthstring 00.00.0000
20580 -no-crt Don't link the default run-time modules
20583 \labelwidthstring 00.00.0000
20596 -use-crt= Use a custom run-time module instead of the defaults.
20598 \layout Subsubsection
20602 Debugging options enable extra debugging information in the output files.
20605 \labelwidthstring 00.00.0000
20618 -debug-xtra Similar to -
20631 \begin_inset LatexCommand \index{-\/-debug}
20635 , but dumps more information.
20638 \labelwidthstring 00.00.0000
20651 -debug-ralloc Force register allocator to dump <source>.d file with debugging
20653 <source> is the name of the file compiled.
20656 \labelwidthstring 00.00.0000
20669 -pcode-verbose Enable pcode debugging information in translation.
20672 \labelwidthstring 00.00.0000
20685 -denable-peeps Force the usage of peepholes.
20689 \labelwidthstring 00.00.0000
20702 -gstack Trace push/pops for stack pointer overflow
20705 \labelwidthstring 00.00.0000
20718 -call-tree dump call tree in .calltree file
20721 Enviromental Variables
20724 There is a number of enviromental variables that can be used when running
20725 SDCC to enable certain optimizations or force a specific program behaviour.
20726 these variables are primarily for debugging purposes so they can be enabled/dis
20730 Currently there is only two such variables available:
20733 \labelwidthstring 00.00.0000
20734 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
20735 bitfields is optimized by directly loading FSR0 with the address of the
20736 bitfield structure.
20737 Normally SDCC will cast the bitfield structure to a bitfield pointer and
20739 This step saves data ram and code space for functions that perform heavy
20742 80 bytes of code space are saved when compiling malloc.c with this option).
20746 \labelwidthstring 00.00.0000
20747 NO_REG_OPT do not perform pCode registers optimization.
20748 This should be used for debugging purposes.
20749 In some where bugs in the pcode optimizer are found, users can benefit
20750 from temporarily disabling the optimizer until the bug is fixed.
20753 Preprocessor Macros
20757 \begin_inset LatexCommand \index{PIC16}
20761 port defines the following preprocessor macros while translating a source.
20765 \begin_inset Tabular
20766 <lyxtabular version="3" rows="6" columns="2">
20768 <column alignment="center" valignment="top" leftline="true" width="0">
20769 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20770 <row topline="true" bottomline="true">
20771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20788 <row topline="true">
20789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20801 Port identification
20806 <row topline="true">
20807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20831 Port identification (same as above)
20836 <row topline="true">
20837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20849 MCU Identification.
20854 is the microcontrol identification number, i.e.
20860 <row topline="true">
20861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20885 MCU Identification (same as above)
20890 <row topline="true" bottomline="true">
20891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20903 nnn = SMALL or LARGE respectively according to the stack model used
20915 In addition the following macros are defined when calling assembler:
20919 \begin_inset Tabular
20920 <lyxtabular version="3" rows="4" columns="2">
20922 <column alignment="center" valignment="top" leftline="true" width="0">
20923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20924 <row topline="true" bottomline="true">
20925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20942 <row topline="true">
20943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20955 MCU Identification.
20960 is the microcontrol identification number, i.e.
20966 <row topline="true">
20967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20979 nnn = SMALL or LARGE respectively according to the memory model used for
20985 <row topline="true" bottomline="true">
20986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20998 nnn = SMALL or LARGE respectively according to the stack model used
21014 \begin_inset LatexCommand \index{PIC16}
21018 port uses the following directories for searching header files and libraries.
21022 \begin_inset Tabular
21023 <lyxtabular version="3" rows="3" columns="4">
21025 <column alignment="center" valignment="top" leftline="true" width="0">
21026 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21027 <column alignment="center" valignment="top" width="0">
21028 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21029 <row topline="true" bottomline="true">
21030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21063 <row topline="true">
21064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21068 PREFIX/sdcc/include/pic16
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21076 PIC16 specific headers
21080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21097 <row topline="true" bottomline="true">
21098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21102 PREFIX/sdcc/lib/pic16
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21110 PIC16 specific libraries
21114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21139 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
21147 \begin_inset LatexCommand \index{PIC16}
21151 port currently supports the following pragmas:
21154 \labelwidthstring 00.00.0000
21156 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
21161 \begin_inset LatexCommand \index{PIC16!stack}
21165 forces the code generator to initialize the stack & frame pointers at a
21167 This is an adhoc solution for cases where no STACK directive is available
21168 in the linker script or gplink is not instructed to create a stack section.
21171 stack pragma should be used only once in a project.
21172 Multiple pragmas may result in indeterminate behaviour of the program.
21177 The old format (ie.
21178 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
21179 cross page boundaries (or even exceed the available data RAM) and crash
21181 Make sure that stack does not cross page boundaries when using the SMALL
21188 The format is as follows:
21191 #pragma stack bottom_address [stack_size]
21198 is the lower bound of the stack section.
21199 The stack pointer initially will point at address (bottom_address+stack_size-1).
21208 /* initializes stack of 100 bytes at RAM address 0x200 */
21211 #pragma stack 0x200 100
21214 If the stack_size field is omitted then a stack is created with the default
21216 This size might be enough for most programs, but its not enough for operations
21217 with deep function nesting or excessive stack usage.
21220 \labelwidthstring 00.00.0000
21222 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
21226 place a function symbol at static FLASH address
21235 /* place function test_func at 0x4000 */
21238 #pragma code test_func 0x4000
21244 \labelwidthstring 00.00.0000
21245 library instructs the linker to use a library module.
21250 #pragma library module_name
21257 can be any library or object file (including its path).
21258 Note that there are four reserved keywords which have special meaning.
21263 \begin_inset Tabular
21264 <lyxtabular version="3" rows="6" columns="3">
21266 <column alignment="center" valignment="top" leftline="true" width="0">
21267 <column alignment="block" valignment="top" leftline="true" width="20page%">
21268 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
21269 <row topline="true" bottomline="true">
21270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21295 <row topline="true">
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21310 ignore all library pragmas
21314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21325 <row topline="true">
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21357 <row topline="true">
21358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21372 link the Math libarary
21376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21389 <row topline="true">
21390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21404 link the I/O library
21408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21421 <row topline="true" bottomline="true">
21422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21436 link the debug library
21440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21459 * is the device number, i.e.
21460 452 for PIC18F452 MCU.
21463 This feature allows for linking with specific libraries withoug having to
21464 explicit name them in the command line.
21469 keyword will reject all modules specified by the library pragma.
21472 \labelwidthstring 00.00.0000
21473 udata pragma udata instructs the compiler to emit code so that linker will
21474 place a variable at a specific memory bank
21483 /* places variable foo at bank2 */
21486 #pragma udata bank2 foo
21492 In order for this pragma to work extra SECTION directives should be added
21493 in the .lkr script.
21494 In the following example a sample .lkr file is shown:
21500 // Sample linker script for the PIC18F452 processor
21506 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
21509 CODEPAGE NAME=page START=0x2A END=0x7FFF
21512 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
21515 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
21518 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
21521 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
21524 ACCESSBANK NAME=accessram START=0x0 END=0x7F
21530 DATABANK NAME=gpr0 START=0x80 END=0xFF
21533 DATABANK NAME=gpr1 START=0x100 END=0x1FF
21536 DATABANK NAME=gpr2 START=0x200 END=0x2FF
21539 DATABANK NAME=gpr3 START=0x300 END=0x3FF
21542 DATABANK NAME=gpr4 START=0x400 END=0x4FF
21545 DATABANK NAME=gpr5 START=0x500 END=0x5FF
21548 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
21554 SECTION NAME=CONFIG ROM=config
21560 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
21563 SECTION NAME=bank1 RAM=gpr1 # should be added to link
21566 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
21569 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
21572 SECTION NAME=bank4 RAM=gpr4
21575 SECTION NAME=bank5 RAM=gpr5
21578 The linker will recognise the section name set in the pragma statement and
21579 will position the variable at the memory bank set with the RAM field at
21580 the SECTION line in the linker script file.
21584 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
21591 There is one main header file
21592 \begin_inset LatexCommand \index{PIC16!Header files}
21596 that can be included to the source files using the pic16
21597 \begin_inset LatexCommand \index{PIC16}
21607 This header file contains the definitions for the processor special registers,
21608 so it is necessary if the source accesses them.
21609 It can be included by adding the following line in the beginning of the
21613 #include <pic18fregs.h>
21616 The specific microcontroller is selected within the pic18fregs.h automatically,
21617 so the same source can be used with a variety of devices.
21624 \begin_inset LatexCommand \index{PIC16!Libraries}
21629 \begin_inset LatexCommand \index{PIC16}
21633 port depends on are the microcontroller device libraries which contain
21634 the symbol definitions for the microcontroller special function registers.
21635 These libraries have the format pic18fxxxx.lib, where
21639 is the microcontroller identification number.
21640 The specific library is selected automatically by the compiler at link
21641 stage according to the selected device.
21644 Libraries are created with gplib which is part of the gputils package
21645 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21651 \layout Subsubsection*
21652 Building the libraries
21655 Before using SDCC/pic16 there are some libraries that need to be compiled.
21656 This process is not done automatically by SDCC since not all users use
21657 SDCC for pic16 projects.
21658 So each user should compile the libraries separately.
21661 The steps to compile the pic16 libraries under Linux are:
21664 cd device/lib/pic16
21679 su -c 'make install' # install the libraries, you need the root password
21682 If you need to install the headers too, do:
21688 su -c 'make install' # install the headers, you need the root password
21691 There exist a special target to build the I/O libraries.
21692 This target is not automatically build because it will build the I/O library
21698 This way building will take quite a lot of time.
21699 Users are advised to edit the
21701 device/lib/pic16/pics.build
21703 file and then execute:
21712 The following memory models are supported by the PIC16 port:
21721 Memory model affects the default size of pointers within the source.
21722 The sizes are shown in the next table:
21726 \begin_inset Tabular
21727 <lyxtabular version="3" rows="3" columns="3">
21729 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21730 <column alignment="center" valignment="top" leftline="true" width="0">
21731 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21732 <row topline="true" bottomline="true">
21733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21737 Pointer sizes according to memory model
21741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21758 <row topline="true" bottomline="true">
21759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21767 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21784 <row topline="true" bottomline="true">
21785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21793 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
21801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21817 It is advisable that all sources within a project are compiled with the
21819 If one wants to override the default memory model, this can be done by
21820 declaring a pointer as
21829 Far selects large memory model's pointers, while near selects small memory
21833 The standard device libraries (see
21834 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
21838 ) contain no reference to pointers, so they can be used with both memory
21846 \begin_inset LatexCommand \index{PIC16!stack}
21850 implementation for the PIC16 port uses two indirect registers, FSR1 and
21854 \labelwidthstring 00.00.0000
21855 FSR1 is assigned as stack pointer
21858 \labelwidthstring 00.00.0000
21859 FSR2 is assigned as frame pointer
21862 The following stack models are supported by the PIC16 port
21883 model means that only the FSRxL byte is used to access stack and frame,
21890 uses both FSRxL and FSRxH registers.
21891 The following table shows the stack/frame pointers sizes according to stack
21892 model and the maximum space they can address:
21896 \begin_inset Tabular
21897 <lyxtabular version="3" rows="3" columns="3">
21899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21900 <column alignment="center" valignment="top" leftline="true" width="0">
21901 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21902 <row topline="true" bottomline="true">
21903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21907 Stack & Frame pointer sizes according to stack model
21911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21928 <row topline="true">
21929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21954 <row topline="true" bottomline="true">
21955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21991 stack model is currently not working properly throughout the code generator.
21992 So its use is not advised.
21993 Also there are some other points that need special care:
21998 Do not create stack sections with size more than one physical bank (that
22002 Stack sections should no cross physical bank limits (i.e.
22003 #pragma stack 0x50 0x100)
22006 These limitations are caused by the fact that only FSRxL is modified when
22007 using SMALL stack model, so no more than 256 bytes of stack can be used.
22008 This problem will disappear after LARGE model is fully implemented.
22014 In addition to the standard SDCC function keywords, PIC16
22015 \begin_inset LatexCommand \index{PIC16}
22019 port makes available two more:
22022 \labelwidthstring 00.00.0000
22024 \begin_inset LatexCommand \index{PIC16!wparam}
22028 Use the WREG to pass one byte of the first function argument.
22029 This improves speed but you may not use this for functions with arguments
22030 that are called via function pointers, otherwise the first byte of the
22031 first parameter will get lost.
22035 void func_wparam(int a) wparam
22041 /* WREG hold the lower part of a */
22044 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22054 \labelwidthstring 00.00.0000
22056 \begin_inset LatexCommand \index{PIC16!shadowregs}
22060 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22061 hardware shadow registers which hold the values of WREG, STATUS and BSR
22063 This can be done by adding the keyword
22071 keyword in the function's header.
22074 void isr_shadow(void) shadowregs interrupt 1
22090 instructs the code generator not to store/restore WREG, STATUS, BSR when
22091 entering/exiting the ISR.
22094 Function return values
22097 Return values from functions are placed to the appropriate registers following
22098 a modified Microchip policy optimized for SDCC.
22099 The following table shows these registers:
22103 \begin_inset Tabular
22104 <lyxtabular version="3" rows="6" columns="2">
22106 <column alignment="center" valignment="top" leftline="true" width="0">
22107 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22108 <row topline="true" bottomline="true">
22109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22121 destination register
22126 <row topline="true">
22127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22144 <row topline="true">
22145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22162 <row topline="true">
22163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22180 <row topline="true">
22181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22193 FSR0L:PRODH:PRODL:WREG
22198 <row topline="true" bottomline="true">
22199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22211 on stack, FSR0 points to the beginning
22227 \begin_inset LatexCommand \index{PIC16!interrupt}
22231 service routine (ISR) is declared using the
22238 void isr(void) interrupt
22256 is the interrupt number, which for PIC18F devices can be:
22260 \begin_inset Tabular
22261 <lyxtabular version="3" rows="4" columns="3">
22263 <column alignment="center" valignment="top" leftline="true" width="0">
22264 <column alignment="center" valignment="top" leftline="true" width="0">
22265 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22266 <row topline="true" bottomline="true">
22267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22289 Interrupt Vector Address
22294 <row topline="true">
22295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22320 <row topline="true">
22321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22351 HIGH priority interrupts
22355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22364 <row topline="true" bottomline="true">
22365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22377 LOW priority interrupts
22381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22397 When generating assembly code for ISR the code generator places a
22403 Interrupt Vector Address
22405 which points at the genetated ISR.
22406 This single GOTO instruction is part of an automatically generated
22408 interrupt entry point
22411 The actuall ISR code is placed as normally would in the code space.
22412 Upon interrupt request, the GOTO instruction is executed which jumps to
22414 When declaring interrupt functions as _naked this GOTO instruction is
22419 The whole interrupt functions is therefore placed at the Interrupt Vector
22420 Address of the specific interrupt.
22421 This is not a problem for the LOW priority interrupts, but it is a problem
22422 for the RESET and the HIGH priority interrupts because code may be written
22423 at the next interrupt´s vector address and cause undeterminate program
22424 behaviour if that interrupt is raised.
22429 This is not a problem when
22432 this is a HIGH interrupt ISR and LOW interrupts are
22439 when the ISR is small enough not to reach the next interrupt´s vector address.
22450 is possible to be omitted.
22451 This way a function is generated similar to an ISR, but it is not assigned
22455 When entering an interrupt, currently the PIC16
22456 \begin_inset LatexCommand \index{PIC16}
22460 port automatically saves the following registers:
22472 PROD (PRODL and PRODH)
22475 FSR0 (FSR0L and FSR0H)
22478 These registers are restored upon return from the interrupt routine.
22483 NOTE that when the _naked attribute is specified for an interrupt routine,
22484 then NO registers are stored or restored.
22494 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
22495 There are 3 types of generic pointers currently implemented data, code
22496 and eeprom pointers.
22497 They are differentiated by the value of the 7th and 6th bits of the upper
22502 \begin_inset Tabular
22503 <lyxtabular version="3" rows="5" columns="5">
22505 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22506 <column alignment="center" valignment="top" width="0">
22507 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22508 <column alignment="center" valignment="top" width="0">
22509 <column alignment="left" valignment="top" rightline="true" width="0">
22510 <row topline="true" bottomline="true">
22511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22539 rest of the pointer
22543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22552 <row topline="true" bottomline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22585 uuuuuu uuuuxxxx xxxxxxxx
22589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22593 a 12-bit data pointer in data RAM memory
22598 <row bottomline="true">
22599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22631 uxxxxx xxxxxxxx xxxxxxxx
22635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22639 a 21-bit code pointer in FLASH memory
22644 <row bottomline="true">
22645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22677 uuuuuu uuuuuuxx xxxxxxxx
22681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22685 a 10-bit eeprom pointer in EEPROM memory
22690 <row bottomline="true">
22691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22723 xxxxxx xxxxxxxx xxxxxxxx
22727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22731 unimplemented pointer type
22743 Generic pointer are read and written with a set of library functions which
22744 read/write 1, 2, 3, 4 bytes.
22749 \layout Subsubsection
22750 Standard I/O Streams
22757 the type FILE is defined as:
22760 typedef char * FILE;
22763 This type is the stream type implemented I/O in the PIC18F devices.
22764 Also the standard input and output streams are declared in stdio.h:
22767 extern FILE * stdin;
22770 extern FILE * stdout;
22773 The FILE type is actually a generic pointer which defines one more type
22774 of generic pointers, the
22779 This new type has the format:
22783 \begin_inset Tabular
22784 <lyxtabular version="3" rows="2" columns="7">
22786 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22787 <column alignment="center" valignment="top" width="0">
22788 <column alignment="center" valignment="top" leftline="true" width="0">
22789 <column alignment="center" valignment="top" leftline="true" width="0">
22790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22791 <column alignment="center" valignment="top" width="0">
22792 <column alignment="left" valignment="top" rightline="true" width="0">
22793 <row topline="true" bottomline="true">
22794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22838 rest of the pointer
22842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22851 <row topline="true" bottomline="true">
22852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22908 upper byte high nubble is 0x2n, the rest are zeroes
22920 Currently implemented there are 3 types of streams defined:
22924 \begin_inset Tabular
22925 <lyxtabular version="3" rows="4" columns="4">
22927 <column alignment="center" valignment="top" leftline="true" width="0">
22928 <column alignment="center" valignment="top" leftline="true" width="0">
22929 <column alignment="center" valignment="top" leftline="true" width="0">
22930 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22931 <row topline="true" bottomline="true">
22932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22996 Writes/Reads characters via the USART peripheral
23001 <row topline="true">
23002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23032 Writes/Reads characters via the MSSP peripheral
23037 <row topline="true" bottomline="true">
23038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23068 Writes/Reads characters via used defined functions
23080 The stream identifiers are declared as macros in the stdio.h header.
23083 In the libc library there exist the functions that are used to write to
23084 each of the above streams.
23088 \labelwidthstring 00.00.0000
23101 _stream_usart_putchar writes a character at the USART stream
23104 \labelwidthstring 00.00.0000
23117 _stream_mssp_putchar writes a character at the MSSP stream
23120 \labelwidthstring 00.00.0000
23121 putchar dummy function.
23122 This writes a character to a user specified manner.
23125 In order to increase performance
23129 is declared in stdio.h as having its parameter in WREG (it has the wparam
23131 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
23132 in a user-friendly way.
23137 is the name of the variable that holds the character to print.
23138 An example follows:
23141 #include <pic18fregs.h>
23153 PORTA = c; /* dump character c to PORTA */
23166 stdout = STREAM_USER; /* this is not necessary, since stdout points
23169 * by default to STREAM_USER */
23172 printf (¨This is a printf test
23182 \layout Subsubsection
23186 PIC16 contains an implementation of the printf-family of functions.
23187 There exist the following functions:
23190 extern unsigned int sprintf(char *buf, char *fmt, ...);
23193 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
23199 extern unsigned int printf(char *fmt, ...);
23202 extern unsigned int vprintf(char *fmt, va_lista ap);
23208 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
23211 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
23214 For sprintf and vsprintf
23218 should normally be a data pointer where the resulting string will be placed.
23219 No range checking is done so the user should allocate the necessery buffer.
23220 For fprintf and vfprintf
23224 should be a stream pointer (i.e.
23225 stdout, STREAM_MSSP, etc...).
23227 \layout Subsubsection
23231 The PIC18F family of microcontrollers supports a number of interrupt sources.
23232 A list of these interrupts is shown in the following table:
23236 \begin_inset Tabular
23237 <lyxtabular version="3" rows="11" columns="4">
23239 <column alignment="left" valignment="top" leftline="true" width="0">
23240 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23241 <column alignment="left" valignment="top" leftline="true" width="0">
23242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23243 <row topline="true" bottomline="true">
23244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23277 <row topline="true">
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23286 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23290 PORTB change interrupt
23294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23306 EEPROM/FLASH write complete interrupt
23311 <row topline="true">
23312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23324 INT0 external interrupt
23328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23340 Bus collision interrupt
23345 <row topline="true">
23346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23358 INT1 external interrupt
23362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23374 Low voltage detect interrupt
23379 <row topline="true">
23380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23392 INT2 external interrupt
23396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23408 Parallel slave port interrupt
23413 <row topline="true">
23414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23426 CCP1 module interrupt
23430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23442 AD convertion complete interrupt
23447 <row topline="true">
23448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23460 CCP2 module interrupt
23464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23476 USART receive interrupt
23481 <row topline="true">
23482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23494 TMR0 overflow interrupt
23498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23510 USART transmit interrupt
23515 <row topline="true">
23516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23528 TMR1 overflow interrupt
23532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23544 SSP receive/transmit interrupt
23549 <row topline="true">
23550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23562 TMR2 matches PR2 interrupt
23566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23583 <row topline="true" bottomline="true">
23584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23596 TMR3 overflow interrupt
23600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23624 The prototypes for these names are defined in the header file
23631 In order to simplify signal handling, a number of macros is provided:
23634 \labelwidthstring 00.00.0000
23635 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
23636 high priority interrupts.
23641 is the function name to use.
23644 \labelwidthstring 00.00.0000
23645 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
23646 low priority interrupt.
23651 is the function name to use.
23654 \labelwidthstring 00.00.0000
23655 DEF_HANDLER(sig,handler) define a handler for signal
23660 \labelwidthstring 00.00.0000
23661 END_DEF end the declaration of the dispatch table.
23664 Additionally there are two more macros to simplify the declaration of the
23668 \labelwidthstring 00.00.0000
23671 SIGHANDLER(handler)
23673 this declares the function prototype for the
23680 \labelwidthstring 00.00.0000
23681 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
23684 An example of using the macros above is shown below:
23687 #include <pic18fregs.h>
23690 #include <signal.h>
23694 DEF_INTHIGH(high_int)
23697 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
23700 DEF_HANDLER(SIG_BCOL, _bcol_handler)
23707 SIGHANDLER(_tmr0_handler)
23713 /* action to be taken when timer 0 overflows */
23720 SIGHANDLERNAKED(_bcol_handler)
23729 /* action to be taken when bus collision occurs */
23745 Special care should be taken when using the above scheme:
23748 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
23751 when declaring SIGHANDLERNAKED handler never forget to use
23755 for proper returning.
23761 Here you can find some general tips for compiling programs with SDCC/pic16.
23763 \layout Subsubsection
23768 \begin_inset LatexCommand \index{PIC16!stack}
23772 size (that is 64 bytes) probably is enough for many programs.
23773 One must take care that when there are many levels of function nesting,
23774 or there is excessive usage of stack, its size should be extended.
23775 An example of such a case is the printf/sprintf family of functions.
23776 If you encounter problems like not being able to print integers, then you
23777 need to set the stack size around the maximum (256 for small stack model).
23778 The following diagram shows what happens when calling printf to print an
23782 printf () --> ltoa () --> ultoa () --> divschar ()
23785 It is should be understood that stack is easily consumed when calling complicate
23787 Using command line arguments like -
23799 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
23801 Other ways to reduce stack usage may exist.
23807 The PIC16 Port currently does not pass SDCC's regression test
23808 \begin_inset LatexCommand \index{Regression test (PIC16)}
23813 \begin_inset LatexCommand \ref{sec:Quality-control}
23817 ) and thus the nightly regression tests for the PIC16 target are currently
23818 disabled for all hosts except for
23823 This means you can see the result of the PIC16 regression tests f.e.
23824 by checking the log files in
23825 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
23829 (pick the most up to date file there, scroll down, lend a hand).
23835 There are several approaches to debugging your code.
23836 This chapter is meant to show your options and to give detail on some of
23841 When writing your code:
23844 write your code with debugging in mind (avoid duplicating code, put conceptually
23845 similar variables into structs, use structured code, have strategic points
23846 within your code where all variables are consistent, ...)
23849 run a syntax-checking tool like splint
23850 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23855 \begin_inset LatexCommand \index{lint (syntax checking tool)}
23872 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23879 for the high level code use a C-compiler (like f.e.
23880 GCC) to compile run and debug the code on your host.
23894 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23898 ) on howto handle syntax extensions like __xdata, __at(), ...
23902 use another C-compiler to compile code for your target.
23903 Always an option but not recommended:) And not very likely to help you.
23904 If you seriously consider walking this path you should at least occasionally
23905 check portability of your code.
23906 Most commercial compiler vendors will offer an evaluation version so you
23907 can test compile your code or snippets of your code.
23910 Debugging on a simulator:
23913 there is a separate section about SDCDB (section
23914 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
23921 or (8051 specific) use a freeware/commercial simulator which interfaces
23923 \begin_inset LatexCommand \index{AOMF, AOMF51}
23928 \begin_inset LatexCommand \ref{OMF file}
23932 ) optionally generated by SDCC.
23935 Debugging On-target:
23938 use a MCU port pin to serially output debug data to the RS232 port of your
23940 You'll probably want some level shifting device typically involving a MAX232
23942 If the hardware serial port of the MCU is not available search for 'Software
23943 UART' in your favourite search machine.
23946 use an on-target monitor.
23947 In this context a monitor is a small program which usually accepts commands
23948 via a serial line and allows to set program counter, to single step through
23949 a program and read/write memory locations.
23950 For the 8051 good examples of monitors are paulmon and cmon51 (see section
23952 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
23959 toggle MCU port pins at strategic points within your code and use an oscilloscop
23963 digital oscilloscope
23966 \begin_inset LatexCommand \index{Oscilloscope}
23970 with deep trace memory is really helpful especially if you have to debug
23971 a realtime application.
23972 If you need to monitor more pins than your oscilloscope provides you can
23973 sometimes get away with a small R-2R network.
23974 On a single channel oscilloscope you could f.e.
23975 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
23977 \begin_inset Formula $\Omega$
23980 resistor and the other one by a 5\SpecialChar ~
23982 \begin_inset Formula $\Omega$
23985 resistor to the oscilloscope probe (check output drive capability of the
23986 pins you want to monitor).
23987 If you need to monitor many more pins a
24007 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24012 Usually very expensive.
24013 And very nice to have too.
24014 And usually locks you (for years...) to the devices the ICE can emulate.
24018 use a remote debugger.
24019 In most 8-bit systems the symbol information is not available on the target,
24020 and a complete debugger is too bulky for the target system.
24021 Therefore usually a debugger on the host system connects to an on-target
24022 debugging stub which accepts only primitive commands.
24025 Terms to enter into your favourite search engine could be 'remote debugging',
24026 'gdb stub' or 'inferior debugger'.
24030 use an on target hardware debugger.
24031 Some of the more modern MCUs include hardware support for setting break
24032 points and monitoring/changing variables by using dedicated hardware pins.
24033 This facility doesn't require additional code to run on the target and
24038 doesn't affect runtime behaviour until a breakpoint is hit.
24039 For the mcs51 most hardware debuggers use the AOMF
24040 \begin_inset LatexCommand \index{AOMF, AOMF51}
24045 \begin_inset LatexCommand \ref{OMF file}
24056 if you are not familiar with any of the following terms you're likely to
24057 run into problems rather sooner than later:
24074 As an embedded programmer you
24078 to know them so why not look them up
24082 you have problems?)
24085 tell someone else about your problem (actually this is a surprisingly effective
24086 means to hunt down the bug even if the listener is not familiar with your
24088 As 'failure to communicate' is probably one of the job-induced deformations
24089 of an embedded programmer this is highly encouraged.
24092 Debugging with SDCDB
24093 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24098 \begin_inset LatexCommand \index{SDCDB (debugger)}
24105 SDCC is distributed with a source level debugger
24106 \begin_inset LatexCommand \index{Debugger}
24111 The debugger uses a command line interface, the command repertoire of the
24112 debugger has been kept as close to gdb
24113 \begin_inset LatexCommand \index{gdb}
24117 (the GNU debugger) as possible.
24118 The configuration and build process is part of the standard compiler installati
24119 on, which also builds and installs the debugger in the target directory
24120 specified during configuration.
24121 The debugger allows you debug BOTH at the C source and at the ASM source
24125 Compiling for Debugging
24141 \begin_inset LatexCommand \index{-\/-debug}
24145 option must be specified for all files for which debug information is to
24147 The compiler generates a .adb file for each of these files.
24148 The linker creates the .cdb
24149 \begin_inset LatexCommand \index{<file>.cdb}
24154 \begin_inset LatexCommand \index{<file>.adb}
24158 files and the address information.
24159 This .cdb is used by the debugger.
24162 How the Debugger Works
24177 -debug option is specified the compiler generates extra symbol information
24178 some of which are put into the assembler source and some are put into the
24180 Then the linker creates the .cdb file from the individual .adb files with
24181 the address information for the symbols.
24182 The debugger reads the symbolic information generated by the compiler &
24183 the address information generated by the linker.
24184 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
24185 execution is controlled by the debugger.
24186 When a command is issued for the debugger, it translates it into appropriate
24187 commands for the simulator.
24188 (Currently SDCDM only connects to the simulator but
24193 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
24197 is an effort to connect directly to the hardware.)
24200 Starting the Debugger SDCDB
24203 The debugger can be started using the following command line.
24204 (Assume the file you are debugging has the file name foo).
24218 The debugger will look for the following files.
24221 foo.c - the source file.
24224 foo.cdb - the debugger symbol information file.
24227 foo.ihx - the Intel hex format
24228 \begin_inset LatexCommand \index{Intel hex format}
24235 SDCDB Command Line Options
24250 -directory=<source file directory> this option can used to specify the directory
24252 The debugger will look into the directory list specified for source, cdb
24254 The items in the directory list must be separated by ':', e.g.
24255 if the source files can be in the directories /home/src1 and /home/src2,
24268 -directory option should be -
24280 -directory=/home/src1:/home/src2.
24281 Note there can be no spaces in the option.
24285 -cd <directory> - change to the <directory>.
24288 -fullname - used by GUI front ends.
24291 -cpu <cpu-type> - this argument is passed to the simulator please see the
24292 simulator docs for details.
24295 -X <Clock frequency > this options is passed to the simulator please see
24296 the simulator docs for details.
24299 -s <serial port file> passed to simulator see the simulator docs for details.
24302 -S <serial in,out> passed to simulator see the simulator docs for details.
24305 -k <port number> passed to simulator see the simulator docs for details.
24308 SDCDB Debugger Commands
24311 As mentioned earlier the command interface for the debugger has been deliberatel
24312 y kept as close the GNU debugger gdb, as possible.
24313 This will help the integration with existing graphical user interfaces
24314 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
24315 If you use a graphical user interface for the debugger you can skip this
24318 \layout Subsubsection*
24319 break [line | file:line | function | file:function]
24322 Set breakpoint at specified line or function:
24331 sdcdb>break foo.c:100
24333 sdcdb>break funcfoo
24335 sdcdb>break foo.c:funcfoo
24337 \layout Subsubsection*
24338 clear [line | file:line | function | file:function ]
24341 Clear breakpoint at specified line or function:
24350 sdcdb>clear foo.c:100
24352 sdcdb>clear funcfoo
24354 sdcdb>clear foo.c:funcfoo
24356 \layout Subsubsection*
24360 Continue program being debugged, after breakpoint.
24362 \layout Subsubsection*
24366 Execute till the end of the current function.
24368 \layout Subsubsection*
24372 Delete breakpoint number 'n'.
24373 If used without any option clear ALL user defined break points.
24375 \layout Subsubsection*
24376 info [break | stack | frame | registers ]
24379 info break - list all breakpoints
24382 info stack - show the function call stack.
24385 info frame - show information about the current execution frame.
24388 info registers - show content of all registers.
24390 \layout Subsubsection*
24394 Step program until it reaches a different source line.
24395 Note: pressing <return> repeats the last command.
24397 \layout Subsubsection*
24401 Step program, proceeding through subroutine calls.
24403 \layout Subsubsection*
24407 Start debugged program.
24409 \layout Subsubsection*
24413 Print type information of the variable.
24415 \layout Subsubsection*
24419 print value of variable.
24421 \layout Subsubsection*
24425 load the given file name.
24426 Note this is an alternate method of loading file for debugging.
24428 \layout Subsubsection*
24432 print information about current frame.
24434 \layout Subsubsection*
24438 Toggle between C source & assembly source.
24440 \layout Subsubsection*
24441 ! simulator command
24444 Send the string following '!' to the simulator, the simulator response is
24446 Note the debugger does not interpret the command being sent to the simulator,
24447 so if a command like 'go' is sent the debugger can loose its execution
24448 context and may display incorrect values.
24450 \layout Subsubsection*
24456 My name is Bobby Brown"
24459 Interfacing SDCDB with DDD
24466 The screenshot was converted from png to eps with:
24467 \begin_inset Quotes sld
24470 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
24471 \begin_inset Quotes srd
24474 which produces a pretty compact eps file which is free from compression
24478 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
24479 as this broke the build system on Sourceforge (pdf-file was broken.
24480 pdflatex does not accept eps files).
24502 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
24508 shows a screenshot of a debugging session with DDD
24509 \begin_inset LatexCommand \index{DDD (debugger)}
24513 (Unix only) on a simulated 8032.
24514 The debugging session might not run as smoothly as the screenshot suggests.
24515 The debugger allows setting of breakpoints, displaying and changing variables,
24516 single stepping through C and assembler code.
24519 The source was compiled with
24544 -debug ddd_example.c
24557 and DDD was invoked with
24564 ddd -debugger "sdcdb -cpu 8032 ddd_example"
24571 Check that the double quotes or an apostroph within the command line survive
24572 the LyX tool chain.
24573 Previously the apostrophs got slanted in the PDF output so a cut and paste
24581 Interfacing SDCDB with XEmacs
24582 \begin_inset LatexCommand \index{XEmacs}
24587 \begin_inset LatexCommand \index{Emacs}
24594 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
24595 sdcdb.el and sdcdbsrc.el.
24596 These two files can be found in the $(prefix)/bin directory after the installat
24598 These files need to be loaded into XEmacs for the interface to work.
24599 This can be done at XEmacs startup time by inserting the following into
24600 your '.xemacs' file (which can be found in your HOME directory):
24606 (load-file sdcdbsrc.el)
24612 .xemacs is a lisp file so the () around the command is REQUIRED.
24613 The files can also be loaded dynamically while XEmacs is running, set the
24614 environment variable 'EMACSLOADPATH' to the installation bin directory
24615 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
24616 To start the interface enter the following command:
24630 You will prompted to enter the file name to be debugged.
24635 The command line options that are passed to the simulator directly are
24636 bound to default values in the file sdcdbsrc.el.
24637 The variables are listed below, these values maybe changed as required.
24640 sdcdbsrc-cpu-type '51
24643 sdcdbsrc-frequency '11059200
24646 sdcdbsrc-serial nil
24649 The following is a list of key mapping for the debugger interface.
24661 ;;key\SpecialChar ~
24675 binding\SpecialChar ~
24699 ;;---\SpecialChar ~
24713 -------\SpecialChar ~
24756 m-src\SpecialChar ~
24784 sdcdb-back-from-src\SpecialChar ~
24813 rom-src\SpecialChar ~
24823 SDCDB continue command
24841 sdcdb-step-from-src\SpecialChar ~
24870 hatis-c-sexp\SpecialChar ~
24880 SDCDB ptypecommand for data at
24947 sdcdbsrc-delete\SpecialChar ~
24962 B Delete all breakpoints if no arg
25011 given or delete arg (C-u arg x)
25030 -frame\SpecialChar ~
25045 SDCDB Display current frame if no arg,
25094 given or display frame arg
25162 sdcdbsrc-goto-sdcdb\SpecialChar ~
25172 Goto the SDCDB output buffer
25191 t-c-sexp\SpecialChar ~
25202 SDCDB print command for data at
25269 sdcdbsrc-goto-sdcdb\SpecialChar ~
25280 o the SDCDB output buffer
25298 sdcdbsrc-mode\SpecialChar ~
25314 Toggles Sdcdbsrc mode (turns it
25330 sdcdb-finish-from-src\SpecialChar ~
25338 SDCDB finish command
25372 Set break for line with point
25387 sdcdbsrc-mode\SpecialChar ~
25403 Toggle Sdcdbsrc mode
25419 dbsrc-srcmode\SpecialChar ~
25443 Here are a few guidelines that will help the compiler generate more efficient
25444 code, some of the tips are specific to this compiler others are generally
25445 good programming practice.
25448 Use the smallest data type to represent your data-value.
25449 If it is known in advance that the value is going to be less than 256 then
25450 use an 'unsigned char' instead of a 'short' or 'int'.
25451 Please note, that ANSI C requires both signed and unsigned chars to be
25452 promoted to 'signed int'
25453 \begin_inset LatexCommand \index{promotion to signed int}
25458 \begin_inset Marginal
25469 before doing any operation.
25471 \begin_inset LatexCommand \index{type promotion}
25476 \begin_inset LatexCommand \label{type promotion}
25480 can be omitted, if the result is the same.
25481 The effect of the promotion rules together with the sign-extension is often
25488 unsigned char uc = 0xfe;
25490 if (uc * uc < 0) /* this is true! */
25509 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
25519 (unsigned char) -12 / (signed char) -3 = ...
25522 No, the result is not 4:
25527 (int) (unsigned char) -12 / (int) (signed char) -3 =
25529 (int) (unsigned char)
25530 0xf4 / (int) (signed char) 0xfd =
25532 (int) 0x00f4 / (int) 0xfffd =
25537 (int) 244 / (int) -3 =
25539 (int) -81 = (int) 0xffaf;
25542 Don't complain, that gcc gives you a different result.
25543 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
25544 Therefore the results are different.
25547 \begin_inset Quotes sld
25551 \begin_inset Quotes srd
25559 If well-defined overflow characteristics are important and negative values
25560 are not, or if you want to steer clear of sign-extension problems when
25561 manipulating bits or bytes, use one of the corresponding unsigned types.
25562 (Beware when mixing signed and unsigned values in expressions, though.)
25565 character types (especially unsigned char) can be used as "tiny" integers,
25566 doing so is sometimes more trouble than it's worth, due to unpredictable
25567 sign extension and increased code size.
25571 Use unsigned when it is known in advance that the value is not going to
25573 This helps especially if you are doing division or multiplication, bit-shifting
25574 or are using an array index.
25577 NEVER jump into a LOOP.
25580 Declare the variables to be local
25581 \begin_inset LatexCommand \index{local variables}
25585 whenever possible, especially loop control variables (induction).
25588 Have a look at the assembly listing to get a
25589 \begin_inset Quotes sld
25593 \begin_inset Quotes srd
25596 for the code generation.
25599 Porting code from or to other compilers
25600 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
25607 check whether endianness of the compilers differs and adapt where needed.
25610 check the device specific header files
25611 \begin_inset LatexCommand \index{Header files}
25616 \begin_inset LatexCommand \index{Include files}
25620 for compiler specific syntax.
25621 Eventually include the file <compiler.h
25622 \begin_inset LatexCommand \index{compiler.h (include file)}
25627 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
25631 to allow using common header files.
25634 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
25641 check whether the startup code contains the correct initialization (watchdog,
25645 check whether the sizes of short, int, long match.
25648 check if some 16 or 32 bit hardware registers require a specific addressing
25649 order (least significant or most significant byte first) and adapt if needed
25658 relate to time and not to lower/upper memory location here, so this is
25663 the same as endianness).
25666 check whether the keyword
25670 is used where needed.
25671 The compilers might differ in their optimization characteristics (as different
25672 versions of the same compiler might also use more clever optimizations
25673 this is good idea anyway).
25675 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
25682 check that the compilers are not told to supress warnings.
25685 check and convert compiler specific extensions (interrupts, memory areas,
25689 check for differences in type promotion.
25690 Especially check for math operations on
25699 For the sake of C99 compatibility SDCC will probably promote these to
25703 more often than other compilers.
25704 Eventually insert explicit casts to
25713 Also check that the ~\SpecialChar ~
25715 \begin_inset LatexCommand \index{\~\/ Operator}
25722 \begin_inset LatexCommand \index{bit}
25728 variables, use the !\SpecialChar ~
25731 \begin_inset LatexCommand \ref{type promotion}
25736 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25743 check the assembly code generated for interrupt routines (f.e.
25744 for calls to possibly non-reentrant library functions).
25747 check whether timing loops result in proper timing (or preferably consider
25748 a rewrite of the code with timer based delays instead).
25751 check for differences in printf parameters (some compilers push (va_arg
25752 \begin_inset LatexCommand \index{vararg, va\_arg}
25756 ) char variables as
25760 others push them as
25766 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25773 check the resulting memory map
25774 \begin_inset LatexCommand \index{Memory map}
25779 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
25780 ly idata, pdata, xdata).
25781 Eventually check if unexpected library functions are included.
25785 \begin_inset LatexCommand \index{Tools}
25789 included in the distribution
25793 \begin_inset Tabular
25794 <lyxtabular version="3" rows="12" columns="3">
25796 <column alignment="left" valignment="top" leftline="true" width="0pt">
25797 <column alignment="left" valignment="top" leftline="true" width="0pt">
25798 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25799 <row topline="true" bottomline="true">
25800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25831 <row topline="true">
25832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25837 \begin_inset LatexCommand \index{uCsim}
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25849 Simulator for various architectures
25853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25862 <row topline="true">
25863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25876 \begin_inset LatexCommand \index{Header files}
25881 \begin_inset LatexCommand \index{Include files}
25889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25893 sdcc/support/scripts
25898 <row topline="true">
25899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25911 header file conversion
25915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25919 sdcc/support/scripts
25924 <row topline="true">
25925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25959 <row topline="true">
25960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25994 <row topline="true">
25995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26029 <row topline="true">
26030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26064 <row topline="true">
26065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26099 <row topline="true">
26100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26134 <row topline="true">
26135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26169 <row topline="true" bottomline="true">
26170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26183 \begin_inset LatexCommand \index{packihx (tool)}
26191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26219 \begin_inset LatexCommand \index{Documentation}
26223 included in the distribution
26227 \begin_inset Tabular
26228 <lyxtabular version="3" rows="10" columns="2">
26230 <column alignment="block" valignment="top" leftline="true" width="40col%">
26231 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
26232 <row topline="true" bottomline="true" endhead="true">
26233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26249 Filename / Where to get
26254 <row topline="true">
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26259 SDCC Compiler User Guide
26263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26267 You're reading it right now
26279 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
26288 <row topline="true">
26289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26313 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26322 <row topline="true">
26323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26328 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
26333 \begin_inset LatexCommand \index{Assembler documentation}
26340 \begin_inset LatexCommand \index{aslink}
26345 \begin_inset LatexCommand \index{Linker documentation}
26353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26357 sdcc/as/doc/asxhtm.html
26369 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
26378 <row topline="true">
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26383 SDCC regression test
26384 \begin_inset LatexCommand \index{Regression test}
26392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26396 sdcc/doc/test_suite_spec.pdf
26408 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26417 <row topline="true">
26418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26442 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
26451 <row topline="true">
26452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26456 Notes on debugging with SDCDB
26457 \begin_inset LatexCommand \index{SDCDB (debugger)}
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26469 sdcc/debugger/README
26481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
26490 <row topline="true">
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26496 \begin_inset LatexCommand \index{uCsim}
26500 Software simulator for microcontrollers
26504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26537 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
26546 <row topline="true">
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26551 Temporary notes on the pic16
26552 \begin_inset LatexCommand \index{PIC16}
26560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26564 sdcc/src/pic16/NOTES
26576 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
26585 <row topline="true" bottomline="true">
26586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26590 SDCC internal documentation (debugging file format)
26594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26627 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
26645 Related open source tools
26646 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
26651 \begin_inset LatexCommand \index{Related tools}
26659 \begin_inset Tabular
26660 <lyxtabular version="3" rows="14" columns="3">
26662 <column alignment="left" valignment="top" leftline="true" width="0pt">
26663 <column alignment="block" valignment="top" leftline="true" width="30line%">
26664 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26665 <row topline="true" bottomline="true">
26666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26697 <row topline="true">
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26703 \begin_inset LatexCommand \index{gpsim (pic simulator)}
26711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26723 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
26732 <row topline="true">
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26738 \begin_inset LatexCommand \index{gputils (pic tools)}
26746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26758 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26767 <row topline="true">
26768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26788 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
26797 <row topline="true">
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26810 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26819 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
26828 <row topline="true">
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26834 \begin_inset LatexCommand \index{indent (source formatting tool)}
26842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26846 Formats C source - Master of the white spaces
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26854 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
26863 <row topline="true">
26864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26869 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
26877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26881 Object file conversion, checksumming, ...
26885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26889 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
26898 <row topline="true">
26899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26904 \begin_inset LatexCommand \index{objdump (tool)}
26912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26916 Object file conversion, ...
26920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26924 Part of binutils (should be there anyway)
26929 <row topline="true">
26930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26942 8051 monitor (hex up-/download, single step, disassemble)
26946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26950 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
26959 <row topline="true">
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26965 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26977 Source code documentation system
26981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26985 \begin_inset LatexCommand \url{http://www.doxygen.org}
26994 <row topline="true">
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27007 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27015 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27024 <row topline="true">
27025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27037 8051 monitor (hex up-/download, single step, disassemble)
27041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27045 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27054 <row topline="true">
27055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27060 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27072 Statically checks c sources (see
27073 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27085 \begin_inset LatexCommand \url{http://www.splint.org}
27094 <row topline="true" bottomline="true">
27095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27100 \begin_inset LatexCommand \index{DDD (debugger)}
27108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27112 Debugger, serves nicely as GUI to SDCDB
27113 \begin_inset LatexCommand \index{SDCDB (debugger)}
27121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27125 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
27143 Related documentation / recommended reading
27147 \begin_inset Tabular
27148 <lyxtabular version="3" rows="7" columns="3">
27150 <column alignment="left" valignment="top" leftline="true" width="0pt">
27151 <column alignment="left" valignment="top" leftline="true" width="0">
27152 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27153 <row topline="true" bottomline="true">
27154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27185 <row topline="true">
27186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27208 \begin_inset LatexCommand \index{C Reference card}
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27220 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
27229 <row topline="true">
27230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27243 \begin_inset LatexCommand \index{C FAQ}
27251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27255 \begin_inset LatexCommand \url{http://www.c-faq.com}
27264 <row topline="true">
27265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27277 \begin_inset Quotes sld
27281 \begin_inset Quotes srd
27288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27294 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
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
27319 Extensions for Embedded C
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/docs/n1021.pdf}
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 Latest datasheet of target CPU
27359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27368 <row topline="true" bottomline="true">
27369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27381 Revision history of datasheet
27385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27403 Application notes specifically for SDCC
27406 SDCC makes no claims about the completeness of this list and about up-to-datenes
27407 s or correctness of the application notes
27408 \begin_inset LatexCommand \index{Application notes}
27418 \begin_inset Tabular
27419 <lyxtabular version="3" rows="7" columns="3">
27421 <column alignment="block" valignment="top" leftline="true" width="17col%">
27422 <column alignment="block" valignment="top" leftline="true" width="27col%">
27423 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
27424 <row topline="true" bottomline="true">
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27436 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27459 <row topline="true">
27460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27476 Using the SDCC Compiler for the DS80C400
27477 \begin_inset LatexCommand \index{DS80C400}
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27491 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
27500 <row topline="true">
27501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27511 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
27517 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
27518 \begin_inset LatexCommand \index{DS89C4x0}
27522 Family of Microcontrollers
27526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27532 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
27541 <row topline="true">
27542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27548 Silicon Laboratories / Cygnal
27552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27558 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
27559 \begin_inset LatexCommand \index{IDE}
27567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27573 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
27582 <row topline="true">
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27589 Ramtron / Goal Semiconductor
27593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27599 Interfacing SDCC to Syn and Textpad
27603 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27609 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27618 <row topline="true">
27619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27625 Ramtron / Goal Semiconductor
27629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27635 Installing and Configuring SDCC and Crimson Editor
27639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27645 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27654 <row topline="true" bottomline="true">
27655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27671 MSC12xx Programming with SDCC
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27681 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
27700 Some questions answered, some pointers given - it might be time to in turn
27708 can you solve your project with the selected microcontroller? Would you
27709 find out early or rather late that your target is too small/slow/whatever?
27710 Can you switch to a slightly better device if it doesn't fit?
27713 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
27714 and/or another programming language be more adequate? Would an operating
27715 system on the target device help?
27718 if you solved the problem, will the marketing department be happy?
27721 if the marketing department is happy, will customers be happy?
27724 if you're the project manager, marketing department and maybe even the customer
27725 in one person, have you tried to see the project from the outside?
27728 is the project done if you think it is done? Or is just that other interface/pro
27729 tocol/feature/configuration/option missing? How about website, manual(s),
27730 internationali(z|s)ation, packaging, labels, 2nd source for components,
27731 electromagnetic compatability/interference, documentation for production,
27732 production test software, update mechanism, patent issues?
27735 is your project adequately positioned in that magic triangle: fame, fortune,
27739 Maybe not all answers to these questions are known and some answers may
27744 , nevertheless knowing these questions may help you to avoid burnout
27749 burnout is bad for electronic devices, programmers and motorcycle tyres
27754 Chances are you didn't want to hear some of them...
27758 \begin_inset LatexCommand \index{Support}
27765 SDCC has grown to be a large project.
27766 The compiler alone (without the preprocessor, assembler and linker) is
27767 well over 150,000 lines of code (blank stripped).
27768 The open source nature of this project is a key to its continued growth
27770 You gain the benefit and support of many active software developers and
27772 Is SDCC perfect? No, that's why we need your help.
27773 The developers take pride in fixing reported bugs.
27774 You can help by reporting the bugs and helping other SDCC users.
27775 There are lots of ways to contribute, and we encourage you to take part
27776 in making SDCC a great software package.
27780 The SDCC project is hosted on the SDCC sourceforge site at
27781 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
27786 You'll find the complete set of mailing lists
27787 \begin_inset LatexCommand \index{Mailing list(s)}
27791 , forums, bug reporting system, patch submission
27792 \begin_inset LatexCommand \index{Patch submission}
27797 \begin_inset LatexCommand \index{download}
27801 area and Subversion code repository
27802 \begin_inset LatexCommand \index{Subversion code repository}
27810 \begin_inset LatexCommand \index{Bug reporting}
27815 \begin_inset LatexCommand \index{Reporting bugs}
27822 The recommended way of reporting bugs is using the infrastructure of the
27824 You can follow the status of bug reports there and have an overview about
27828 Bug reports are automatically forwarded to the developer mailing list and
27829 will be fixed ASAP.
27830 When reporting a bug, it is very useful to include a small test program
27831 (the smaller the better) which reproduces the problem.
27832 If you can isolate the problem by looking at the generated assembly code,
27833 this can be very helpful.
27834 Compiling your program with the -
27847 \begin_inset LatexCommand \index{-\/-dumpall}
27851 option can sometimes be useful in locating optimization problems.
27852 When reporting a bug please make sure you:
27855 Attach the code you are compiling with SDCC.
27859 Specify the exact command you use to run SDCC, or attach your Makefile.
27863 Specify the SDCC version (type "
27869 "), your platform, and operating system.
27873 Provide an exact copy of any error message or incorrect output.
27877 Put something meaningful in the subject of your message.
27880 Please attempt to include these 5 important parts, as applicable, in all
27881 requests for support or when reporting any problems or bugs with SDCC.
27882 Though this will make your message lengthy, it will greatly improve your
27883 chance that SDCC users and developers will be able to help you.
27884 Some SDCC developers are frustrated by bug reports without code provided
27885 that they can use to reproduce and ultimately fix the problem, so please
27886 be sure to provide sample code if you are reporting a bug!
27889 Please have a short check that you are using a recent version of SDCC and
27890 the bug is not yet known.
27891 This is the link for reporting bugs:
27892 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
27897 With SDCC on average having more than 200 downloads
27898 \begin_inset LatexCommand \index{download}
27902 on sourceforge per day
27907 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
27908 between 2002 and 2005.
27909 This does not include other methods of distribution.
27913 there must be some users.
27914 So it's not exactly easy to find a new bug.
27915 If you find one we need it:
27917 reporting bugs is good
27922 Requesting Features
27923 \begin_inset LatexCommand \label{sub:Requesting-Features}
27928 \begin_inset LatexCommand \index{Feature request}
27933 \begin_inset LatexCommand \index{Requesting features}
27940 Like bug reports feature requests are forwarded to the developer mailing
27942 This is the link for requesting features:
27943 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
27953 Like bug reports contributed patches are forwarded to the developer mailing
27955 This is the link for submitting patches
27956 \begin_inset LatexCommand \index{Patch submission}
27961 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
27968 You need to specify some parameters to the
27972 command for the patches to be useful.
27973 If you modified more than one file a patch created f.e.
27978 \begin_inset Quotes sld
27981 diff -Naur unmodified_directory modified_directory >my_changes.patch
27982 \begin_inset Quotes srd
27988 will be fine, otherwise
27992 \begin_inset Quotes sld
27995 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
27996 \begin_inset Quotes srd
28009 These links should take you directly to the
28010 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28019 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28020 automated messages (mid 2003)
28025 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28030 \begin_inset LatexCommand \index{Mailing list(s)}
28034 and forums are archived and searchable so if you are lucky someone already
28035 had a similar problem.
28036 While mails to the lists themselves are delivered promptly their web front
28037 end on sourceforge sometimes shows a severe time lag (up to several weeks),
28038 if you're seriously using SDCC please consider subscribing to the lists.
28044 You can follow the status of the Subversion version
28045 \begin_inset LatexCommand \index{version}
28049 of SDCC by watching the Changelog
28050 \begin_inset LatexCommand \index{Changelog}
28054 in the Subversion repository
28057 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28064 Subversion Source Code Repository
28073 or the filenames of the snapshot versions of SDCC include date and its
28075 \begin_inset LatexCommand \index{Subversion code repository}
28080 Subversion allows to download the source of recent or previous versions
28082 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28086 (by number or by date).
28087 An on-line source code browser and detailled instructions are also available
28089 SDCC versions starting from 1999 up to now are available (currently the
28090 versions prior to the conversion from cvs
28091 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28095 to Subversion (April 2006) are either by accessible by Subversion or by
28100 \begin_inset LatexCommand \index{Release policy}
28107 Historically there often were long delays between official releases and
28108 the sourceforge download area tends to get not updated at all.
28109 Excuses in the past might have referred to problems with live range analysis,
28110 but as this was fixed a while ago, the current problem is that another
28111 excuse has to be found.
28112 Kidding aside, we have to get better there! On the other hand there are
28113 daily snapshots available at
28114 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
28118 , and you can always build the very last version (hopefully with many bugs
28119 fixed, and features added) from the source code available at
28120 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
28126 \begin_inset LatexCommand \index{wiki}
28131 \begin_inset LatexCommand \index{Release wiki}
28136 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
28140 also holds some information about past and future releases.
28144 \begin_inset LatexCommand \index{Examples}
28151 You'll find some small examples in the directory
28153 sdcc/device/examples/.
28156 More examples and libraries are available at
28158 The SDCC Open Knowledge Resource
28159 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
28166 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
28177 I did insert a reference to Paul's web site here although it seems rather
28178 dedicated to a specific 8032 board (I think it's okay because it f.e.
28179 shows LCD/Harddisc interface and has a free 8051 monitor.
28180 Independent 8032 board vendors face hard competition of heavily subsidized
28181 development boards anyway).
28184 Maybe we should include some links to real world applications.
28185 Preferably pointer to pointers (one for each architecture) so this stays
28194 \begin_inset LatexCommand \label{sec:Quality-control}
28199 \begin_inset LatexCommand \index{Quality control}
28206 The compiler is passed through nightly compile and build checks.
28212 \begin_inset LatexCommand \index{Regression test}
28216 check that SDCC itself compiles flawlessly on several host platforms (i386,
28217 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
28218 the quality of the code generated by SDCC by running the code for several
28219 target platforms through simulators.
28220 The regression test suite comprises more than 100 files which expand to
28221 more than 500 test cases which include more than 4500 tests.
28222 The results of these tests are published daily on SDCC's snapshot page
28223 (click on the red or green symbols on the right side of
28224 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
28231 There is a separate document
28234 \begin_inset LatexCommand \index{Test suite}
28241 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28245 about the regression test suite.
28248 You'll find the test code in the directory
28250 sdcc/support/regression
28253 You can run these tests manually by running
28257 in this directory (or f.e.
28262 \begin_inset Quotes sld
28266 \begin_inset Quotes srd
28272 if you don't want to run the complete tests).
28273 The test code might also be interesting if you want to look for examples
28274 \begin_inset LatexCommand \index{Examples}
28278 checking corner cases of SDCC or if you plan to submit patches
28279 \begin_inset LatexCommand \index{Patch submission}
28286 The 14bit pic port uses a different set of regression tests
28287 \begin_inset LatexCommand \index{Regression test (PIC14)}
28291 , you'll find them in the directory
28293 sdcc/src/regression
28298 Use of SDCC in Education
28310 the phrase "use in education" might evoke the association "
28314 fit for use in education".
28315 This connotation is not intended but nevertheless risked as the licensing
28316 of SDCC makes it difficult to offer educational discounts
28321 If your rationales are to:
28324 give students a chance to understand the
28328 steps of code generation
28331 have a curriculum that can be extended for years.
28332 Then you could use an fpga board as target and your curriculum will seamlessly
28333 extend from logic synthesis (
28334 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
28339 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
28343 ), over assembly programming, to C to FPGA compilers (
28344 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
28351 be able to insert excursions about skills like using a revision control
28352 system, submitting/applying patches, using a type-setting (as opposed to
28353 word-processing) engine LyX/LaTeX, using
28354 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
28359 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
28363 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
28364 Source Software, CPU simulation, compiler regression tests
28365 \begin_inset LatexCommand \index{Regression test}
28372 And if there should be a shortage of ideas then you can always point students
28373 to the ever-growing feature request list
28374 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28381 not tie students to a specific host platform and instead allow them to use
28386 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
28388 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
28395 not encourage students to use illegal copies of educational software
28398 be immune to licensing/availability/price changes of the chosen tool chain
28401 be able to change to a new target platform without having to adopt a new
28405 have complete control over and insight into the tool chain
28408 make your students aware about the pros and cons of open source software
28412 give back to the public as you are probably at least partially publically
28416 give students a chance to publically prove their skills and to possibly
28417 see a world wide impact
28420 then SDCC is probably among the first choices.
28422 Well, probably SDCC might be the only choice.
28426 SDCC Technical Data
28430 \begin_inset LatexCommand \index{Optimizations}
28437 SDCC performs a host of standard optimizations in addition to some MCU specific
28442 Sub-expression Elimination
28443 \begin_inset LatexCommand \index{Subexpression elimination}
28450 The compiler does local and
28476 will be translated to
28488 Some subexpressions are not as obvious as the above example, e.g.:
28498 In this case the address arithmetic a->b[i] will be computed only once;
28499 the equivalent code in C would be.
28511 The compiler will try to keep these temporary variables in registers.
28514 Dead-Code Elimination
28515 \begin_inset LatexCommand \index{Dead-code elimination}
28536 i = 1; \SpecialChar ~
28545 global = 1;\SpecialChar ~
28559 global = 3;\SpecialChar ~
28584 \begin_inset LatexCommand \index{Copy propagation}
28640 Note: the dead stores created by this copy propagation will be eliminated
28641 by dead-code elimination.
28645 \begin_inset LatexCommand \index{Loop optimization}
28650 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
28657 Two types of loop optimizations are done by SDCC
28665 of loop induction variables.
28666 In addition to the strength reduction the optimizer marks the induction
28667 variables and the register allocator tries to keep the induction variables
28668 in registers for the duration of the loop.
28669 Because of this preference of the register allocator
28670 \begin_inset LatexCommand \index{Register allocation}
28674 , loop induction optimization causes an increase in register pressure, which
28675 may cause unwanted spilling of other temporary variables into the stack
28676 \begin_inset LatexCommand \index{stack}
28681 The compiler will generate a warning message when it is forced to allocate
28682 extra space either on the stack or data space.
28683 If this extra space allocation is undesirable then induction optimization
28684 can be eliminated either for the entire source file (with -
28696 -noinduction option) or for a given function only using #pragma\SpecialChar ~
28698 \begin_inset LatexCommand \index{\#pragma noinduction}
28711 for (i = 0 ; i < 100 ; i ++)
28727 for (i = 0; i < 100; i++)
28736 As mentioned previously some loop invariants are not as apparent, all static
28737 address computations are also moved out of the loop.
28742 \begin_inset LatexCommand \index{Strength reduction}
28746 , this optimization substitutes an expression by a cheaper expression:
28751 for (i=0;i < 100; i++)
28769 for (i=0;i< 100;i++) {
28775 ar[itemp1] = itemp2;
28793 The more expensive multiplication
28794 \begin_inset LatexCommand \index{Multiplication}
28798 is changed to a less expensive addition.
28802 \begin_inset LatexCommand \index{Loop reversing}
28809 This optimization is done to reduce the overhead of checking loop boundaries
28810 for every iteration.
28811 Some simple loops can be reversed and implemented using a
28812 \begin_inset Quotes eld
28815 decrement and jump if not zero
28816 \begin_inset Quotes erd
28820 SDCC checks for the following criterion to determine if a loop is reversible
28821 (note: more sophisticated compilers use data-dependency analysis to make
28822 this determination, SDCC uses a more simple minded analysis).
28825 The 'for' loop is of the form
28831 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
28841 The <for body> does not contain
28842 \begin_inset Quotes eld
28846 \begin_inset Quotes erd
28850 \begin_inset Quotes erd
28856 All goto's are contained within the loop.
28859 No function calls within the loop.
28862 The loop control variable <sym> is not assigned any value within the loop
28865 The loop control variable does NOT participate in any arithmetic operation
28869 There are NO switch statements in the loop.
28872 Algebraic Simplifications
28875 SDCC does numerous algebraic simplifications, the following is a small sub-set
28876 of these optimizations.
28881 i = j + 0;\SpecialChar ~
28885 /* changed to: */\SpecialChar ~
28891 i /= 2;\SpecialChar ~
28898 /* changed to: */\SpecialChar ~
28905 = j - j;\SpecialChar ~
28909 /* changed to: */\SpecialChar ~
28915 i = j / 1;\SpecialChar ~
28919 /* changed to: */\SpecialChar ~
28926 Note the subexpressions
28927 \begin_inset LatexCommand \index{Subexpression}
28931 given above are generally introduced by macro expansions or as a result
28932 of copy/constant propagation.
28935 'switch' Statements
28936 \begin_inset LatexCommand \label{sub:'switch'-Statements}
28941 \begin_inset LatexCommand \index{switch statement}
28948 SDCC can optimize switch statements to jump tables
28949 \begin_inset LatexCommand \index{jump tables}
28954 It makes the decision based on an estimate of the generated code size.
28955 SDCC is quite liberal in the requirements for jump table generation:
28958 The labels need not be in order, and the starting number need not be one
28959 or zero, the case labels are in numerical sequence or not too many case
28960 labels are missing.
28966 switch(i) {\SpecialChar ~
28997 case 4: ...\SpecialChar ~
29029 case 5: ...\SpecialChar ~
29061 case 3: ...\SpecialChar ~
29092 case 6: ...\SpecialChar ~
29124 case 7: ...\SpecialChar ~
29156 case 8: ...\SpecialChar ~
29188 case 9: ...\SpecialChar ~
29220 case 10: ...\SpecialChar ~
29251 case 11: ...\SpecialChar ~
29318 Both the above switch statements will be implemented using a jump-table.
29319 The example to the right side is slightly more efficient as the check for
29320 the lower boundary of the jump-table is not needed.
29324 The number of case labels is not larger than supported by the target architectur
29328 If the case labels are not in numerical sequence ('gaps' between cases)
29329 SDCC checks whether a jump table with additionally inserted dummy cases
29330 is still attractive.
29334 If the starting number is not zero and a check for the lower boundary of
29335 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
29340 Switch statements which have large gaps in the numeric sequence or those
29341 that have too many case labels can be split into more than one switch statement
29342 for efficient code generation, e.g.:
29422 If the above switch statement is broken down into two switch statements
29512 then both the switch statements will be implemented using jump-tables whereas
29513 the unmodified switch statement will not be.
29520 There might be reasons which SDCC cannot know about to either favour or
29521 not favour jump tables.
29522 If the target system has to be as quick for the last switch case as for
29523 the first (pro jump table), or if the switch argument is known to be zero
29524 in the majority of the cases (contra jump table).
29531 The pragma nojtbound
29532 \begin_inset LatexCommand \index{\#pragma nojtbound}
29536 can be used to turn off checking the
29549 It has no effect if a default label is supplied.
29550 Use of this pragma is dangerous: if the switch
29551 \begin_inset LatexCommand \index{switch statement}
29555 argument is not matched by a case statement the processor will happily
29559 Bit-shifting Operations
29560 \begin_inset LatexCommand \index{Bit shifting}
29567 Bit shifting is one of the most frequently used operation in embedded programmin
29569 SDCC tries to implement bit-shift operations in the most efficient way
29585 generates the following code:
29602 In general SDCC will never setup a loop if the shift count is known.
29645 \begin_inset LatexCommand \index{Bit rotation}
29652 A special case of the bit-shift operation is bit rotation
29653 \begin_inset LatexCommand \index{rotating bits}
29657 , SDCC recognizes the following expression to be a left bit-rotation:
29667 char i;\SpecialChar ~
29678 /* unsigned is needed for rotation */
29683 i = ((i << 1) | (i >> 7));
29692 will generate the following code:
29711 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
29712 ns of this case will also be recognized as bit-rotation, i.e.:
29717 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
29720 Nibble and Byte Swapping
29723 Other special cases of the bit-shift operations are nibble or byte swapping
29724 \begin_inset LatexCommand \index{swapping nibbles/bytes}
29728 , SDCC recognizes the following expressions:
29751 i = ((i << 4) | (i >> 4));
29757 j = ((j << 8) | (j >> 8));
29760 and generates a swap instruction for the nibble swapping
29761 \begin_inset LatexCommand \index{Nibble swapping}
29765 or move instructions for the byte swapping
29766 \begin_inset LatexCommand \index{Byte swapping}
29772 \begin_inset Quotes sld
29776 \begin_inset Quotes srd
29779 example can be used to convert from little to big-endian or vice versa.
29780 If you want to change the endianness of a
29784 integer you have to cast to
29791 Note that SDCC stores numbers in little-endian
29796 Usually 8-bit processors don't care much about endianness.
29797 This is not the case for the standard 8051 which only has an instruction
29803 \begin_inset LatexCommand \index{DPTR}
29811 so little-endian is the more efficient byte order.
29816 \begin_inset LatexCommand \index{little-endian}
29821 \begin_inset LatexCommand \index{Endianness}
29826 lowest order first).
29830 \begin_inset LatexCommand \index{Highest Order Bit}
29835 \begin_inset LatexCommand \index{Any Order Bit}
29842 It is frequently required to obtain the highest order bit of an integral
29843 type (long, int, short or char types).
29844 Also obtaining any other order bit is not uncommon.
29845 SDCC recognizes the following expressions to yield the highest order bit
29846 and generates optimized code for it, e.g.:
29859 unsigned char hob1, aob1;
29863 bit hob2, hob3, aob2,
29873 hob1 = (gint >> 15) & 1;
29877 hob2 = (gint >> 15) & 1;
29881 hob3 = gint & 0x8000;
29886 aob1 = (gint >> 9) & 1;
29890 aob2 = (gint >> 8) & 1;
29894 aob3 = gint & 0x0800;
29904 will generate the following code:
29937 000A E5*01\SpecialChar ~
29964 000C 23\SpecialChar ~
29995 000D 54 01\SpecialChar ~
30023 000F F5*02\SpecialChar ~
30078 0011 E5*01\SpecialChar ~
30106 0013 33\SpecialChar ~
30136 0014 92*00\SpecialChar ~
30192 0016 E5*01\SpecialChar ~
30219 0018 33\SpecialChar ~
30249 0019 92*01\SpecialChar ~
30305 001B E5*01\SpecialChar ~
30364 001E 54 01\SpecialChar ~
30391 0020 F5*03\SpecialChar ~
30447 0022 E5*01\SpecialChar ~
30474 0024 13\SpecialChar ~
30504 0025 92*02\SpecialChar ~
30560 0027 E5*01\SpecialChar ~
30588 A2 E3\SpecialChar ~
30615 002B 92*03\SpecialChar ~
30643 Other variations of these cases however will
30648 They are standard C expressions, so I heartily recommend these be the only
30649 way to get the highest order bit, (it is portable).
30650 Of course it will be recognized even if it is embedded in other expressions,
30656 xyz = gint + ((gint >> 15) & 1);
30659 will still be recognized.
30663 \begin_inset LatexCommand \index{Higher Order Byte}
30667 / Higher Order Word
30668 \begin_inset LatexCommand \index{Higher Order Word}
30675 It is also frequently required to obtain a higher order byte or word of
30676 a larger integral type (long, int or short types).
30677 SDCC recognizes the following expressions to yield the higher order byte
30678 or word and generates optimized code for it, e.g.:
30685 unsigned long int glong;
30693 unsigned char hob1,
30698 unsigned int how1, how2;
30707 hob1 = (gint >> 8) & 0xFF;
30711 hob2 = glong >> 24;
30715 how1 = (glong >> 16) & 0xFFFF;
30730 will generate the following code:
30763 0037 85*01*06\SpecialChar ~
30785 _foo_hob1_1_1,(_gint + 1)
30816 003A 85*05*07\SpecialChar ~
30838 _foo_hob2_1_1,(_glong + 3)
30868 003D 85*04*08\SpecialChar ~
30891 _foo_how1_1_1,(_glong + 2)
30893 0040 85*05*09\SpecialChar ~
30918 0043 85*03*0A\SpecialChar ~
30940 _foo_how2_1_1,(_glong + 1)
30942 0046 85*04*0B\SpecialChar ~
30965 (_foo_how2_1_1 + 1),(_glong + 2)
30968 Again, variations of these cases may
30973 They are standard C expressions, so I heartily recommend these be the only
30974 way to get the higher order byte/word, (it is portable).
30975 Of course it will be recognized even if it is embedded in other expressions,
30981 xyz = gint + ((gint >> 8) & 0xFF);
30984 will still be recognized.
30988 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
30993 \begin_inset LatexCommand \index{Peephole optimizer}
31000 The compiler uses a rule based, pattern matching and re-writing mechanism
31001 for peep-hole optimization.
31006 a peep-hole optimizer by Christopher W.
31007 Fraser (cwfraser\SpecialChar ~
31010 A default set of rules are compiled into the compiler, additional rules
31011 may be added with the
31026 \begin_inset LatexCommand \index{-\/-peep-file}
31033 The rule language is best illustrated with examples.
31057 The above rule will change the following assembly
31058 \begin_inset LatexCommand \index{Assembler routines}
31080 Note: All occurrences of a
31084 (pattern variable) must denote the same string.
31085 With the above rule, the assembly sequence:
31095 will remain unmodified.
31099 Other special case optimizations may be added by the
31118 some variants of the 8051 MCU
31119 \begin_inset LatexCommand \index{MCS51 variants}
31132 The following two rules will change all
31151 replace { lcall %1 } by { acall %1 }
31153 replace { ljmp %1 } by { ajmp %1 }
31158 inline-assembler code
31160 is also passed through the peep hole optimizer, thus the peephole optimizer
31161 can also be used as an assembly level macro expander.
31162 The rules themselves are MCU dependent whereas the rule language infra-structur
31163 e is MCU independent.
31164 Peephole optimization rules for other MCU can be easily programmed using
31169 The syntax for a rule is as follows:
31174 rule := replace [ restart ] '{' <assembly sequence> '
31212 <assembly sequence> '
31230 '}' [if <functionName> ] '
31235 <assembly sequence> := assembly instruction (each instruction including
31236 labels must be on a separate line).
31240 The optimizer will apply to the rules
31241 one by one from the top in the sequence of their appearance, it will terminate
31242 when all rules are exhausted.
31243 If the 'restart' option is specified, then the optimizer will start matching
31244 the rules again from the top, this option for a rule is expensive (performance)
31245 , it is intended to be used in situations where a transformation will trigger
31246 the same rule again.
31247 An example of this (not a good one, it has side effects) is the following
31270 Note that the replace pattern cannot be a blank, but can be a comment line.
31271 Without the 'restart' option only the innermost 'pop' 'push' pair would
31272 be eliminated, i.e.:
31302 the restart option the rule will be applied again to the resulting code
31303 and then all the pop-push pairs will be eliminated to yield:
31313 A conditional function can be attached to a rule.
31314 Attaching rules are somewhat more involved, let me illustrate this with
31341 The optimizer does a look-up of a function name table defined in function
31346 in the source file SDCCpeeph.c, with the name
31351 If it finds a corresponding entry the function is called.
31352 Note there can be no parameters specified for these functions, in this
31357 is crucial, since the function
31361 expects to find the label in that particular variable (the hash table containin
31362 g the variable bindings is passed as a parameter).
31363 If you want to code more such functions, take a close look at the function
31364 labelInRange and the calling mechanism in source file SDCCpeeph.c.
31365 Currently implemented are
31367 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
31368 24bitMode, portIsDS390, 24bitModeAndPortDS390
31377 I know this whole thing is a little kludgey, but maybe some day we will
31378 have some better means.
31379 If you are looking at this file, you will see the default rules that are
31380 compiled into the compiler, you can add your own rules in the default set
31381 there if you get tired of specifying the -
31397 \begin_inset LatexCommand \index{ANSI-compliance}
31402 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
31409 The latest publically available version of the standard
31411 ISO/IEC 9899 - Programming languages - C
31413 should be available at:
31414 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31423 Deviations from the compliance:
31426 functions are not reentrant
31427 \begin_inset LatexCommand \index{reentrant}
31431 unless explicitly declared as such or the
31446 \begin_inset LatexCommand \index{-\/-stack-auto}
31452 command line option is specified.
31456 \begin_inset LatexCommand \index{struct}
31461 \begin_inset LatexCommand \index{union}
31465 cannot be assigned values directly, cannot be passed as function parameters
31466 or assigned to each other and cannot be a return value
31467 \begin_inset LatexCommand \index{return value}
31471 from a function, e.g.:
31497 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
31516 s parms) /* invalid in SDCC although allowed in ANSI */
31538 return rets; /* is invalid in SDCC although allowed in ANSI */
31544 initialization of structure arrays must be fully braced.
31550 struct s { char x } a[] = {1, 2};\SpecialChar ~
31555 /* invalid in SDCC */
31558 } a[] = {{1}, {2}}; /* OK */
31563 \begin_inset LatexCommand \index{long long (not supported)}
31568 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
31576 \begin_inset LatexCommand \index{double (not supported)}
31580 ' precision floating point
31581 \begin_inset LatexCommand \index{Floating point support}
31589 \begin_inset LatexCommand \index{K\&R style}
31593 function declarations are NOT allowed.
31599 foo(i,j) /* this old style of function declarations */
31601 int i,j; /* are valid
31602 in ANSI but not valid in SDCC */
31617 Most enhancements in C99 are not supported, f.e.:
31625 \begin_inset LatexCommand \index{inline (not supported)}
31631 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
31637 can be used as a work around */
31645 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
31649 Certain words that are valid identifiers in the standard may be reserved
31650 words in SDCC unless the
31665 \begin_inset LatexCommand \index{-\/-std-c89}
31682 \begin_inset LatexCommand \index{-\/-std-c99}
31688 command line options are used.
31689 These may include (depending on the selected processor): 'at', 'banked',
31690 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
31691 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
31692 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
31694 Compliant equivalents of these keywords are always available in a form
31695 that begin with two underscores
31696 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
31701 '__data' instead of 'data'.
31704 Cyclomatic Complexity
31705 \begin_inset LatexCommand \index{Cyclomatic complexity}
31712 Cyclomatic complexity of a function is defined as the number of independent
31713 paths the program can take during execution of the function.
31714 This is an important number since it defines the number test cases you
31715 have to generate to validate the function.
31716 The accepted industry standard for complexity number is 10, if the cyclomatic
31717 complexity reported by SDCC exceeds 10 you should think about simplification
31718 of the function logic.
31719 Note that the complexity level is not related to the number of lines of
31720 code in a function.
31721 Large functions can have low complexity, and small functions can have large
31727 SDCC uses the following formula to compute the complexity:
31732 complexity = (number of edges in control flow graph) - (number of nodes
31733 in control flow graph) + 2;
31737 Having said that the industry standard is 10,
31738 you should be aware that in some cases it be may unavoidable to have a
31739 complexity level of less than 10.
31740 For example if you have switch statement with more than 10 case labels,
31741 each case label adds one to the complexity level.
31742 The complexity level is by no means an absolute measure of the algorithmic
31743 complexity of the function, it does however provide a good starting point
31744 for which functions you might look at for further optimization.
31747 Retargetting for other Processors
31750 The issues for retargetting the compiler are far too numerous to be covered
31752 What follows is a brief description of each of the seven phases of the
31753 compiler and its MCU dependency.
31756 Parsing the source and building the annotated parse tree.
31757 This phase is largely MCU independent (except for the language extensions).
31758 Syntax & semantic checks are also done in this phase, along with some initial
31759 optimizations like back patching labels and the pattern matching optimizations
31760 like bit-rotation etc.
31763 The second phase involves generating an intermediate code which can be easy
31764 manipulated during the later phases.
31765 This phase is entirely MCU independent.
31766 The intermediate code generation assumes the target machine has unlimited
31767 number of registers, and designates them with the name iTemp.
31768 The compiler can be made to dump a human readable form of the code generated
31784 This phase does the bulk of the standard optimizations and is also MCU independe
31786 This phase can be broken down into several sub-phases:
31790 Break down intermediate
31791 code (iCode) into basic blocks.
31793 Do control flow & data flow analysis on the
31796 Do local common subexpression elimination, then global subexpressio
31799 Dead code elimination
31803 If loop optimizations
31804 caused any changes then do 'global subexpression elimination' and 'dead
31805 code elimination' again.
31808 This phase determines the live-ranges; by live range I mean those iTemp
31809 variables defined by the compiler that still survive after all the optimization
31811 Live range analysis
31812 \begin_inset LatexCommand \index{Live range analysis}
31816 is essential for register allocation, since these computation determines
31817 which of these iTemps will be assigned to registers, and for how long.
31820 Phase five is register allocation.
31821 There are two parts to this process.
31825 The first part I call 'register packing'
31826 (for lack of a better term).
31827 In this case several MCU specific expression folding is done to reduce
31832 The second part is more MCU independent and deals with
31833 allocating registers to the remaining live ranges.
31834 A lot of MCU specific code does creep into this phase because of the limited
31835 number of index registers available in the 8051.
31838 The Code generation phase is (unhappily), entirely MCU dependent and very
31839 little (if any at all) of this code can be reused for other MCU.
31840 However the scheme for allocating a homogenized assembler operand for each
31841 iCode operand may be reused.
31844 As mentioned in the optimization section the peep-hole optimizer is rule
31845 based system, which can reprogrammed for other MCUs.
31848 More information is available in a wiki
31849 \begin_inset LatexCommand \index{wiki}
31854 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
31858 ) and in the thread
31859 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
31867 \begin_inset LatexCommand \index{Compiler internals}
31874 The anatomy of the compiler
31875 \begin_inset LatexCommand \label{sub:The-anatomy-of}
31884 This is an excerpt from an article published in Circuit Cellar Magazine
31890 It's a little outdated (the compiler is much more efficient now and user/develo
31891 per friendly), but pretty well exposes the guts of it all.
31897 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
31898 It is fairly easy to retarget for other 8-bit MCU.
31899 Here we take a look at some of the internals of the compiler.
31904 \begin_inset LatexCommand \index{Parsing}
31911 Parsing the input source file and creating an AST (Annotated Syntax Tree
31912 \begin_inset LatexCommand \index{Annotated syntax tree}
31917 This phase also involves propagating types (annotating each node of the
31918 parse tree with type information) and semantic analysis.
31919 There are some MCU specific parsing rules.
31920 For example the storage classes, the extended storage classes are MCU specific
31921 while there may be a xdata storage class for 8051 there is no such storage
31922 class for z80 or Atmel AVR.
31923 SDCC allows MCU specific storage class extensions, i.e.
31924 xdata will be treated as a storage class specifier when parsing 8051 C
31925 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
31930 \begin_inset LatexCommand \index{iCode}
31937 Intermediate code generation.
31938 In this phase the AST is broken down into three-operand form (iCode).
31939 These three operand forms are represented as doubly linked lists.
31940 ICode is the term given to the intermediate form generated by the compiler.
31941 ICode example section shows some examples of iCode generated for some simple
31942 C source functions.
31946 \begin_inset LatexCommand \index{Optimizations}
31953 Bulk of the target independent optimizations is performed in this phase.
31954 The optimizations include constant propagation, common sub-expression eliminati
31955 on, loop invariant code movement, strength reduction of loop induction variables
31956 and dead-code elimination.
31959 Live range analysis
31960 \begin_inset LatexCommand \index{Live range analysis}
31967 During intermediate code generation phase, the compiler assumes the target
31968 machine has infinite number of registers and generates a lot of temporary
31970 The live range computation determines the lifetime of each of these compiler-ge
31971 nerated temporaries.
31972 A picture speaks a thousand words.
31973 ICode example sections show the live range annotations for each of the
31975 It is important to note here, each iCode is assigned a number in the order
31976 of its execution in the function.
31977 The live ranges are computed in terms of these numbers.
31978 The from number is the number of the iCode which first defines the operand
31979 and the to number signifies the iCode which uses this operand last.
31982 Register Allocation
31983 \begin_inset LatexCommand \index{Register allocation}
31990 The register allocation determines the type and number of registers needed
31992 In most MCUs only a few registers can be used for indirect addressing.
31993 In case of 8051 for example the registers R0 & R1 can be used to indirectly
31994 address the internal ram and DPTR to indirectly address the external ram.
31995 The compiler will try to allocate the appropriate register to pointer variables
31997 ICode example section shows the operands annotated with the registers assigned
31999 The compiler will try to keep operands in registers as much as possible;
32000 there are several schemes the compiler uses to do achieve this.
32001 When the compiler runs out of registers the compiler will check to see
32002 if there are any live operands which is not used or defined in the current
32003 basic block being processed, if there are any found then it will push that
32004 operand and use the registers in this block, the operand will then be popped
32005 at the end of the basic block.
32009 There are other MCU specific considerations in this phase.
32010 Some MCUs have an accumulator; very short-lived operands could be assigned
32011 to the accumulator instead of a general-purpose register.
32017 Figure II gives a table of iCode
32018 \begin_inset LatexCommand \index{iCode}
32022 operations supported by the compiler.
32023 The code generation involves translating these operations into corresponding
32024 assembly code for the processor.
32025 This sounds overly simple but that is the essence of code generation.
32026 Some of the iCode operations are generated on a MCU specific manner for
32027 example, the z80 port does not use registers to pass parameters so the
32028 SEND and RECV iCode operations will not be generated, and it also does
32029 not support JUMPTABLES.
32038 \begin_inset Tabular
32039 <lyxtabular version="3" rows="39" columns="4">
32040 <features islongtable="true" headBottomDL="true">
32041 <column alignment="block" valignment="top" leftline="true" width="13col%">
32042 <column alignment="left" valignment="top" leftline="true" width="13col%">
32043 <column alignment="block" valignment="top" leftline="true" width="22col%">
32044 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32045 <row topline="true" bottomline="true" endhead="true">
32046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32055 \begin_inset LatexCommand \index{iCode}
32063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32094 <row topline="true">
32095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32111 IC_LEFT() IC_RESULT()
32115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32131 IC_RESULT = ! IC_LEFT;
32136 <row topline="true">
32137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32153 IC_LEFT() IC_RESULT()
32157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32163 Bitwise complement of
32167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32173 IC_RESULT = ~IC_LEFT;
32178 <row topline="true">
32179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32195 IC_LEFT() IC_RESULT()
32199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32205 Rotate right with carry
32209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32215 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
32220 <row topline="true">
32221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32237 IC_LEFT() IC_RESULT()
32241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32247 Rotate left with carry
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32257 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
32262 <row topline="true">
32263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32279 IC_LEFT() IC_RESULT()
32283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32289 Get the highest order bit of IC_LEFT
32293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32299 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
32304 <row topline="true">
32305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32321 IC_LEFT() IC_RESULT()
32325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32341 IC_RESULT = - IC_LEFT;
32346 <row topline="true">
32347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32373 Push the operand into stack
32377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32388 <row topline="true">
32389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32415 Pop the operand from the stack
32419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32430 <row topline="true">
32431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32447 IC_LEFT() IC_RESULT()
32451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32457 Call the function represented by IC_LEFT
32461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32467 IC_RESULT = IC_LEFT();
32472 <row topline="true">
32473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32489 IC_LEFT() IC_RESULT()
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32499 Call via function pointer
32503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32509 IC_RESULT = (*IC_LEFT)();
32514 <row topline="true">
32515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32541 Return the value in operand IC_LEFT
32545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32556 <row topline="true">
32557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32598 <row topline="true">
32599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32640 <row topline="true">
32641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32657 IC_LEFT() IC_RIGHT() IC_RESULT()
32661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32677 IC_RESULT = IC_LEFT + IC_RIGHT
32682 <row topline="true">
32683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32699 IC_LEFT() IC_RIGHT() IC_RESULT()
32703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32719 IC_RESULT = IC_LEFT - IC_RIGHT
32724 <row topline="true">
32725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32741 IC_LEFT() IC_RIGHT() IC_RESULT()
32745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32761 IC_RESULT = IC_LEFT * IC_RIGHT;
32766 <row topline="true">
32767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32783 IC_LEFT() IC_RIGHT() IC_RESULT()
32787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32803 IC_RESULT = IC_LEFT / IC_RIGHT;
32808 <row topline="true">
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32825 IC_LEFT() IC_RIGHT() IC_RESULT()
32829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32845 IC_RESULT = IC_LEFT % IC_RIGHT;
32850 <row topline="true">
32851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32867 IC_LEFT() IC_RIGHT() IC_RESULT()
32871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32887 IC_RESULT = IC_LEFT < IC_RIGHT;
32892 <row topline="true">
32893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32909 IC_LEFT() IC_RIGHT() IC_RESULT()
32913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32929 IC_RESULT = IC_LEFT > IC_RIGHT;
32934 <row topline="true">
32935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32951 IC_LEFT() IC_RIGHT() IC_RESULT()
32955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32971 IC_RESULT = IC_LEFT == IC_RIGHT;
32976 <row topline="true">
32977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32993 IC_LEFT() IC_RIGHT() IC_RESULT()
32997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33003 Logical and operation
33007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33013 IC_RESULT = IC_LEFT && IC_RIGHT;
33018 <row topline="true">
33019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33035 IC_LEFT() IC_RIGHT() IC_RESULT()
33039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33045 Logical or operation
33049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33055 IC_RESULT = IC_LEFT || IC_RIGHT;
33060 <row topline="true">
33061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33077 IC_LEFT() IC_RIGHT() IC_RESULT()
33081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33097 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33102 <row topline="true">
33103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33119 IC_LEFT() IC_RIGHT() IC_RESULT()
33123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33139 IC_RESULT = IC_LEFT | IC_RIGHT;
33144 <row topline="true">
33145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33161 IC_LEFT() IC_RIGHT() IC_RESULT()
33165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33181 IC_RESULT = IC_LEFT & IC_RIGHT;
33186 <row topline="true">
33187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33203 IC_LEFT() IC_RIGHT() IC_RESULT()
33207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33223 IC_RESULT = IC_LEFT << IC_RIGHT
33228 <row topline="true">
33229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33245 IC_LEFT() IC_RIGHT() IC_RESULT()
33249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33265 IC_RESULT = IC_LEFT >> IC_RIGHT
33270 <row topline="true">
33271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33289 IC_LEFT() IC_RESULT()
33293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33309 IC_RESULT = (*IC_LEFT);
33314 <row topline="true">
33315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33331 IC_RIGHT() IC_RESULT()
33335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33351 (*IC_RESULT) = IC_RIGHT;
33356 <row topline="true">
33357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33373 IC_RIGHT() IC_RESULT()
33377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33393 IC_RESULT = IC_RIGHT;
33398 <row topline="true">
33399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33415 IC_COND IC_TRUE IC_LABEL
33419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33426 If true label is present then jump to true label if condition is true else
33427 jump to false label if condition is false
33431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33437 if (IC_COND) goto IC_TRUE;
33443 If (!IC_COND) goto IC_FALSE;
33448 <row topline="true">
33449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33465 IC_LEFT() IC_RESULT()
33469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33485 IC_RESULT = &IC_LEFT();
33490 <row topline="true">
33491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33507 IC_JTCOND IC_JTLABELS
33511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33517 Jump to list of labels depending on the value of JTCOND
33521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33532 <row topline="true">
33533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33549 IC_RIGHT() IC_LEFT() IC_RESULT()
33553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33569 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
33574 <row topline="true">
33575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33601 This is used for passing parameters in registers;
33603 move IC_LEFT to the next
33604 available parameter register.
33608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33619 <row topline="true">
33620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33646 This is used for receiving parameters passed in registers;
33649 in the next parameter register to IC_RESULT
33653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33664 <row topline="true" bottomline="true">
33665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33672 (some more have been added)
33676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33722 In the original article Figure II was announced to be downloadable on
33727 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
33735 \begin_inset LatexCommand \index{iCode}
33742 This section shows some details of iCode.
33743 The example C code does not do anything useful; it is used as an example
33744 to illustrate the intermediate code generated by the compiler.
33756 /* This function does nothing useful.
33763 for the purpose of explaining iCode */
33766 short function (data
33775 short i=10; \SpecialChar ~
33777 /* dead initialization eliminated */
33783 /* dead initialization eliminated */
33811 /* compiler detects i,j to be induction
33816 for (i = 0, j = 10 ; i < 10 ; i++, j
33844 mul += i * 3; \SpecialChar ~
33846 /* this multiplication remains */
33853 j * 3;\SpecialChar ~
33855 /* this multiplication changed to addition */
33869 In addition to the operands each iCode contains information about the filename
33870 and line it corresponds to in the source file.
33871 The first field in the listing should be interpreted as follows:
33876 Filename(linenumber: iCode Execution sequence number : ICode hash table
33877 key : loop depth of the iCode).
33882 Then follows the human readable form of the ICode operation.
33883 Each operand of this triplet form can be of three basic types a) compiler
33884 generated temporary b) user defined variable c) a constant value.
33885 Note that local variables and parameters are replaced by compiler generated
33888 \begin_inset LatexCommand \index{Live range analysis}
33892 are computed only for temporaries (i.e.
33893 live ranges are not computed for global variables).
33895 \begin_inset LatexCommand \index{Register allocation}
33899 are allocated for temporaries only.
33900 Operands are formatted in the following manner:
33905 Operand Name [lr live-from : live-to ] { type information } [ registers
33911 As mentioned earlier the live ranges are computed in terms of the execution
33912 sequence number of the iCodes, for example
33914 the iTemp0 is live from (i.e.
33915 first defined in iCode with execution sequence number 3, and is last used
33916 in the iCode with sequence number 5).
33917 For induction variables such as iTemp21 the live range computation extends
33918 the lifetime from the start to the end of the loop.
33920 The register allocator
33921 used the live range information to allocate registers, the same registers
33922 may be used for different temporaries if their live ranges do not overlap,
33923 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
33924 ranges do not overlap.
33925 In addition the allocator also takes into consideration the type and usage
33926 of a temporary, for example itemp6 is a pointer to near space and is used
33927 as to fetch data from (i.e.
33928 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
33929 Some short lived temporaries are allocated to special registers which have
33930 meaning to the code generator e.g.
33931 iTemp13 is allocated to a pseudo register CC which tells the back end that
33932 the temporary is used only for a conditional jump the code generation makes
33933 use of this information to optimize a compare and jump ICode.
33937 \begin_inset LatexCommand \index{Loop optimization}
33941 performed by the compiler.
33942 It can detect induction variables iTemp21(i) and iTemp23(j).
33943 Also note the compiler does selective strength reduction
33944 \begin_inset LatexCommand \index{Strength reduction}
33949 the multiplication of an induction variable in line 18 (gint = j * 3) is
33950 changed to addition, a new temporary iTemp17 is allocated and assigned
33951 a initial value, a constant 3 is then added for each iteration of the loop.
33952 The compiler does not change the multiplication
33953 \begin_inset LatexCommand \index{Multiplication}
33957 in line 17 however since the processor does support an 8 * 8 bit multiplication.
33960 Note the dead code elimination
33961 \begin_inset LatexCommand \index{Dead-code elimination}
33965 optimization eliminated the dead assignments in line 7 & 8 to I and sum
33973 Sample.c (5:1:0:0) _entry($9) :
33978 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
33983 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
33988 Sample.c(11:4:53:0) preHeaderLbl0($11) :
33993 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
33999 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34004 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34010 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34015 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34021 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34027 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34033 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34039 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34040 * int}[r0] + 0x2 {short}
34045 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34050 Sample.c(11:17:21:0)_whilebreak_0($3) :
34055 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34060 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34065 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34070 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34075 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34080 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34085 Sample.c(15:24:26:1)_forcond_0($4) :
34090 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34096 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34101 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34102 + ITemp21 [lr21:38]{short}[r4]
34107 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
34113 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
34114 + iTemp15 [lr29:30]{short}[r1]
34119 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
34125 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
34131 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
34137 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
34143 Sample.c(19:38:47:1) goto _forcond_0($4)
34148 Sample.c(19:39:48:0)_forbreak_0($7) :
34153 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
34154 + ITemp11 [lr19:40]{short}[r3]
34159 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
34164 Sample.c(20:42:51:0)_return($8) :
34169 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
34175 Finally the code generated for this function:
34216 ; ----------------------------------------------
34221 ; function function
34226 ; ----------------------------------------------
34236 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
34248 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
34260 ;_whilecontinue_0($1) :
34270 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
34275 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34334 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
34353 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
34400 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
34440 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
34466 ; iTemp6 [lr5:16]{_near * int}[r0] =
34471 ; iTemp6 [lr5:16]{_near * int}[r0] +
34488 ; goto _whilecontinue_0($1)
34500 ; _whilebreak_0($3) :
34510 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34522 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34534 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34546 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34565 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34594 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
34599 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34644 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
34649 ; iTemp21 [lr21:38]{short}[r4]
34675 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
34708 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
34713 ; iTemp15 [lr29:30]{short}[r1]
34732 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
34779 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
34826 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
34838 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
34852 cjne r5,#0xff,00104$
34864 ; goto _forcond_0($4)
34876 ; _forbreak_0($7) :
34886 ; ret iTemp24 [lr40:41]{short}
34929 A few words about basic block successors, predecessors and dominators
34932 Successors are basic blocks
34933 \begin_inset LatexCommand \index{Basic blocks}
34937 that might execute after this basic block.
34939 Predecessors are basic blocks
34940 that might execute before reaching this basic block.
34942 Dominators are basic
34943 blocks that WILL execute before reaching this basic block.
34976 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
34979 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
34982 c) domVect of [BB4] = BB1 ...
34983 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
34990 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35000 Thanks to all the other volunteer developers who have helped with coding,
35001 testing, web-page creation, distribution sets, etc.
35002 You know who you are :-)
35010 Also thanks to Sourceforge
35011 \begin_inset LatexCommand \url{http://www.sf.net}
35015 which has hosted the project since 1999 and donates significant download
35016 bandwidth and probably more than
35026 CPU cycles per day.
35033 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35034 minutes for (configure+make+regression test), and there is (i386, amd64,
35035 alpha, ppc64, (mingw32), sparc, macosx).
35043 This document was initially written by Sandeep Dutta
35046 All product names mentioned herein may be trademarks
35047 \begin_inset LatexCommand \index{Trademarks}
35051 of their respective companies.
35058 To avoid confusion, the installation and building options for SDCC itself
35059 (chapter 2) are not part of the index.
35062 \begin_inset LatexCommand \printindex{}