1 #LyX 1.4.1 created this file. For more info see http://www.lyx.org/
5 \pdfoptionpdfminorversion=3
7 pdftitle={SDCC Compiler User Guide},
8 pdfauthor={SDCC development team},
9 pdfsubject={installation, user manual},
10 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
11 pdfpagemode=UseOutlines,
13 linkcolor=blue] {hyperref}
17 \emergencystretch=30pt
22 \inputencoding default
25 \paperfontsize default
27 \papersize letterpaper
31 \use_numerical_citations 0
32 \paperorientation portrait
39 \paragraph_separation indent
41 \quotes_language swedish
51 Please note: double dashed longoptions (e.g.
52 --version) are written this way: -
68 three consecutive dashes simply result in a long resp.
72 Architecture specific stuff (like memory models, code examples) should maybe
76 into seperate sections/chapters/appendices (it is hard to document PIC or
80 a 8051 centered document) - for now simply add.
87 SDCC Compiler User Guide
105 The above strings enclosed in $ are automatically updated by Subversion
112 \begin_inset LatexCommand \tableofcontents{}
145 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
150 designed for 8 bit Microprocessors.
151 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
153 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
157 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
158 Zilog Z80 based MCUs.
159 It can be retargeted for other microprocessors, support for Microchip PIC,
160 Atmel AVR is under development.
161 The entire source code for the compiler is distributed under GPL.
163 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
168 \begin_inset LatexCommand \index{aslink}
172 , an open source retargetable assembler & linker.
173 SDCC has extensive language extensions suitable for utilizing various microcont
174 rollers and underlying hardware effectively.
179 In addition to the MCU specific optimizations SDCC also does a host of
180 standard optimizations like:
183 global sub expression elimination,
186 loop optimizations (loop invariant, strength reduction of induction variables
190 constant folding & propagation,
196 dead code elimination
206 For the back-end SDCC uses a global register allocation scheme which should
207 be well suited for other 8 bit MCUs.
212 The peep hole optimizer uses a rule based substitution mechanism which
218 Supported data-types are:
222 <lyxtabular version="3" rows="8" columns="5">
224 <column alignment="center" valignment="top" leftline="true" width="0">
225 <column alignment="center" valignment="top" leftline="true" width="0">
226 <column alignment="center" valignment="top" leftline="true" width="0">
227 <column alignment="center" valignment="top" leftline="true" width="0">
228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
229 <row topline="true" bottomline="true">
230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
439 <row topline="true" bottomline="true">
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
468 -2.147.483.648, +2.147.483.647
472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
481 <row topline="true" bottomline="true">
482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
532 <row topline="true" bottomline="true">
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
580 The compiler also allows
582 inline assembler code
584 to be embedded anywhere in a function.
585 In addition, routines developed in assembly can also be called.
590 provides an option (-
602 -cyclomatic) to report the relative complexity of a function.
603 These functions can then be further optimized, or hand coded in assembly
609 SDCC also comes with a companion source level debugger SDCDB, the debugger
610 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
615 The latest version can be downloaded from
616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
626 Please note: the compiler will probably always be some steps ahead of this
631 \begin_inset LatexCommand \index{Status of documentation}
640 Obviously this has pros and cons
650 All packages used in this compiler system are
658 ; source code for all the sub-packages (pre-processor, assemblers, linkers
659 etc) is distributed with the package.
660 This documentation is maintained using a freeware word processor (LyX).
663 program is free software; you can redistribute it and/or modify it under
664 the terms of the GNU General Public License
665 \begin_inset LatexCommand \index{GNU General Public License, GPL}
669 as published by the Free Software Foundation; either version 2, or (at
670 your option) any later version.
671 This program is distributed in the hope that it will be useful, but WITHOUT
672 ANY WARRANTY; without even the implied warranty
673 \begin_inset LatexCommand \index{warranty}
677 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
678 See the GNU General Public License for more details.
679 You should have received a copy of the GNU General Public License along
680 with this program; if not, write to the Free Software Foundation, 59 Temple
681 Place - Suite 330, Boston, MA 02111-1307, USA.
682 In other words, you are welcome to use, share and improve this program.
683 You are forbidden to forbid anyone else to use, share and improve what
685 Help stamp out software-hoarding!
688 Typographic conventions
689 \begin_inset LatexCommand \index{Typographic conventions}
696 Throughout this manual, we will use the following convention.
697 Commands you have to type in are printed in
705 Code samples are printed in
710 Interesting items and new terms are printed in
716 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
720 with previous versions
721 \begin_inset LatexCommand \index{Compatibility with previous versions}
728 This version has numerous bug fixes compared with the previous version.
729 But we also introduced some incompatibilities with older versions.
730 Not just for the fun of it, but to make the compiler more stable, efficient
732 \begin_inset LatexCommand \index{ANSI-compliance}
737 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
741 for ANSI-Compliance).
747 short is now equivalent to int (16 bits), it used to be equivalent to char
748 (8 bits) which is not ANSI compliant.
751 the default directory for gcc-builds where include, library and documentation
752 files are stored is now in /usr/local/share.
755 char type parameters to vararg
756 \begin_inset LatexCommand \index{vararg, va\_arg}
760 functions are casted to int unless explicitly casted
761 \begin_inset Marginal
788 will push a as an int and as a char resp.
803 -regextend has been removed.
818 -noregparms has been removed.
833 -stack-after-data has been removed.
837 \begin_inset LatexCommand \index{bit}
842 \begin_inset LatexCommand \index{sbit}
847 \begin_inset LatexCommand \index{\_\_sbit}
851 types now consistently behave like the C99 _Bool type with respect to type
853 \begin_inset LatexCommand \index{type conversion}
858 \begin_inset LatexCommand \index{type promotion}
863 The most common incompatibility resulting from this change is related to
865 \begin_inset LatexCommand \index{Bit toggling}
880 \begin_inset LatexCommand \index{\~\/ Operator}
884 b; /* equivalent to b=1 instead of toggling b */
885 \begin_inset Marginal
900 b = !b; /* toggles b */
904 In previous versions, both forms would have toggled the bit.
909 <pending: more incompatibilities?>
915 What do you need before you start installation of SDCC? A computer, and
917 The preferred method of installation is to compile SDCC from source using
919 For Windows some pre-compiled binary distributions are available for your
921 You should have some experience with command line tools and compiler use.
927 The SDCC home page at
928 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
932 is a great place to find distribution sets.
933 You can also find links to the user mailing lists that offer help or discuss
934 SDCC with other SDCC users.
935 Web links to other SDCC related sites can also be found here.
936 This document can be found in the DOC directory of the source package as
938 A pdf version of this document is available at
939 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
944 Some of the other tools (simulator and assembler) included with SDCC contain
945 their own documentation and can be found in the source distribution.
946 If you want the latest unreleased software, the complete source package
947 is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
951 Wishes for the future
954 There are (and always will be) some things that could be done.
955 Here are some I can think of:
962 char KernelFunction3(char p) at 0x340;
970 \begin_inset LatexCommand \index{code banking (limited support)}
980 If you can think of some more, please see the section
981 \begin_inset LatexCommand \ref{sub:Requesting-Features}
985 about filing feature requests
986 \begin_inset LatexCommand \index{Requesting features}
991 \begin_inset LatexCommand \index{Feature request}
1001 \begin_inset LatexCommand \index{Installation}
1008 For most users it is sufficient to skip to either section
1009 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1014 \begin_inset LatexCommand \ref{sub:Windows-Install}
1019 More detailed instructions follow below.
1023 \begin_inset LatexCommand \index{Options SDCC configuration}
1030 The install paths, search paths and other options are defined when running
1032 The defaults can be overridden by:
1035 \labelwidthstring 00.00.0000
1048 -prefix see table below
1051 \labelwidthstring 00.00.0000
1064 -exec_prefix see table below
1067 \labelwidthstring 00.00.0000
1080 -bindir see table below
1083 \labelwidthstring 00.00.0000
1096 -datadir see table below
1099 \labelwidthstring 00.00.0000
1112 -datarootdir see table below
1117 \labelwidthstring 00.00.0000
1120 docdir environment variable, see table below
1123 \labelwidthstring 00.00.0000
1126 include_dir_suffix environment variable, see table below
1129 \labelwidthstring 00.00.0000
1132 lib_dir_suffix environment variable, see table below
1135 \labelwidthstring 00.00.0000
1138 sdccconf_h_dir_separator environment variable, either / or
1143 This character will only be used in sdccconf.h; don't forget it's a C-header,
1144 therefore a double-backslash is needed there.
1149 \labelwidthstring 00.00.0000
1162 -disable-mcs51-port Excludes the Intel mcs51 port
1165 \labelwidthstring 00.00.0000
1178 -disable-gbz80-port Excludes the Gameboy gbz80 port
1181 \labelwidthstring 00.00.0000
1194 -disable-z80-port Excludes the z80 port
1197 \labelwidthstring 00.00.0000
1210 -disable-avr-port Excludes the AVR port
1213 \labelwidthstring 00.00.0000
1226 -disable-ds390-port Excludes the DS390 port
1229 \labelwidthstring 00.00.0000
1242 -disable-hc08-port Excludes the HC08 port
1245 \labelwidthstring 00.00.0000
1258 -disable-pic-port Excludes the PIC port
1261 \labelwidthstring 00.00.0000
1274 -disable-xa51-port Excludes the XA51 port
1277 \labelwidthstring 00.00.0000
1290 -disable-ucsim Disables configuring and building of ucsim
1293 \labelwidthstring 00.00.0000
1306 -disable-device-lib Disables automatically building device libraries
1309 \labelwidthstring 00.00.0000
1322 -disable-packihx Disables building packihx
1327 \labelwidthstring 00.00.0000
1340 -enable-doc Build pdf, html and txt files from the lyx sources
1343 \labelwidthstring 00.00.0000
1356 -enable-libgc Use the Bohem memory allocator.
1357 Lower runtime footprint.
1360 Furthermore the environment variables CC, CFLAGS, ...
1361 the tools and their arguments can be influenced.
1362 Please see `configure -
1374 -help` and the man/info pages of `configure` for details.
1379 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1380 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1381 SDCC_LIB_NAME are defined by `configure` too.
1382 At the moment it's not possible to change the default settings (it was
1383 simply never required).
1387 These configure options are compiled into the binaries,
1388 and can only be changed by rerunning 'configure' and recompiling SDCC.
1389 The configure options are written in
1393 to distinguish them from run time environment variables (see section search
1399 \begin_inset Quotes sld
1403 \begin_inset Quotes srd
1406 are used by the SDCC team to build the official Win32 binaries.
1407 The SDCC team uses Mingw32 to build the official Windows binaries, because
1414 a gcc compiler and last but not least
1417 the binaries can be built by cross compiling on Sourceforge's compile farm.
1420 See the examples, how to pass the Win32 settings to 'configure'.
1421 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1422 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1433 \begin_inset Tabular
1434 <lyxtabular version="3" rows="9" columns="3">
1436 <column alignment="block" valignment="top" leftline="true" width="0in">
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1439 <row topline="true" bottomline="true">
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1465 <row topline="true">
1466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1495 <row topline="true">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1527 <row topline="true">
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1597 <row topline="true">
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1631 <row topline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1697 <row topline="true" bottomline="true">
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1735 'configure' also computes relative paths.
1736 This is needed for full relocatability of a binary package and to complete
1737 search paths (see section search paths below):
1743 \begin_inset Tabular
1744 <lyxtabular version="3" rows="4" columns="3">
1746 <column alignment="block" valignment="top" leftline="true" width="0in">
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1749 <row topline="true" bottomline="true">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1775 <row topline="true" bottomline="true">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1803 <row bottomline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1831 <row bottomline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1887 \begin_inset Quotes srd
1891 \begin_inset Quotes srd
1907 \begin_inset Quotes srd
1911 \begin_inset Quotes srd
1943 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1952 \begin_inset Quotes srd
1955 i586-mingw32msvc-gcc
1956 \begin_inset Quotes srd
1960 \begin_inset Quotes srd
1963 i586-mingw32msvc-g++
1964 \begin_inset Quotes srd
1972 \begin_inset Quotes srd
1975 i586-mingw32msvc-ranlib
1976 \begin_inset Quotes srd
1984 \begin_inset Quotes srd
1987 i586-mingw32msvc-strip
1988 \begin_inset Quotes srd
2008 \begin_inset Quotes srd
2012 \begin_inset Quotes srd
2032 \begin_inset Quotes srd
2036 \begin_inset Quotes srd
2044 \begin_inset Quotes srd
2050 \begin_inset Quotes srd
2058 \begin_inset Quotes srd
2062 \begin_inset Quotes srd
2070 \begin_inset Quotes srd
2074 \begin_inset Quotes srd
2081 sdccconf_h_dir_separator=
2082 \begin_inset Quotes srd
2094 \begin_inset Quotes srd
2129 -host=i586-mingw32msvc
2145 -build=unknown-unknown-linux-gnu
2149 \begin_inset Quotes sld
2153 \begin_inset Quotes srd
2156 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2177 \begin_inset Quotes srd
2181 \begin_inset Quotes srd
2201 \begin_inset Quotes srd
2205 \begin_inset Quotes srd
2213 \begin_inset Quotes srd
2219 \begin_inset Quotes srd
2227 \begin_inset Quotes srd
2231 \begin_inset Quotes srd
2239 \begin_inset Quotes srd
2243 \begin_inset Quotes srd
2250 sdccconf_h_dir_separator=
2251 \begin_inset Quotes srd
2263 \begin_inset Quotes srd
2271 \begin_inset Quotes srd
2275 \begin_inset Quotes srd
2283 \begin_inset Quotes srd
2287 \begin_inset Quotes srd
2293 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2306 -C' turns on caching, which gives a little bit extra speed.
2307 However if options are changed, it can be necessary to delete the config.cache
2312 \added_space_bottom medskip
2313 \begin_inset LatexCommand \label{sub:Install-paths}
2318 \begin_inset LatexCommand \index{Install paths}
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="5" columns="4">
2330 <column alignment="left" valignment="top" leftline="true" width="0">
2331 <column alignment="left" valignment="top" leftline="true" width="0">
2332 <column alignment="left" valignment="top" leftline="true" width="0">
2333 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2334 <row topline="true" bottomline="true">
2335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2376 <row topline="true">
2377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2416 <row topline="true">
2417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2431 $DATADIR/ $INCLUDE_DIR_SUFFIX
2435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 /usr/local/share/sdcc/include
2443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2456 <row topline="true">
2457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2471 $DATADIR/$LIB_DIR_SUFFIX
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2479 /usr/local/share/sdcc/lib
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2496 <row topline="true" bottomline="true">
2497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2519 /usr/local/share/sdcc/doc
2523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2545 *compiler, preprocessor, assembler, and linker
2551 is auto-appended by the compiler, e.g.
2552 small, large, z80, ds390 etc
2556 The install paths can still be changed during `make install` with e.g.:
2559 make install prefix=$(HOME)/local/sdcc
2562 Of course this doesn't change the search paths compiled into the binaries.
2567 r the install path can be changed by defining DESTDIR
2568 \begin_inset LatexCommand \index{DESTDIR}
2575 make install DESTDIR=$(HOME)/sdcc.rpm/
2578 Please note that DESTDIR must have a trailing slash!
2582 \begin_inset LatexCommand \label{sub:Search-Paths}
2587 \begin_inset LatexCommand \index{Search path}
2594 Some search paths or parts of them are determined by configure variables
2599 , see section above).
2600 Further search paths are determined by environment variables during runtime.
2603 The paths searched when running the compiler are as follows (the first
2609 Binary files (preprocessor, assembler and linker)
2615 \begin_inset Tabular
2616 <lyxtabular version="3" rows="4" columns="3">
2618 <column alignment="block" valignment="top" leftline="true" width="0in">
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2621 <row topline="true" bottomline="true">
2622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2647 <row topline="true">
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2677 <row topline="true">
2678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 Path of argv[0] (if available)
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2703 <row topline="true" bottomline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2746 \begin_inset Tabular
2747 <lyxtabular version="3" rows="6" columns="3">
2749 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2752 <row topline="true" bottomline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2778 <row topline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2840 <row topline="true">
2841 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2866 <row topline="true">
2867 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2881 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2904 <row topline="true">
2905 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2986 <row topline="true" bottomline="true">
2987 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3003 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3007 /usr/local/share/sdcc/
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3044 -nostdinc disables the last two search paths.
3054 With the exception of
3055 \begin_inset Quotes sld
3071 \begin_inset Quotes srd
3078 is auto-appended by the compiler (e.g.
3079 small, large, z80, ds390 etc.).
3086 \begin_inset Tabular
3087 <lyxtabular version="3" rows="6" columns="3">
3089 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3090 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3091 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3092 <row topline="true" bottomline="true">
3093 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3118 <row topline="true">
3119 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3180 <row topline="true">
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3193 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3220 <row topline="true">
3221 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3231 $LIB_DIR_SUFFIX/<model>
3235 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3249 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3266 <row topline="true">
3267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3281 $LIB_DIR_SUFFIX/<model>
3285 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3394 <row topline="true" bottomline="true">
3395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3403 $LIB_DIR_SUFFIX/<model>
3407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3411 /usr/local/share/sdcc/
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3441 Don't delete any of the stray spaces in the table above without checking
3442 the HTML output (last line)!
3464 -nostdlib disables the last two search paths.
3468 \begin_inset LatexCommand \index{Building SDCC}
3475 Building SDCC on Linux
3476 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3485 Download the source package
3487 either from the SDCC Subversion repository or from the nightly snapshots
3489 , it will be named something like sdcc
3500 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3509 Bring up a command line terminal, such as xterm.
3514 Unpack the file using a command like:
3517 "tar -xvzf sdcc.src.tar.gz
3522 , this will create a sub-directory called sdcc with all of the sources.
3525 Change directory into the main SDCC directory, for example type:
3542 This configures the package for compilation on your system.
3558 All of the source packages will compile, this can take a while.
3574 This copies the binary executables, the include files, the libraries and
3575 the documentation to the install directories.
3576 Proceed with section
3577 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3584 Building SDCC on OSX 2.x
3587 Follow the instruction for Linux.
3591 On OSX 2.x it was reported, that the default
3592 gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3593 Fortunately there's also gcc 2.9.x installed, which works fine.
3594 This compiler can be selected by running 'configure' with:
3597 ./configure CC=gcc2 CXX=g++2
3600 Cross compiling SDCC on Linux for Windows
3603 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3604 See section 'Configure Options'.
3607 Building SDCC using Cygwin and Mingw32
3610 For building and installing a Cygwin executable follow the instructions
3616 \begin_inset Quotes sld
3620 \begin_inset Quotes srd
3623 Win32-binary can be built, which will not need the Cygwin-DLL.
3624 For the necessary 'configure' options see section 'configure options' or
3625 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3630 Cygwin on Windows download setup.exe from
3631 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3637 \begin_inset Quotes sld
3640 default text file type
3641 \begin_inset Quotes srd
3645 \begin_inset Quotes sld
3649 \begin_inset Quotes srd
3652 and download/install at least the following packages.
3653 Some packages are selected by default, others will be automatically selected
3654 because of dependencies with the manually selected packages.
3655 Never deselect these packages!
3664 gcc ; version 3.x is fine, no need to use the old 2.9x
3667 binutils ; selected with gcc
3673 rxvt ; a nice console, which makes life much easier under windoze (see below)
3676 man ; not really needed for building SDCC, but you'll miss it sooner or
3680 less ; not really needed for building SDCC, but you'll miss it sooner or
3684 svn ; only if you use Subversion access
3687 If you want to develop something you'll need:
3690 python ; for the regression tests
3693 gdb ; the gnu debugger, together with the nice GUI
3694 \begin_inset Quotes sld
3698 \begin_inset Quotes srd
3704 openssh ; to access the CF or commit changes
3707 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3708 use autoconf-stable!
3711 rxvt is a nice console with history.
3712 Replace in your cygwin.bat the line
3733 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3736 -bg black -fg white -geometry 100x65 -e bash -
3751 Text selected with the mouse is automatically copied to the clipboard, pasting
3752 works with shift-insert.
3756 The other good tip is to make sure you have no //c/-styl
3757 e paths anywhere, use /cygdrive/c/ instead.
3758 Using // invokes a network lookup which is very slow.
3760 \begin_inset Quotes sld
3764 \begin_inset Quotes srd
3767 is too long, you can change it with e.g.
3773 SDCC sources use the unix line ending LF.
3774 Life is much easier, if you store the source tree on a drive which is mounted
3776 And use an editor which can handle LF-only line endings.
3777 Make sure not to commit files with windows line endings.
3778 The tabulator spacing
3779 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3783 used in the project is 8.
3784 Although a tabulator spacing of 8 is a sensible choice for programmers
3785 (it's a power of 2 and allows to display 8/16 bit signed variables without
3786 loosing columns) the plan is to move towards using only spaces in the source.
3789 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3794 Download the source package
3796 either from the SDCC Subversion repository or from the
3797 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3803 , it will be named something like sdcc
3810 SDCC is distributed with all the projects, workspaces, and files you need
3811 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3812 The workspace name is 'sdcc.dsw'.
3813 Please note that as it is now, all the executables are created in a folder
3817 Once built you need to copy the executables from sdcc
3821 bin before running SDCC.
3826 WARNING: Visual studio is very picky with line terminations; it expects
3827 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3828 When using the Subversion repository it's easiest to configure the svn
3829 client to convert automatically for you.
3830 If however you are getting a message such as "This makefile was not generated
3831 by Developer Studio etc.
3833 \begin_inset Quotes srd
3836 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3837 need to convert the Unix style line endings to DOS style line endings.
3838 To do so you can use the
3839 \begin_inset Quotes sld
3843 \begin_inset Quotes srd
3846 utility freely available on the internet.
3847 Doug Hawkins reported in the sdcc-user list that this works:
3855 SDCC> unix2dos sdcc.dsw
3861 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3865 In order to build SDCC with MSVC
3866 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3867 One good place to get them is
3868 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3876 Download the file UnxUtils
3877 \begin_inset LatexCommand \index{UnxUtils}
3882 Now you have to install the utilities and setup MSVC so it can locate the
3884 Here there are two alternatives (choose one!):
3891 a) Extract UnxUtils.zip to your C:
3893 hard disk PRESERVING the original paths, otherwise bison won't work.
3894 (If you are using WinZip make certain that 'Use folder names' is selected)
3899 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3900 'Show directories for:' select 'Executable files', and in the directories
3901 window add a new path: 'C:
3911 (As a side effect, you get a bunch of Unix utilities that
3912 could be useful, such as diff and patch.)
3919 This one avoids extracting a bunch of files you may not
3920 use, but requires some extra work:
3924 a) Create a directory were to put the
3925 tools needed, or use a directory already present.
3932 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3933 gawk.exe to such directory WITHOUT preserving the original paths.
3934 (If you are using WinZip make certain that 'Use folder names' is not selected)
3939 ) Rename bison.exe to '_bison.exe'.
3943 d) Create a batch file 'bison.bat' in 'C:
3947 ' and add these lines:
3967 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3971 Steps 'c' and 'd' are needed
3972 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3973 reside in some weird Unix directory, '/usr/local/share/' I think.
3974 So it is necessary to tell bison where those files are located if they
3975 are not in such directory.
3976 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3981 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3982 in 'Show directories for:' select 'Executable files', and in the directories
3983 window add a new path: 'c:
3986 Note that you can use any other path instead of 'c:
3988 util', even the path where the Visual C++ tools are, probably: 'C:
3992 Microsoft Visual Studio
3997 So you don't have to execute step 'e' :)
4001 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4002 the executables from sdcc
4006 bin, and you can compile using SDCC.
4009 Building SDCC Using Borland
4012 From the sdcc directory, run the command "make -f Makefile.bcc".
4013 This should regenerate all the .exe files in the bin directory except for
4017 If you modify any source files and need to rebuild, be aware that the dependenci
4018 es may not be correctly calculated.
4019 The safest option is to delete all .obj files and run the build again.
4020 From a Cygwin BASH prompt, this can easily be done with the command (be
4021 sure you are in the sdcc directory):
4031 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4033 ) -print -exec rm {}
4042 or on Windows NT/2000/XP from the command prompt with the command:
4049 del /s *.obj *.lib *.rul
4052 from the sdcc directory.
4055 Windows Install Using a ZIP Package
4058 Download the binary zip package from
4059 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4063 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4064 This should unpack to a group of sub-directories.
4065 An example directory structure after unpacking the mingw32 package is:
4070 bin for the executables, c:
4078 lib for the include and libraries.
4081 Adjust your environment variable PATH to include the location of the bin
4082 directory or start sdcc using the full path.
4085 Windows Install Using the Setup Program
4086 \begin_inset LatexCommand \label{sub:Windows-Install}
4093 Download the setup program
4095 sdcc-x.y.z-setup.exe
4097 for an official release from
4100 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4104 or a setup program for one of the snapshots
4106 sdcc-yyyymmdd-xxxx-setup.exe
4109 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4114 A windows typical installer will guide you through the installation process.
4118 \begin_inset LatexCommand \index{VPATH}
4125 SDCC supports the VPATH feature provided by configure and make.
4126 It allows to separate the source and build trees.
4158 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4159 # extract source to directory sdcc
4164 mkdir sdcc.build\SpecialChar ~
4173 # put output in sdcc.build
4183 ../sdcc/configure\SpecialChar ~
4191 # configure is doing all the magic!
4204 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4205 It automagically computes the variables srcdir, top_srcdir and top_buildir
4211 the generated files will be in ~/sdcc.build, while the source files stay
4214 This is not only usefull for building different binaries, e.g.
4215 when cross compiling.
4216 It also gives you a much better overview in the source tree when all the
4217 generated files are not scattered between the source files.
4218 And the best thing is: if you want to change a file you can leave the original
4219 file untouched in the source directory.
4220 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4221 Makefile.dep` and `make`.
4226 will do the rest for you!
4229 Building the Documentation
4244 -enable-doc to the configure arguments to build the documentation together
4245 with all the other stuff.
4246 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4247 dvips and makeindex) to get the job done.
4248 Another possibility is to change to the doc directory and to type
4252 \begin_inset Quotes srd
4256 \begin_inset Quotes srd
4263 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4266 \begin_inset LatexCommand \url{http://www.lyx.org}
4270 as editor is straightforward.
4271 Prebuilt documentation in html and pdf format is available from
4272 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4279 Reading the Documentation
4280 \begin_inset LatexCommand \index{Documentation}
4287 Currently reading the document in pdf format is recommended, as for unknown
4288 reason the hyperlinks are working there whereas in the html version they
4294 If you should know why please drop us a note
4301 You'll find the pdf version
4302 \begin_inset LatexCommand \index{PDF version of this document}
4307 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4315 \begin_inset LatexCommand \index{HTML version of this document}
4320 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4326 This documentation is in some aspects different from a commercial documentation:
4330 It tries to document SDCC for several processor architectures in one document
4331 (commercially these probably would be separate documents/products).
4333 \begin_inset LatexCommand \index{Status of documentation}
4337 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4339 Z80, PIC14, PIC16 and HC08.
4342 There are many references pointing away from this documentation.
4343 Don't let this distract you.
4345 was a reference like
4346 \begin_inset LatexCommand \url{http://www.opencores.org}
4350 together with a statement
4351 \begin_inset Quotes sld
4354 some processors which are targetted by SDCC can be implemented in a
4371 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4376 \begin_inset Quotes srd
4380 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4385 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4390 \begin_inset Quotes sld
4393 have you ever heard of an open source compiler that compiles a subset of
4395 \begin_inset Quotes srd
4398 we expect you to have a quick look there and come back.
4399 If you read this you are on the right track.
4402 Some sections attribute more space to problems, restrictions and warnings
4403 than to the solution.
4406 The installation section and the section about the debugger is intimidating.
4409 There are still lots of typos and there are more different writing styles
4413 Testing the SDCC Compiler
4414 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4421 The first thing you should do after installing your SDCC compiler is to
4439 \begin_inset LatexCommand \index{version}
4446 at the prompt, and the program should run and output its version like:
4451 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4455 If it doesn't run, or gives a message about not finding sdcc program, then
4456 you need to check over your installation.
4457 Make sure that the sdcc bin directory is in your executable search path
4458 defined by the PATH environment setting (
4463 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4470 Install trouble-shooting for suggestions
4473 Make sure that the sdcc program is in the bin folder, if not perhaps something
4474 did not install correctly.
4482 is commonly installed as described in section
4483 \begin_inset Quotes sld
4486 Install and search paths
4487 \begin_inset Quotes srd
4496 Make sure the compiler works on a very simple example.
4497 Type in the following test.c program using your favorite
4523 Compile this using the following command:
4532 If all goes well, the compiler will generate a test.asm and test.rel file.
4533 Congratulations, you've just compiled your first program with SDCC.
4534 We used the -c option to tell SDCC not to link the generated code, just
4535 to keep things simple for this step.
4543 The next step is to try it with the linker.
4553 If all goes well the compiler will link with the libraries and produce
4554 a test.ihx output file.
4559 (no test.ihx, and the linker generates warnings), then the problem is most
4568 usr/local/share/sdcc/lib directory
4575 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4582 Install trouble-shooting for suggestions).
4590 The final test is to ensure
4598 header files and libraries.
4599 Edit test.c and change it to the following:
4616 strcpy(str1, "testing");
4623 Compile this by typing
4630 This should generate a test.ihx output file, and it should give no warnings
4631 such as not finding the string.h file.
4632 If it cannot find the string.h file, then the problem is that
4636 cannot find the /usr/local/share/sdcc/include directory
4643 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4650 Install trouble-shooting section for suggestions).
4670 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4674 to find exactly where SDCC is looking for the include and lib files.
4677 Install Trouble-shooting
4678 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4683 \begin_inset LatexCommand \index{Install trouble-shooting}
4690 If SDCC does not build correctly
4693 A thing to try is starting from scratch by unpacking the .tgz source package
4694 again in an empty directory.
4702 ./configure 2>&1 | tee configure.log
4716 make 2>&1 | tee make.log
4723 If anything goes wrong, you can review the log files to locate the problem.
4724 Or a relevant part of this can be attached to an email that could be helpful
4725 when requesting help from the mailing list.
4729 \begin_inset Quotes sld
4733 \begin_inset Quotes srd
4740 \begin_inset Quotes sld
4744 \begin_inset Quotes srd
4747 command is a script that analyzes your system and performs some configuration
4748 to ensure the source package compiles on your system.
4749 It will take a few minutes to run, and will compile a few tests to determine
4750 what compiler features are installed.
4754 \begin_inset Quotes sld
4758 \begin_inset Quotes srd
4764 This runs the GNU make tool, which automatically compiles all the source
4765 packages into the final installed binary executables.
4769 \begin_inset Quotes sld
4773 \begin_inset Quotes erd
4779 This will install the compiler, other executables libraries and include
4780 files into the appropriate directories.
4782 \begin_inset LatexCommand \ref{sub:Install-paths}
4788 \begin_inset LatexCommand \ref{sub:Search-Paths}
4793 about install and search paths.
4795 On most systems you will need super-user privilege
4802 SDCC is not just a compiler, but a collection of tools by various developers.
4803 These include linkers, assemblers, simulators and other components.
4804 Here is a summary of some of the components.
4805 Note that the included simulator and assembler have separate documentation
4806 which you can find in the source package in their respective directories.
4807 As SDCC grows to include support for other processors, other packages from
4808 various developers are included and may have their own sets of documentation.
4813 might want to look at the files which are installed in <installdir>.
4814 At the time of this writing, we find the following programs for gcc-builds:
4819 In <installdir>/bin:
4822 sdcc - The compiler.
4825 sdcpp - The C preprocessor.
4828 asx8051 - The assembler for 8051 type processors.
4835 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4838 aslink -The linker for 8051 type processors.
4845 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4848 s51 - The ucSim 8051 simulator.
4851 sdcdb - The source debugger.
4854 packihx - A tool to pack (compress) Intel hex files.
4857 In <installdir>/share/sdcc/include
4863 In <installdir>/share/sdcc/lib
4866 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4870 In <installdir>/share/sdcc/doc
4876 As development for other processors proceeds, this list will expand to include
4877 executables to support processors like AVR, PIC, etc.
4883 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4884 the assembler and linkage editor.
4887 sdcpp - The C-Preprocessor
4891 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4895 is a modified version of the GNU cpp
4896 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4901 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4906 The C preprocessor is used to pull in #include sources, process #ifdef
4907 statements, #defines and so on.
4918 - The Assemblers and Linkage Editors
4921 This is retargettable assembler & linkage editor, it was developed by Alan
4923 John Hartman created the version for 8051, and I (Sandeep) have made some
4924 enhancements and bug fixes for it to work properly with SDCC.
4931 \begin_inset LatexCommand \index{s51}
4935 is a freeware, opensource simulator developed by Daniel Drotos.
4936 The simulator is built as part of the build process.
4937 For more information visit Daniel's web site at:
4938 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4943 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4947 sdcdb - Source Level Debugger
4951 \begin_inset LatexCommand \index{SDCDB (debugger)}
4955 is the companion source level debugger.
4956 More about SDCDB in section
4957 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4962 The current version of the debugger uses Daniel's Simulator S51
4963 \begin_inset LatexCommand \index{s51}
4967 , but can be easily changed to use other simulators.
4976 Single Source File Projects
4979 For single source file 8051 projects the process is very simple.
4980 Compile your programs with the following command
4983 "sdcc sourcefile.c".
4987 This will compile, assemble and link your source file.
4988 Output files are as follows:
4992 \begin_inset LatexCommand \index{<file>.asm}
4997 \begin_inset LatexCommand \index{Assembler source}
5001 file created by the compiler
5005 \begin_inset LatexCommand \index{<file>.lst}
5010 \begin_inset LatexCommand \index{Assembler listing}
5014 file created by the Assembler
5018 \begin_inset LatexCommand \index{<file>.rst}
5023 \begin_inset LatexCommand \index{Assembler listing}
5027 file updated with linkedit information, created by linkage editor
5031 \begin_inset LatexCommand \index{<file>.sym}
5036 \begin_inset LatexCommand \index{Symbol listing}
5040 for the sourcefile, created by the assembler
5044 \begin_inset LatexCommand \index{<file>.rel}
5049 \begin_inset LatexCommand \index{<file>.o}
5054 \begin_inset LatexCommand \index{Object file}
5058 created by the assembler, input to Linkage editor
5062 \begin_inset LatexCommand \index{<file>.map}
5067 \begin_inset LatexCommand \index{Memory map}
5071 for the load module, created by the Linker
5075 \begin_inset LatexCommand \index{<file>.mem}
5079 - A file with a summary of the memory usage
5083 \begin_inset LatexCommand \index{<file>.ihx}
5087 - The load module in Intel hex format
5088 \begin_inset LatexCommand \index{Intel hex format}
5092 (you can select the Motorola S19 format
5093 \begin_inset LatexCommand \index{Motorola S19 format}
5110 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5115 If you need another format you might want to use
5122 \begin_inset LatexCommand \index{objdump (tool)}
5133 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5138 Both formats are documented in the documentation of srecord
5139 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5147 \begin_inset LatexCommand \index{<file>.adb}
5151 - An intermediate file containing debug information needed to create the
5165 \begin_inset LatexCommand \index{-\/-debug}
5173 \begin_inset LatexCommand \index{<file>.cdb}
5177 - An optional file (with -
5189 -debug) containing debug information.
5190 The format is documented in cdbfileformat.pdf
5195 \begin_inset LatexCommand \index{<file> (no extension)}
5199 An optional AOMF or AOMF51
5200 \begin_inset LatexCommand \index{AOMF, AOMF51}
5205 \begin_inset LatexCommand \label{OMF file}
5209 file containing debug information (generated with option -
5238 ormat is commonly used by third party tools (debuggers
5239 \begin_inset LatexCommand \index{Debugger}
5243 , simulators, emulators)
5247 \begin_inset LatexCommand \index{<file>.dump*}
5251 - Dump file to debug the compiler it self (generated with option -
5263 -dumpall) (see section
5264 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5270 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5276 \begin_inset Quotes sld
5279 Anatomy of the compiler
5280 \begin_inset Quotes srd
5286 Postprocessing the Intel Hex
5287 \begin_inset LatexCommand \index{Intel hex format}
5294 In most cases this won't be needed but the Intel Hex file
5295 \begin_inset LatexCommand \index{<file>.ihx}
5299 which is generated by SDCC might include lines of varying length and the
5300 addresses within the file are not guaranteed to be strictly ascending.
5301 If your toolchain or a bootloader does not like this you can use the tool
5307 \begin_inset LatexCommand \index{packihx (tool)}
5311 which is part of the SDCC distribution:
5318 packihx sourcefile.ihx >sourcefile.hex
5325 The separately available
5330 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5334 package additionally allows to set undefined locations to a predefined
5335 value, to insert checksums
5336 \begin_inset LatexCommand \index{checksum}
5340 of various flavours (crc, add, xor) and to perform other manipulations
5341 (convert, split, crop, offset, ...).
5349 srec_cat\SpecialChar ~
5351 sourcefile.ihx -intel\SpecialChar ~
5353 -o sourcefile.hex -intel
5360 An example for a more complex command line
5365 the command backfills
5366 \begin_inset LatexCommand \index{backfill unused memory}
5370 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5372 If the program counter on an mcs51 runs wild the backfill pattern 0x12
5373 will be interpreted as an
5381 (where an emergency routine could sit).
5393 srec_cat\SpecialChar ~
5394 sourcefile.ihx -intel\SpecialChar ~
5396 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5397 -little-endian-checksum-nega
5398 tive 0xfffe 0x02 0x02\SpecialChar ~
5400 -o sourcefile.hex -intel
5409 The srecord package is available at
5410 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5417 Projects with Multiple Source Files
5420 SDCC can compile only ONE file at a time.
5421 Let us for example assume that you have a project containing the following
5426 foo1.c (contains some functions)
5428 foo2.c (contains some more functions)
5431 n.c (contains more functions and the function main)
5439 The first two files will need to be compiled separately with the commands:
5471 Then compile the source file containing the
5476 \begin_inset LatexCommand \index{Linker}
5480 the files together with the following command:
5488 foomain.c\SpecialChar ~
5489 foo1.rel\SpecialChar ~
5494 \begin_inset LatexCommand \index{<file>.rel}
5506 can be separately compiled as well:
5517 sdcc foomain.rel foo1.rel foo2.rel
5524 The file containing the
5539 file specified in the command line, since the linkage editor processes
5540 file in the order they are presented to it.
5541 The linker is invoked from SDCC using a script file with extension .lnk
5542 \begin_inset LatexCommand \index{<file>.lnk}
5547 You can view this file to troubleshoot linking problems such as those arising
5548 from missing libraries.
5551 Projects with Additional Libraries
5552 \begin_inset LatexCommand \index{Libraries}
5559 Some reusable routines may be compiled into a library, see the documentation
5560 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5564 \begin_inset LatexCommand \index{<file>.lib}
5571 Libraries created in this manner can be included in the command line.
5572 Make sure you include the -L <library-path> option to tell the linker where
5573 to look for these files if they are not in the current directory.
5574 Here is an example, assuming you have the source file
5586 (if that is not the same as your current project):
5593 sdcc foomain.c foolib.lib -L mylib
5604 must be an absolute path name.
5608 The most efficient way to use libraries is
5609 to keep separate modules in separate source files.
5610 The lib file now should name all the modules.rel
5611 \begin_inset LatexCommand \index{<file>.rel}
5616 For an example see the standard library file
5620 in the directory <installdir>/share/lib/small.
5623 Using sdcclib to Create and Manage Libraries
5624 \begin_inset LatexCommand \index{sdcclib}
5631 Alternatively, instead of having a .rel file for each entry on the library
5632 file as described in the preceding section, sdcclib can be used to embed
5633 all the modules belonging to such library in the library file itself.
5634 This results in a larger library file, but it greatly reduces the number
5635 of disk files accessed by the linker.
5636 Additionally, the packed library file contains an index of all include
5637 modules and symbols that significantly speeds up the linking process.
5638 To display a list of options supported by sdcclib type:
5647 \begin_inset LatexCommand \index{sdcclib}
5658 To create a new library file, start by compiling all the required modules.
5696 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5698 The next step is to add the .rel files to the library file:
5706 sdcclib libint.lib _divsint.rel
5709 \begin_inset LatexCommand \index{sdcclib}
5719 sdcclib libint.lib _divuint.rel
5725 sdcclib libint.lib _modsint.rel
5731 sdcclib libint.lib _moduint.rel
5737 sdcclib libint.lib _mulint.rel
5744 If the file already exists in the library, it will be replaced.
5745 To see what modules and symbols are included in the library, options -s
5746 and -m are available.
5754 sdcclib -s libint.lib
5757 \begin_inset LatexCommand \index{sdcclib}
5867 \added_space_bottom bigskip
5868 If the source files are compiled using -
5881 \begin_inset LatexCommand \index{-\/-debug}
5885 , the corresponding debug information file .adb will be include in the library
5887 The library files created with sdcclib are plain text files, so they can
5888 be viewed with a text editor.
5889 It is not recomended to modify a library file created with sdcclib using
5890 a text editor, as there are file indexes numbers located accross the file
5891 used by the linker to quickly locate the required module to link.
5892 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5893 it can be safely deleted, since all the information required for linking
5894 is embedded in the library file itself.
5895 Library files created using sdcclib are used as described in the preceding
5901 Command Line Options
5902 \begin_inset LatexCommand \index{Command Line Options}
5909 Processor Selection Options
5910 \begin_inset LatexCommand \index{Options processor selection}
5915 \begin_inset LatexCommand \index{Processor selection options}
5922 \labelwidthstring 00.00.0000
5926 \begin_inset LatexCommand \index{-mmcs51}
5932 Generate code for the Intel MCS51
5933 \begin_inset LatexCommand \index{MCS51}
5937 family of processors.
5938 This is the default processor target.
5941 \labelwidthstring 00.00.0000
5945 \begin_inset LatexCommand \index{-mds390}
5951 Generate code for the Dallas DS80C390
5952 \begin_inset LatexCommand \index{DS80C390}
5959 \labelwidthstring 00.00.0000
5963 \begin_inset LatexCommand \index{-mds400}
5969 Generate code for the Dallas DS80C400
5970 \begin_inset LatexCommand \index{DS80C400}
5977 \labelwidthstring 00.00.0000
5981 \begin_inset LatexCommand \index{-mhc08}
5987 Generate code for the Freescale/Motorola HC08
5988 \begin_inset LatexCommand \index{HC08}
5992 family of processors.
5995 \labelwidthstring 00.00.0000
5999 \begin_inset LatexCommand \index{-mz80}
6005 Generate code for the Zilog Z80
6006 \begin_inset LatexCommand \index{Z80}
6010 family of processors.
6013 \labelwidthstring 00.00.0000
6017 \begin_inset LatexCommand \index{-mgbz80}
6023 Generate code for the GameBoy Z80
6024 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6028 processor (Not actively maintained).
6031 \labelwidthstring 00.00.0000
6035 \begin_inset LatexCommand \index{-mavr}
6041 Generate code for the Atmel AVR
6042 \begin_inset LatexCommand \index{AVR}
6046 processor (Not maintained, not complete).
6047 AVR users should probably have a look at winavr
6048 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6053 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6064 I think it is fair to direct users there for now.
6065 Open source is also about avoiding unnecessary work .
6066 But I didn't find the 'official' link.
6073 \labelwidthstring 00.00.0000
6077 \begin_inset LatexCommand \index{-mpic14}
6083 Generate code for the Microchip PIC 14
6084 \begin_inset LatexCommand \index{PIC14}
6088 -bit processors (p16f84 and variants.
6089 In development, not complete).
6096 p16f627 p16f628 p16f84 p16f873 p16f877?
6103 \labelwidthstring 00.00.0000
6107 \begin_inset LatexCommand \index{-mpic16}
6113 Generate code for the Microchip PIC 16
6114 \begin_inset LatexCommand \index{PIC16}
6118 -bit processors (p18f452 and variants.
6119 In development, not complete).
6122 \labelwidthstring 00.00.0000
6127 Generate code for the Toshiba TLCS-900H
6128 \begin_inset LatexCommand \index{TLCS-900H}
6132 processor (Not maintained, not complete).
6135 \labelwidthstring 00.00.0000
6136 \added_space_bottom bigskip
6140 \begin_inset LatexCommand \index{-mxa51}
6146 Generate code for the Phillips XA51
6147 \begin_inset LatexCommand \index{XA51}
6151 processor (Not maintained, not complete).
6155 Preprocessor Options
6156 \begin_inset LatexCommand \index{Options preprocessor}
6161 \begin_inset LatexCommand \index{Preprocessor options}
6166 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6173 \labelwidthstring 00.00.0000
6177 \begin_inset LatexCommand \index{-I<path>}
6183 The additional location where the pre processor will look for <..h> or
6184 \begin_inset Quotes eld
6188 \begin_inset Quotes erd
6194 \labelwidthstring 00.00.0000
6198 \begin_inset LatexCommand \index{-D<macro[=value]>}
6204 Command line definition of macros.
6205 Passed to the preprocessor.
6208 \labelwidthstring 00.00.0000
6212 \begin_inset LatexCommand \index{-M}
6218 Tell the preprocessor to output a rule suitable for make describing the
6219 dependencies of each object file.
6220 For each source file, the preprocessor outputs one make-rule whose target
6221 is the object file name for that source file and whose dependencies are
6222 all the files `#include'd in it.
6223 This rule may be a single line or may be continued with `
6225 '-newline if it is long.
6226 The list of rules is printed on standard output instead of the preprocessed
6229 \begin_inset LatexCommand \index{-E}
6236 \labelwidthstring 00.00.0000
6240 \begin_inset LatexCommand \index{-C}
6246 Tell the preprocessor not to discard comments.
6247 Used with the `-E' option.
6250 \labelwidthstring 00.00.0000
6254 \begin_inset LatexCommand \index{-MM}
6265 Like `-M' but the output mentions only the user header files included with
6267 \begin_inset Quotes eld
6271 System header files included with `#include <file>' are omitted.
6274 \labelwidthstring 00.00.0000
6278 \begin_inset LatexCommand \index{-Aquestion(answer)}
6284 Assert the answer answer for question, in case it is tested with a preprocessor
6285 conditional such as `#if #question(answer)'.
6286 `-A-' disables the standard assertions that normally describe the target
6290 \labelwidthstring 00.00.0000
6294 \begin_inset LatexCommand \index{-Umacro}
6300 Undefine macro macro.
6301 `-U' options are evaluated after all `-D' options, but before any `-include'
6302 and `-imacros' options.
6305 \labelwidthstring 00.00.0000
6309 \begin_inset LatexCommand \index{-dM}
6315 Tell the preprocessor to output only a list of the macro definitions that
6316 are in effect at the end of preprocessing.
6317 Used with the `-E' option.
6320 \labelwidthstring 00.00.0000
6324 \begin_inset LatexCommand \index{-dD}
6330 Tell the preprocessor to pass all macro definitions into the output, in
6331 their proper sequence in the rest of the output.
6334 \labelwidthstring 00.00.0000
6338 \begin_inset LatexCommand \index{-dN}
6349 Like `-dD' except that the macro arguments and contents are omitted.
6350 Only `#define name' is included in the output.
6353 \labelwidthstring 00.00.0000
6356 -pedantic-parse-number
6357 \begin_inset LatexCommand \index{-pedantic-parse-number}
6368 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6369 and the macro LO_B(3) gets expanded.
6370 See also #pragma pedantic_parse_number in section
6371 \begin_inset LatexCommand \ref{sec:Pragmas}
6377 Note: this functionality is not in conformance with standard!
6380 \labelwidthstring 00.00.0000
6381 \added_space_bottom bigskip
6385 preprocessorOption[,preprocessorOption]
6388 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6393 Pass the preprocessorOption to the preprocessor
6398 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6403 SDCC uses an adapted version of the preprocessor
6407 of the GNU Compiler Collection
6408 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6417 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6421 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6426 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6435 \begin_inset LatexCommand \index{Options linker}
6440 \begin_inset LatexCommand \index{Linker options}
6447 \labelwidthstring 00.00.0000
6468 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6473 \begin_inset LatexCommand \index{-L -\/-lib-path}
6480 <absolute path to additional libraries> This option is passed to the linkage
6481 editor's additional libraries
6482 \begin_inset LatexCommand \index{Libraries}
6487 The path name must be absolute.
6488 Additional library files may be specified in the command line.
6489 See section Compiling programs for more details.
6492 \labelwidthstring 00.00.0000
6510 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6515 <Value> The start location of the external ram
6516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6520 , default value is 0.
6521 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6533 -xram-loc 0x8000 or -
6548 \labelwidthstring 00.00.0000
6566 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6571 <Value> The start location of the code
6572 \begin_inset LatexCommand \index{code}
6576 segment, default value 0.
6577 Note when this option is used the interrupt vector table
6578 \begin_inset LatexCommand \index{interrupt vector table}
6582 is also relocated to the given address.
6583 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6595 -code-loc 0x8000 or -
6610 \labelwidthstring 00.00.0000
6628 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6633 <Value> By default the stack
6634 \begin_inset LatexCommand \index{stack}
6638 is placed after the data segment.
6639 Using this option the stack can be placed anywhere in the internal memory
6641 The value entered can be in Hexadecimal or Decimal format, e.g.
6654 -stack-loc 0x20 or -
6667 Since the sp register is incremented before a push or call, the initial
6668 sp will be set to one byte prior the provided value.
6669 The provided value should not overlap any other memory areas such as used
6670 register banks or the data segment and with enough space for the current
6690 \begin_inset LatexCommand \index{-\/-pack-iram}
6694 option (which is now a default setting) will override this setting, so
6695 you should also specify the
6713 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6717 option if you need to manually place the stack.
6720 \labelwidthstring 00.00.0000
6738 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6743 <Value> By default the external stack
6744 \begin_inset LatexCommand \index{xstack}
6748 is placed after the pdata
6749 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6754 Using this option the xstack can be placed anywhere in the external memory
6756 The value entered can be in Hexadecimal or Decimal format, e.g.
6769 -xstack-loc 0x8000 or -
6782 The provided value should not overlap any other memory areas such as the
6783 pdata or xdata segment and with enough space for the current application.
6786 \labelwidthstring 00.00.0000
6804 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6809 <Value> The start location of the internal ram data
6810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6815 The value entered can be in Hexadecimal or Decimal format, eg.
6841 (By default, the start location of the internal ram data segment is set
6842 as low as possible in memory, taking into account the used register banks
6843 and the bit segment at address 0x20.
6844 For example if register banks 0 and 1 are used without bit variables, the
6845 data segment will be set, if -
6857 -data-loc is not used, to location 0x10.)
6860 \labelwidthstring 00.00.0000
6878 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6883 <Value> The start location of the indirectly addressable internal ram
6884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6888 of the 8051, default value is 0x80.
6889 The value entered can be in Hexadecimal or Decimal format, eg.
6902 -idata-loc 0x88 or -
6917 \labelwidthstring 00.00.0000
6935 <Value> The start location of the bit
6936 \begin_inset LatexCommand \index{bit}
6940 addressable internal ram of the 8051.
6946 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6950 \labelwidthstring 00.00.0000
6966 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6975 The linker output (final object code) is in Intel Hex format.
6976 \begin_inset LatexCommand \index{Intel hex format}
6980 This is the default option.
6981 The format itself is documented in the documentation of srecord
6982 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6989 \labelwidthstring 00.00.0000
7005 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7014 The linker output (final object code) is in Motorola S19 format
7015 \begin_inset LatexCommand \index{Motorola S19 format}
7020 The format itself is documented in the documentation of srecord.
7023 \labelwidthstring 00.00.0000
7039 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7044 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7053 The linker output (final object code) is in ELF format
7054 \begin_inset LatexCommand \index{ELF format}
7059 (Currently only supported for the HC08
7060 \begin_inset LatexCommand \index{HC08}
7067 \labelwidthstring 00.00.0000
7068 \added_space_bottom bigskip
7072 linkOption[,linkOption]
7075 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7080 Pass the linkOption to the linker.
7081 If a bootloader is used an option like
7082 \begin_inset Quotes sld
7087 \begin_inset Quotes srd
7090 would be typical to set the start of the code segment.
7091 See also #pragma constseg and #pragma codeseg in section
7092 \begin_inset LatexCommand \ref{sec:Pragmas}
7097 File sdcc/as/doc/asxhtm.html has more on linker options.
7102 \begin_inset LatexCommand \index{Options MCS51}
7107 \begin_inset LatexCommand \index{MCS51 options}
7114 \labelwidthstring 00.00.0000
7130 \begin_inset LatexCommand \index{-\/-model-small}
7141 Generate code for Small Model programs, see section Memory Models for more
7143 This is the default model.
7146 \labelwidthstring 00.00.0000
7162 \begin_inset LatexCommand \index{-\/-model-medium}
7168 Generate code for Medium model programs, see section Memory Models for
7170 If this option is used all source files in the project have to be compiled
7172 It must also be used when invoking the linker.
7175 \labelwidthstring 00.00.0000
7191 \begin_inset LatexCommand \index{-\/-model-large}
7197 Generate code for Large model programs, see section Memory Models for more
7199 If this option is used all source files in the project have to be compiled
7201 It must also be used when invoking the linker.
7204 \labelwidthstring 00.00.0000
7220 \begin_inset LatexCommand \index{-\/-xstack}
7226 Uses a pseudo stack in the pdata
7227 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7231 area (usually the first 256 bytes in the external ram) for allocating variables
7232 and passing parameters.
7234 \begin_inset LatexCommand \ref{sub:External-Stack}
7239 External Stack for more details.
7242 \labelwidthstring 00.00.0000
7261 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7265 Causes the linker to check if the internal ram usage is within limits of
7269 \labelwidthstring 00.00.0000
7288 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7292 Causes the linker to check if the external ram usage is within limits of
7296 \labelwidthstring 00.00.0000
7315 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7319 Causes the linker to check if the code memory usage is within limits of
7323 \labelwidthstring 00.00.0000
7342 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7346 Causes the linker to check if there is at minimum <Value> bytes for stack.
7349 \labelwidthstring 00.00.0000
7368 \begin_inset LatexCommand \index{-\/-pack-iram}
7372 Causes the linker to use unused register banks for data variables and pack
7373 data, idata and stack together.
7374 This is the default now.
7377 \labelwidthstring 00.00.0000
7378 \added_space_bottom bigskip
7397 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7401 Causes the linker to use old style for allocating memory areas.
7405 DS390 / DS400 Options
7406 \begin_inset LatexCommand \index{Options DS390}
7411 \begin_inset LatexCommand \index{DS390}
7418 \labelwidthstring 00.00.0000
7436 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7446 Generate 24-bit flat mode code.
7447 This is the one and only that the ds390 code generator supports right now
7448 and is default when using
7453 See section Memory Models for more details.
7456 \labelwidthstring 00.00.0000
7472 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7478 disable interrupts during ESP:SP updates.
7481 \labelwidthstring 00.00.0000
7499 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7503 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7504 This is the one and only that the ds390 code generator supports right now
7505 and is default when using
7510 In this mode, the stack is located in the lower 1K of the internal RAM,
7511 which is mapped to 0x400000.
7512 Note that the support is incomplete, since it still uses a single byte
7513 as the stack pointer.
7514 This means that only the lower 256 bytes of the potential 1K stack space
7515 will actually be used.
7516 However, this does allow you to reclaim the precious 256 bytes of low RAM
7517 for use for the DATA and IDATA segments.
7518 The compiler will not generate any code to put the processor into 10 bit
7520 It is important to ensure that the processor is in this mode before calling
7521 any re-entrant functions compiled with this option.
7522 In principle, this should work with the
7537 \begin_inset LatexCommand \index{-\/-stack-auto}
7543 option, but that has not been tested.
7544 It is incompatible with the
7559 \begin_inset LatexCommand \index{-\/-xstack}
7566 It also only makes sense if the processor is in 24 bit contiguous addressing
7581 -model-flat24 option
7586 \labelwidthstring 00.00.0000
7602 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7608 insert call to function __stack_probe at each function prologue.
7611 \labelwidthstring 00.00.0000
7627 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7633 <nnnn> LibraryID used in -mTININative.
7637 \labelwidthstring 00.00.0000
7638 \added_space_bottom bigskip
7654 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7660 generate code for DS390 Arithmetic Accelerator.
7666 \begin_inset LatexCommand \index{Options Z80}
7671 \begin_inset LatexCommand \index{Z80}
7678 \labelwidthstring 00.00.0000
7696 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7706 Force a called function to always save BC.
7709 \labelwidthstring 00.00.0000
7710 \added_space_bottom bigskip
7728 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7732 When linking, skip the standard crt0.o object file.
7733 You must provide your own crt0.o for your system when linking.
7738 Optimization Options
7739 \begin_inset LatexCommand \index{Options optimization}
7744 \begin_inset LatexCommand \index{Optimization options}
7751 \labelwidthstring 00.00.0000
7767 \begin_inset LatexCommand \index{-\/-nogcse}
7773 Will not do global subexpression elimination, this option may be used when
7774 the compiler creates undesirably large stack/data spaces to store compiler
7784 \begin_inset LatexCommand \index{sloc (spill location)}
7789 A warning message will be generated when this happens and the compiler
7790 will indicate the number of extra bytes it allocated.
7791 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7793 \begin_inset LatexCommand \index{\#pragma nogcse}
7797 can be used to turn off global subexpression elimination
7798 \begin_inset LatexCommand \index{Subexpression elimination}
7802 for a given function only.
7805 \labelwidthstring 00.00.0000
7821 \begin_inset LatexCommand \index{-\/-noinvariant}
7827 Will not do loop invariant optimizations, this may be turned off for reasons
7828 explained for the previous option.
7829 For more details of loop optimizations performed see Loop Invariants in
7831 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7836 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7838 \begin_inset LatexCommand \index{\#pragma noinvariant}
7842 can be used to turn off invariant optimizations for a given function only.
7845 \labelwidthstring 00.00.0000
7861 \begin_inset LatexCommand \index{-\/-noinduction}
7867 Will not do loop induction optimizations, see section strength reduction
7869 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7871 \begin_inset LatexCommand \index{\#pragma noinduction}
7875 can be used to turn off induction optimizations for a given function only.
7878 \labelwidthstring 00.00.0000
7894 \begin_inset LatexCommand \index{-\/-nojtbound}
7905 Will not generate boundary condition check when switch statements
7906 \begin_inset LatexCommand \index{switch statement}
7910 are implemented using jump-tables.
7912 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7917 Switch Statements for more details.
7918 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7920 \begin_inset LatexCommand \index{\#pragma nojtbound}
7924 can be used to turn off boundary checking for jump tables for a given function
7928 \labelwidthstring 00.00.0000
7944 \begin_inset LatexCommand \index{-\/-noloopreverse}
7953 Will not do loop reversal
7954 \begin_inset LatexCommand \index{Loop reversing}
7961 \labelwidthstring 00.00.0000
7979 \begin_inset LatexCommand \index{-\/-nolabelopt }
7983 Will not optimize labels (makes the dumpfiles more readable).
7986 \labelwidthstring 00.00.0000
8002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8008 Will not memcpy initialized data from code space into xdata space.
8009 This saves a few bytes in code space if you don't have initialized data
8010 \begin_inset LatexCommand \index{Variable initialization}
8017 \labelwidthstring 00.00.0000
8033 \begin_inset LatexCommand \index{-\/-nooverlay}
8039 The compiler will not overlay parameters and local variables of any function,
8040 see section Parameters and local variables for more details.
8043 \labelwidthstring 00.00.0000
8059 \begin_inset LatexCommand \index{-\/-no-peep}
8065 Disable peep-hole optimization with built-in rules.
8068 \labelwidthstring 00.00.0000
8086 \begin_inset LatexCommand \index{-\/-peep-file}
8091 <filename> This option can be used to use additional rules to be used by
8092 the peep hole optimizer.
8094 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8099 Peep Hole optimizations for details on how to write these rules.
8102 \labelwidthstring 00.00.0000
8118 \begin_inset LatexCommand \index{-\/-peep-asm}
8124 Pass the inline assembler code through the peep hole optimizer.
8125 This can cause unexpected changes to inline assembler code, please go through
8126 the peephole optimizer
8127 \begin_inset LatexCommand \index{Peephole optimizer}
8131 rules defined in the source file tree '<target>/peeph.def' before using
8135 \labelwidthstring 00.00.0000
8151 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8157 The compiler will optimize code generation towards fast code, possibly
8158 at the expense of code size.
8161 \labelwidthstring 00.00.0000
8162 \added_space_bottom bigskip
8178 \begin_inset LatexCommand \index{-\/-opt-code-size}
8184 The compiler will optimize code generation towards compact code, possibly
8185 at the expense of code speed.
8190 \begin_inset LatexCommand \index{Options other}
8197 \labelwidthstring 00.00.0000
8214 \begin_inset LatexCommand \index{-\/-compile-only}
8219 \begin_inset LatexCommand \index{-c -\/-compile-only}
8225 will compile and assemble the source, but will not call the linkage editor.
8228 \labelwidthstring 00.00.0000
8248 \begin_inset LatexCommand \index{-\/-c1mode}
8254 reads the preprocessed source from standard input and compiles it.
8255 The file name for the assembler output must be specified using the -o option.
8258 \labelwidthstring 00.00.0000
8262 \begin_inset LatexCommand \index{-E}
8268 Run only the C preprocessor.
8269 Preprocess all the C source files specified and output the results to standard
8273 \labelwidthstring 00.00.0000
8278 \begin_inset LatexCommand \index{-o <path/file>}
8284 The output path resp.
8285 file where everything will be placed.
8286 If the parameter is a path, it must have a trailing slash (or backslash
8287 for the Windows binaries) to be recognized as a path.
8291 \labelwidthstring 00.00.0000
8307 \begin_inset LatexCommand \index{-\/-stack-auto}
8318 All functions in the source file will be compiled as
8323 \begin_inset LatexCommand \index{reentrant}
8328 the parameters and local variables will be allocated on the stack
8329 \begin_inset LatexCommand \index{stack}
8335 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8339 Parameters and Local Variables for more details.
8340 If this option is used all source files in the project should be compiled
8342 It automatically implies --int-long-reent and --float-reent.
8346 \labelwidthstring 00.00.0000
8362 \begin_inset LatexCommand \index{-\/-callee-saves}
8366 function1[,function2][,function3]....
8369 The compiler by default uses a caller saves convention for register saving
8370 across function calls, however this can cause unnecessary register pushing
8371 & popping when calling small functions from larger functions.
8372 This option can be used to switch the register saving convention for the
8373 function names specified.
8374 The compiler will not save registers when calling these functions, no extra
8375 code will be generated at the entry & exit (function prologue
8378 \begin_inset LatexCommand \index{function prologue}
8387 \begin_inset LatexCommand \index{function epilogue}
8393 ) for these functions to save & restore the registers used by these functions,
8394 this can SUBSTANTIALLY reduce code & improve run time performance of the
8396 In the future the compiler (with inter procedural analysis) will be able
8397 to determine the appropriate scheme to use for each function call.
8398 DO NOT use this option for built-in functions such as _mulint..., if this
8399 option is used for a library function the appropriate library function
8400 needs to be recompiled with the same option.
8401 If the project consists of multiple source files then all the source file
8402 should be compiled with the same -
8414 -callee-saves option string.
8415 Also see #pragma\SpecialChar ~
8417 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8424 \labelwidthstring 00.00.0000
8440 \begin_inset LatexCommand \index{-\/-debug}
8449 When this option is used the compiler will generate debug information.
8450 The debug information collected in a file with .cdb extension can be used
8452 For more information see documentation for SDCDB.
8453 Another file with no extension contains debug information in AOMF or AOMF51
8454 \begin_inset LatexCommand \index{AOMF, AOMF51}
8458 format which is commonly used by third party tools.
8461 \labelwidthstring 00.00.0000
8465 \begin_inset LatexCommand \index{-S}
8476 Stop after the stage of compilation proper; do not assemble.
8477 The output is an assembler code file for the input file specified.
8480 \labelwidthstring 00.00.0000
8496 \begin_inset LatexCommand \index{-\/-int-long-reent}
8502 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8503 Note by default these libraries are compiled as non-reentrant.
8504 See section Installation for more details.
8507 \labelwidthstring 00.00.0000
8523 \begin_inset LatexCommand \index{-\/-cyclomatic}
8532 This option will cause the compiler to generate an information message for
8533 each function in the source file.
8534 The message contains some
8538 information about the function.
8539 The number of edges and nodes the compiler detected in the control flow
8540 graph of the function, and most importantly the
8542 cyclomatic complexity
8543 \begin_inset LatexCommand \index{Cyclomatic complexity}
8549 see section on Cyclomatic Complexity for more details.
8552 \labelwidthstring 00.00.0000
8568 \begin_inset LatexCommand \index{-\/-float-reent}
8574 Floating point library is compiled as reentrant
8575 \begin_inset LatexCommand \index{reentrant}
8580 See section Installation for more details.
8583 \labelwidthstring 00.00.0000
8599 \begin_inset LatexCommand \index{-\/-funsigned-char}
8605 The default signedness for every type is
8610 In some embedded environments the default signedness of
8619 To set the signess for characters to unsigned, use the option --funsigned-char.
8620 If this option is set and no signedness keyword (unsigned/signed) is given,
8621 a char will be signed.
8622 All other types are unaffected.
8625 \labelwidthstring 00.00.0000
8641 \begin_inset LatexCommand \index{-\/-main-return}
8647 This option can be used if the code generated is called by a monitor program
8648 or if the main routine includes an endless loop.
8649 This option results in slightly smaller code and saves two bytes of stack
8651 The return from the 'main'
8652 \begin_inset LatexCommand \index{main return}
8656 function will return to the function calling main.
8657 The default setting is to lock up i.e.
8665 \labelwidthstring 00.00.0000
8681 \begin_inset LatexCommand \index{-\/-nostdinc}
8687 This will prevent the compiler from passing on the default include path
8688 to the preprocessor.
8691 \labelwidthstring 00.00.0000
8707 \begin_inset LatexCommand \index{-\/-nostdlib}
8713 This will prevent the compiler from passing on the default library
8714 \begin_inset LatexCommand \index{Libraries}
8721 \labelwidthstring 00.00.0000
8737 \begin_inset LatexCommand \index{-\/-verbose}
8743 Shows the various actions the compiler is performing.
8746 \labelwidthstring 00.00.0000
8750 \begin_inset LatexCommand \index{-V}
8756 Shows the actual commands the compiler is executing.
8759 \labelwidthstring 00.00.0000
8775 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8781 Hides your ugly and inefficient c-code from the asm file, so you can always
8782 blame the compiler :)
8785 \labelwidthstring 00.00.0000
8801 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8807 Will not include peep-hole comments in the generated files.
8810 \labelwidthstring 00.00.0000
8826 \begin_inset LatexCommand \index{-\/-no-gen-comments}
8832 Will not include code generator comments in the generated files.
8835 \labelwidthstring 00.00.0000
8851 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8857 Include i-codes in the asm file.
8858 Sounds like noise but is most helpful for debugging the compiler itself.
8861 \labelwidthstring 00.00.0000
8877 \begin_inset LatexCommand \index{-\/-less-pedantic}
8883 Disable some of the more pedantic warnings
8884 \begin_inset LatexCommand \index{Warnings}
8888 (jwk burps: please be more specific here, please!).
8891 \labelwidthstring 00.00.0000
8906 -disable-warning\SpecialChar ~
8908 \begin_inset LatexCommand \index{-\/-disable-warning}
8914 Disable specific warning with number <nnnn>.
8917 \labelwidthstring 00.00.0000
8933 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8939 Display the directories in the compiler's search path
8942 \labelwidthstring 00.00.0000
8958 \begin_inset LatexCommand \index{-\/-vc}
8964 Display errors and warnings using MSVC style, so you can use SDCC with
8965 the visual studio IDE
8966 \begin_inset LatexCommand \index{IDE}
8971 With SDCC both offering a GCC-like (the default) and a MSVC-like
8972 \begin_inset LatexCommand \index{MSVC output style}
8976 output style, integration into most programming editors should be straightforwa
8980 \labelwidthstring 00.00.0000
8996 \begin_inset LatexCommand \index{-\/-use-stdout}
9002 Send errors and warnings to stdout instead of stderr.
9005 \labelwidthstring 00.00.0000
9009 asmOption[,asmOption]
9012 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9017 Pass the asmOption to the assembler
9018 \begin_inset LatexCommand \index{Options assembler}
9023 \begin_inset LatexCommand \index{Assembler options}
9028 See file sdcc/as/doc/asxhtm.html for assembler options.cd
9031 \labelwidthstring 00.00.0000
9047 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9053 Generally follow the C89 standard, but allow SDCC features that conflict
9054 with the standard (default).
9057 \labelwidthstring 00.00.0000
9073 \begin_inset LatexCommand \index{-\/-std-c89}
9079 Follow the C89 standard and disable SDCC features that conflict with the
9083 \labelwidthstring 00.00.0000
9099 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9105 Generally follow the C99 standard, but allow SDCC features that conflict
9106 with the standard (incomplete support).
9109 \labelwidthstring 00.00.0000
9125 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9131 Follow the C99 standard and disable SDCC features that conflict with the
9132 standard (incomplete support).
9135 \labelwidthstring 00.00.0000
9153 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9158 <Name> The name to be used for the code
9159 \begin_inset LatexCommand \index{code}
9163 segment, default CSEG.
9164 This is useful if you need to tell the compiler to put the code in a special
9165 segment so you can later on tell the linker to put this segment in a special
9167 Can be used for instance when using bank switching to put the code in a
9171 \labelwidthstring 00.00.0000
9189 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9194 <Name> The name to be used for the const
9195 \begin_inset LatexCommand \index{code}
9199 segment, default CONST.
9200 This is useful if you need to tell the compiler to put the const data in
9201 a special segment so you can later on tell the linker to put this segment
9202 in a special place in memory.
9203 Can be used for instance when using bank switching to put the const data
9207 \labelwidthstring 00.00.0000
9222 -fdollars-in-identifiers
9223 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9229 Permit '$' as an identifier character
9232 \labelwidthstring 00.00.0000
9233 \added_space_bottom bigskip
9244 a SDCC compiler option but if you want
9248 warnings you can use a separate tool dedicated to syntax checking like
9250 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9255 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9260 \begin_inset LatexCommand \url{http://www.splint.org}
9265 To make your source files parseable by splint you will have to include
9271 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9275 in your source file and add brackets around extended keywords (like
9278 \begin_inset Quotes sld
9291 \begin_inset Quotes srd
9299 \begin_inset Quotes sld
9302 __interrupt\SpecialChar ~
9304 \begin_inset Quotes srd
9312 Splint has an excellent on line manual at
9313 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9317 and it's capabilities go beyond pure syntax checking.
9318 You'll need to tell splint the location of SDCC's include files so a typical
9319 command line could look like this:
9323 splint\SpecialChar ~
9325 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9331 Intermediate Dump Options
9332 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9337 \begin_inset LatexCommand \index{Options intermediate dump}
9342 \begin_inset LatexCommand \index{Intermediate dump options}
9349 The following options are provided for the purpose of retargetting and debugging
9351 They provide a means to dump the intermediate code (iCode
9352 \begin_inset LatexCommand \index{iCode}
9356 ) generated by the compiler in human readable form at various stages of
9357 the compilation process.
9358 More on iCodes see chapter
9359 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9364 \begin_inset Quotes srd
9367 The anatomy of the compiler
9368 \begin_inset Quotes srd
9374 \labelwidthstring 00.00.0000
9390 \begin_inset LatexCommand \index{-\/-dumpraw}
9396 This option will cause the compiler to dump the intermediate code into
9399 <source filename>.dumpraw
9401 just after the intermediate code has been generated for a function, i.e.
9402 before any optimizations are done.
9404 \begin_inset LatexCommand \index{Basic blocks}
9408 at this stage ordered in the depth first number, so they may not be in
9409 sequence of execution.
9412 \labelwidthstring 00.00.0000
9428 \begin_inset LatexCommand \index{-\/-dumpgcse}
9434 Will create a dump of iCode's, after global subexpression elimination
9435 \begin_inset LatexCommand \index{Global subexpression elimination}
9441 <source filename>.dumpgcse.
9444 \labelwidthstring 00.00.0000
9460 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9466 Will create a dump of iCode's, after deadcode elimination
9467 \begin_inset LatexCommand \index{Dead-code elimination}
9473 <source filename>.dumpdeadcode.
9476 \labelwidthstring 00.00.0000
9492 \begin_inset LatexCommand \index{-\/-dumploop}
9501 Will create a dump of iCode's, after loop optimizations
9502 \begin_inset LatexCommand \index{Loop optimization}
9508 <source filename>.dumploop.
9511 \labelwidthstring 00.00.0000
9527 \begin_inset LatexCommand \index{-\/-dumprange}
9536 Will create a dump of iCode's, after live range analysis
9537 \begin_inset LatexCommand \index{Live range analysis}
9543 <source filename>.dumprange.
9546 \labelwidthstring 00.00.0000
9562 \begin_inset LatexCommand \index{-\/-dumlrange}
9568 Will dump the life ranges
9569 \begin_inset LatexCommand \index{Live range analysis}
9576 \labelwidthstring 00.00.0000
9592 \begin_inset LatexCommand \index{-\/-dumpregassign}
9601 Will create a dump of iCode's, after register assignment
9602 \begin_inset LatexCommand \index{Register assignment}
9608 <source filename>.dumprassgn.
9611 \labelwidthstring 00.00.0000
9627 \begin_inset LatexCommand \index{-\/-dumplrange}
9633 Will create a dump of the live ranges of iTemp's
9636 \labelwidthstring 00.00.0000
9637 \added_space_bottom bigskip
9653 \begin_inset LatexCommand \index{-\/-dumpall}
9664 Will cause all the above mentioned dumps to be created.
9668 Redirecting output on Windows Shells
9671 \added_space_bottom bigskip
9672 By default SDCC writes it's error messages to
9673 \begin_inset Quotes sld
9677 \begin_inset Quotes srd
9681 To force all messages to
9682 \begin_inset Quotes sld
9686 \begin_inset Quotes srd
9712 \begin_inset LatexCommand \index{-\/-use-stdout}
9717 Additionally, if you happen to have visual studio installed in your windows
9718 machine, you can use it to compile your sources using a custom build and
9736 \begin_inset LatexCommand \index{-\/-vc}
9741 Something like this should work:
9789 -model-large -c $(InputPath)
9796 Environment variables
9797 \begin_inset LatexCommand \index{Environment variables}
9804 SDCC recognizes the following environment variables:
9807 \labelwidthstring 00.00.0000
9811 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9817 SDCC installs a signal handler
9818 \begin_inset LatexCommand \index{signal handler}
9822 to be able to delete temporary files after an user break (^C) or an exception.
9823 If this environment variable is set, SDCC won't install the signal handler
9824 in order to be able to debug SDCC.
9827 \labelwidthstring 00.00.0000
9833 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9839 Path, where temporary files will be created.
9840 The order of the variables is the search order.
9841 In a standard *nix environment these variables are not set, and there's
9842 no need to set them.
9843 On Windows it's recommended to set one of them.
9846 \labelwidthstring 00.00.0000
9850 \begin_inset LatexCommand \index{SDCC\_HOME}
9857 \begin_inset LatexCommand \ref{sub:Install-paths}
9863 \begin_inset Quotes sld
9867 \begin_inset Quotes srd
9873 \labelwidthstring 00.00.0000
9877 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9884 \begin_inset LatexCommand \ref{sub:Search-Paths}
9890 \begin_inset Quotes sld
9894 \begin_inset Quotes srd
9900 \labelwidthstring 00.00.0000
9904 \begin_inset LatexCommand \index{SDCC\_LIB}
9911 \begin_inset LatexCommand \ref{sub:Search-Paths}
9917 \begin_inset Quotes sld
9921 \begin_inset Quotes srd
9927 \added_space_bottom bigskip
9928 There are some more environment variables recognized by SDCC, but these
9929 are solely used for debugging purposes.
9930 They can change or disappear very quickly, and will never be documented.
9935 Storage Class Language Extensions
9938 MCS51/DS390 Storage Class
9939 \begin_inset LatexCommand \index{Storage class}
9946 In addition to the ANSI storage classes SDCC allows the following MCS51
9947 specific storage classes:
9949 \layout Subsubsection
9951 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9956 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9961 \begin_inset LatexCommand \index{near (storage class)}
9966 \begin_inset LatexCommand \index{\_\_near (storage class)}
9977 storage class for the Small Memory model (
9985 or the more ANSI-C compliant forms
9993 can be used synonymously).
9994 Variables declared with this storage class will be allocated in the directly
9995 addressable portion of the internal RAM of a 8051, e.g.:
10000 __data unsigned char test_data;
10003 Writing 0x01 to this variable generates the assembly code:
10008 75*00 01\SpecialChar ~
10015 \layout Subsubsection
10017 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10022 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10027 \begin_inset LatexCommand \index{far (storage class)}
10032 \begin_inset LatexCommand \index{\_\_far (storage class)}
10039 Variables declared with this storage class will be placed in the external
10045 storage class for the Large Memory model, e.g.:
10050 __xdata unsigned char test_xdata;
10053 Writing 0x01 to this variable generates the assembly code:
10058 90s00r00\SpecialChar ~
10088 \layout Subsubsection
10090 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10095 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10102 Variables declared with this storage class will be allocated into the indirectly
10103 addressable portion of the internal ram of a 8051, e.g.:
10108 __idata unsigned char test_idata;
10111 Writing 0x01 to this variable generates the assembly code:
10116 78r00\SpecialChar ~
10140 Please note, the first 128 byte of idata physically access the same RAM
10141 as the data memory.
10142 The original 8051 had 128 byte idata memory, nowadays most devices have
10143 256 byte idata memory.
10145 \begin_inset LatexCommand \index{stack}
10149 is located in idata memory.
10151 \layout Subsubsection
10153 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10158 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10165 Paged xdata access is just as straightforward as using the other addressing
10167 It is typically located at the start of xdata and has a maximum size of
10169 The following example writes 0x01 to the pdata variable.
10170 Please note, pdata access physically accesses xdata memory.
10171 The high byte of the address is determined by port P2
10172 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10176 (or in case of some 8051 variants by a separate Special Function Register,
10178 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10187 storage class for the Medium Memory model, e.g.:
10192 __pdata unsigned char test_pdata;
10195 Writing 0x01 to this variable generates the assembly code:
10200 78r00\SpecialChar ~
10206 mov r0,#_test_pdata
10208 74 01\SpecialChar ~
10241 \begin_inset LatexCommand \index{-\/-xstack}
10245 option is used the pdata memory area is followed by the xstack memory area
10246 and the sum of their sizes is limited to 256 bytes.
10248 \layout Subsubsection
10250 \begin_inset LatexCommand \index{code}
10255 \begin_inset LatexCommand \index{\_\_code}
10262 'Variables' declared with this storage class will be placed in the code
10268 __code unsigned char test_code;
10271 Read access to this variable generates the assembly code:
10276 90s00r6F\SpecialChar ~
10279 mov dptr,#_test_code
10308 indexed arrays of characters in code memory can be accessed efficiently:
10313 __code char test_array[] = {'c','h','e','a','p'};
10316 Read access to this array using an 8-bit unsigned index generates the assembly
10322 E5*00\SpecialChar ~
10333 90s00r41\SpecialChar ~
10336 mov dptr,#_test_array
10352 \layout Subsubsection
10354 \begin_inset LatexCommand \index{bit}
10359 \begin_inset LatexCommand \index{\_\_bit}
10366 This is a data-type and a storage class specifier.
10367 When a variable is declared as a bit, it is allocated into the bit addressable
10368 memory of 8051, e.g.:
10376 Writing 1 to this variable generates the assembly code:
10381 D2*00\SpecialChar ~
10392 The bit addressable memory consists of 128 bits which are located from 0x20
10393 to 0x2f in data memory.
10396 Apart from this 8051 specific storage class most architectures support
10398 \begin_inset LatexCommand \index{bitfields}
10407 Not really meant as examples, but nevertheless showing what bitfields are
10408 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10413 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10414 signed modifier are implemented as unsigned.
10416 \layout Subsubsection
10418 \begin_inset LatexCommand \index{sfr}
10423 \begin_inset LatexCommand \index{\_\_sfr}
10428 \begin_inset LatexCommand \index{sfr16}
10433 \begin_inset LatexCommand \index{\_\_sfr16}
10438 \begin_inset LatexCommand \index{sfr32}
10443 \begin_inset LatexCommand \index{\_\_sfr32}
10448 \begin_inset LatexCommand \index{\_\_sbit}
10453 \begin_inset LatexCommand \index{sbit}
10460 Like the bit keyword,
10462 sfr / sfr16 / sfr32 / sbit
10464 signify both a data-type and storage class, they are used to describe the
10485 variables of a 8051, eg:
10491 \begin_inset LatexCommand \index{at}
10496 \begin_inset LatexCommand \index{\_\_at}
10500 (0x80) P0;\SpecialChar ~
10501 /* special function register P0 at location 0x80 */
10506 special function register combination for timer 0
10510 with the high byte at
10511 location 0x8C and the low byte at location 0x8A */
10513 __sfr16 __at (0x8C8A)
10519 \begin_inset LatexCommand \index{at}
10524 \begin_inset LatexCommand \index{\_\_at}
10528 (0xd7) CY;\SpecialChar ~
10530 \begin_inset LatexCommand \index{Flags}
10535 \begin_inset LatexCommand \index{Carry flag}
10542 Special function registers which are located on an address dividable by
10543 8 are bit-addressable, an
10547 addresses a specific bit within these sfr.
10549 16 Bit and 32 bit special function
10550 register combinations which require a certain access order are better not
10560 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10561 this is not guaranteed.
10566 Please note, if you use a header file which was written for another compiler
10567 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10573 Specifically the syntax
10576 sfr P0 = 0x80;\SpecialChar ~
10583 by SDCC to an assignment of 0x80 to a variable called P0
10586 \begin_inset Marginal
10600 Nevertheless it is possible to write header files
10601 \begin_inset LatexCommand \index{Header files}
10606 \begin_inset LatexCommand \index{Include files}
10610 which can be shared among different compilers (see section
10611 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10618 \layout Subsubsection
10620 \begin_inset LatexCommand \index{Pointer}
10624 to MCS51/DS390 specific memory spaces
10627 SDCC allows (via language extensions) pointers to explicitly point to any
10628 of the memory spaces
10629 \begin_inset LatexCommand \index{Memory model}
10634 In addition to the explicit pointers, the compiler uses (by default) generic
10635 pointers which can be used to point to any of the memory spaces.
10640 declaration examples:
10645 /* pointer physically in internal ram pointing to object in external ram
10648 __xdata unsigned char * __data p;
10652 /* pointer physically in external ram
10653 pointing to object in internal ram */
10655 __data unsigned char * __xdata p;
10660 pointer physically in code rom pointing to data in xdata space */
10663 unsigned char * __code p;
10667 /* pointer physically in code space pointing to
10668 data in code space */
10670 __code unsigned char * __code p;
10675 physically located in xdata space */
10677 unsigned char * __xdata p;
10682 pointer physically located in default memory space */
10689 the following is a function pointer
10690 \begin_inset LatexCommand \index{function pointer}
10694 physically located in data space */
10696 char (* __data fp)(void);
10699 Well you get the idea.
10704 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
10717 The highest order byte of the
10721 pointers contains the data space information.
10722 Assembler support routines are called whenever data is stored or retrieved
10728 These are useful for developing reusable library
10729 \begin_inset LatexCommand \index{Libraries}
10734 Explicitly specifying the pointer
10735 \begin_inset LatexCommand \index{pointer}
10739 type will generate the most efficient code.
10741 \layout Subsubsection
10742 Notes on MCS51 memory
10743 \begin_inset LatexCommand \index{MCS51 memory}
10750 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10751 RAM memory which is structured as follows:
10755 - Bytes 00-1F - 32 bytes to hold
10756 up to 4 banks of the registers R0 to R7,
10758 - Bytes 20-2F - 16 bytes to hold
10760 \begin_inset LatexCommand \index{bit}
10766 - Bytes 30-7F - 80 bytes for general purpose use.
10771 Additionally some members of the MCS51 family may have up to 128 bytes of
10772 additional, indirectly addressable, internal RAM memory (
10777 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10782 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10787 Furthermore, some chips may have some built in external memory (
10792 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10797 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10801 ) which should not be confused with the internal, directly addressable RAM
10807 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10812 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10817 Sometimes this built in
10821 memory has to be activated before using it (you can probably find this
10822 information on the datasheet of the microcontroller your are using, see
10824 \begin_inset LatexCommand \ref{sub:Startup-Code}
10832 Normally SDCC will only use the first bank
10833 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10837 of registers (register bank 0), but it is possible to specify that other
10838 banks of registers (keyword
10845 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10850 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10856 ) should be used in interrupt
10857 \begin_inset LatexCommand \index{interrupt}
10862 \begin_inset LatexCommand \index{\_\_interrupt}
10867 By default, the compiler will place the stack after the last byte of allocated
10868 memory for variables.
10869 For example, if the first 2 banks of registers are used, and only four
10874 variables, it will position the base of the internal stack at address 20
10876 This implies that as the stack
10877 \begin_inset LatexCommand \index{stack}
10881 grows, it will use up the remaining register banks, and the 16 bytes used
10882 by the 128 bit variables, and 80 bytes for general purpose use.
10883 If any bit variables are used, the data variables will be placed in unused
10884 register banks and after the byte holding the last bit variable.
10885 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10890 variables will be placed starting from address 0x10 to 0x20 and continue
10905 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10909 to specify the start address of the
10926 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10930 to specify the size of the total internal RAM (
10944 By default the 8051 linker will place the stack after the last byte of (i)data
10959 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10963 allows you to specify the start of the stack, i.e.
10964 you could start it after any data in the general purpose area.
10965 If your microcontroller has additional indirectly addressable internal
10970 ) you can place the stack on it.
10971 You may also need to use -
10984 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10988 to set the start address of the external RAM (
11005 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
11009 to specify its size.
11010 Same goes for the code memory, using -
11023 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
11040 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11045 If in doubt, don't specify any options and see if the resulting memory
11046 layout is appropriate, then you can adjust it.
11049 \added_space_bottom bigskip
11050 The linker generates two files with memory allocation information.
11051 The first, with extension .map
11052 \begin_inset LatexCommand \index{<file>.map}
11056 shows all the variables and segments.
11057 The second with extension .mem
11058 \begin_inset LatexCommand \index{<file>.mem}
11062 shows the final memory layout.
11063 The linker will complain either if memory segments overlap, there is not
11064 enough memory, or there is not enough space for stack.
11065 If you get any linking warnings and/or errors related to stack or segments
11066 allocation, take a look at either the .map or .mem files to find out what
11068 The .mem file may even suggest a solution to the problem.
11073 Z80/Z180 Storage Class
11074 \begin_inset LatexCommand \index{Z80!Storage class}
11078 Language Extensions
11080 \layout Subsubsection
11082 \begin_inset LatexCommand \index{sfr}
11087 \begin_inset LatexCommand \index{\_\_sfr}
11091 (in/out to 8-bit addresses)
11095 \begin_inset LatexCommand \index{Z80}
11099 family has separate address spaces for memory and
11109 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11114 \begin_inset LatexCommand \index{Z80!I/O memory}
11119 \begin_inset LatexCommand \index{Z180!I/O memory}
11123 is accessed with special instructions, e.g.:
11128 sfr at 0x78 IoPort;\SpecialChar ~
11130 /* define a var in I/O space at 78h called IoPort */
11134 Writing 0x01 to this variable generates the assembly code:
11139 3E 01\SpecialChar ~
11147 D3 78\SpecialChar ~
11155 \layout Subsubsection
11157 \begin_inset LatexCommand \index{sfr}
11162 \begin_inset LatexCommand \index{\_\_sfr}
11166 (in/out to 16-bit addresses)
11173 is used to support 16 bit addresses in I/O memory e.g.:
11179 \begin_inset LatexCommand \index{at}
11184 \begin_inset LatexCommand \index{\_\_at}
11191 Writing 0x01 to this variable generates the assembly code:
11196 01 23 01\SpecialChar ~
11201 3E 01\SpecialChar ~
11209 ED 79\SpecialChar ~
11217 \layout Subsubsection
11219 \begin_inset LatexCommand \index{sfr}
11224 \begin_inset LatexCommand \index{\_\_sfr}
11228 (in0/out0 to 8 bit addresses on Z180
11229 \begin_inset LatexCommand \index{Z180}
11234 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11241 \added_space_bottom bigskip
11242 The compiler option -
11255 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11259 =180 (80) and a compiler #pragma\SpecialChar ~
11261 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11265 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11275 If you include the file z180.h this will be set automatically.
11281 \begin_inset LatexCommand \index{HC08!Storage class}
11285 Language Extensions
11287 \layout Subsubsection
11289 \begin_inset LatexCommand \index{data (hc08 storage class)}
11294 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11301 The data storage class declares a variable that resides in the first 256
11302 bytes of memory (the direct page).
11304 \begin_inset LatexCommand \index{HC08}
11308 is most efficient at accessing variables (especially pointers) stored here.
11310 \layout Subsubsection
11312 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11317 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11324 \added_space_bottom bigskip
11325 The xdata storage class declares a variable that can reside anywhere in
11327 This is the default if no storage class is specified.
11333 Absolute Addressing
11334 \begin_inset LatexCommand \index{Absolute addressing}
11341 Data items can be assigned an absolute address with the
11344 \begin_inset LatexCommand \index{at}
11349 \begin_inset LatexCommand \index{\_\_at}
11355 keyword, in addition to a storage class, e.g.:
11361 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11366 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11371 \begin_inset LatexCommand \index{at}
11376 \begin_inset LatexCommand \index{\_\_at}
11380 0x7ffe unsigned int chksum;
11383 or, better conforming to ISO/IEC 9899 C:
11388 __xdata __at (0x7ffe) unsigned int chksum;
11391 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11392 of the external ram.
11397 reserve any space for variables declared in this way
11398 \begin_inset Marginal
11409 (they are implemented with an equate in the assembler).
11410 Thus it is left to the programmer to make sure there are no overlaps with
11411 other variables that are declared without the absolute address.
11412 The assembler listing file (.lst
11413 \begin_inset LatexCommand \index{<file>.lst}
11417 ) and the linker output files (.rst
11418 \begin_inset LatexCommand \index{<file>.rst}
11423 \begin_inset LatexCommand \index{<file>.map}
11427 ) are good places to look for such overlaps.
11428 Variables with an absolute address are
11431 \begin_inset Marginal
11445 \begin_inset LatexCommand \index{Variable initialization}
11452 In case of memory mapped I/O devices the keyword
11456 has to be used to tell the compiler that accesses might not be removed:
11462 \begin_inset LatexCommand \index{volatile}
11467 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11472 \begin_inset LatexCommand \index{at}
11476 (0x8000) unsigned char PORTA_8255;
11479 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11484 \begin_inset LatexCommand \index{Aligned array}
11491 starts at a block (256 byte) boundary
11492 \begin_inset LatexCommand \index{block boundary}
11497 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11503 Absolute addresses can be specified for variables in all
11504 storage classes, e.g.:
11510 \begin_inset LatexCommand \index{bit}
11515 \begin_inset LatexCommand \index{at}
11522 The above example will allocate the variable at offset 0x02 in the bit-addressab
11524 There is no real advantage to assigning absolute addresses to variables
11525 in this manner, unless you want strict control over all the variables allocated.
11526 One possible use would be to write hardware portable code.
11527 For example, if you have a routine that uses one or more of the microcontroller
11528 I/O pins, and such pins are different for two different hardwares, you
11529 can declare the I/O pins in your routine using:
11535 \begin_inset LatexCommand \index{volatile}
11539 __bit MOSI;\SpecialChar ~
11543 /* master out, slave in */
11545 extern volatile __bit MISO;\SpecialChar ~
11552 extern volatile __bit MCLK;\SpecialChar ~
11561 Output of a byte on a 3-wire serial bus.
11566 If needed adapt polarity of clock,
11567 polarity of data and bit order
11572 unsigned char spi_io(unsigned char out_byte)
11597 MOSI = out_byte & 0x80;
11628 /* _asm nop _endasm; */\SpecialChar ~
11636 /* for slow peripherals */
11688 Then, someplace in the code for the first hardware you would use
11694 \begin_inset LatexCommand \index{at}
11699 \begin_inset LatexCommand \index{\_\_at}
11703 (0x80) MOSI;\SpecialChar ~
11707 /* I/O port 0, bit 0 */
11709 __bit __at (0x81) MISO;\SpecialChar ~
11716 __bit __at (0x82) MCLK;\SpecialChar ~
11720 /* I/O port 0, bit 2 */
11723 Similarly, for the second hardware you would use
11728 __bit __at (0x83) MOSI;\SpecialChar ~
11732 /* I/O port 0, bit 3 */
11734 __bit __at (0x91) MISO;\SpecialChar ~
11739 I/O port 1, bit 1 */
11742 \begin_inset LatexCommand \index{bit}
11746 __at (0x92) MCLK;\SpecialChar ~
11750 /* I/O port 1, bit 2 */
11753 \added_space_bottom bigskip
11754 and you can use the same hardware dependent routine without changes, as
11755 for example in a library.
11756 This is somehow similar to sbit, but only one absolute address has to be
11757 specified in the whole project.
11763 \begin_inset LatexCommand \index{Parameters}
11768 \begin_inset LatexCommand \index{function parameter}
11773 \begin_inset LatexCommand \index{local variables}
11778 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11785 Automatic (local) variables and parameters to functions can either be placed
11786 on the stack or in data-space.
11787 The default action of the compiler is to place these variables in the internal
11788 RAM (for small model) or external RAM (for large model).
11789 This in fact makes them similar to
11792 \begin_inset LatexCommand \index{static}
11798 so by default functions are non-reentrant
11799 \begin_inset LatexCommand \index{reentrant}
11808 They can be placed on the stack
11809 \begin_inset LatexCommand \index{stack}
11828 \begin_inset LatexCommand \index{-\/-stack-auto}
11836 #pragma\SpecialChar ~
11840 \begin_inset LatexCommand \index{\#pragma stackauto}
11847 \begin_inset LatexCommand \index{reentrant}
11853 keyword in the function declaration, e.g.:
11858 unsigned char foo(char i) __reentrant
11872 Since stack space on 8051 is limited, the
11892 option should be used sparingly.
11893 Note that the reentrant keyword just means that the parameters & local
11894 variables will be allocated to the stack, it
11898 mean that the function is register bank
11899 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11908 \begin_inset LatexCommand \index{local variables}
11912 can be assigned storage classes and absolute
11913 \begin_inset LatexCommand \index{Absolute addressing}
11922 unsigned char foo()
11930 __xdata unsigned char i;
11943 \begin_inset LatexCommand \index{at}
11947 (0x31) unsigned char j;
11959 In the above example the variable
11963 will be allocated in the external ram,
11967 in bit addressable space and
11988 or when a function is declared as
11992 this should only be done for static variables.
11996 \begin_inset LatexCommand \index{function parameter}
12000 however are not allowed any storage class
12001 \begin_inset LatexCommand \index{Storage class}
12005 , (storage classes for parameters will be ignored), their allocation is
12006 governed by the memory model in use, and the reentrancy options.
12009 It is however allowed to use bit parameters in reentrant functions and also
12010 non-static local bit variables are supported.
12011 Efficient use is limited to 8 semi-bitregisters in bit space.
12012 They are pushed and popped to stack
12013 \begin_inset LatexCommand \index{stack}
12017 as a single byte just like the normal registers.
12021 \begin_inset LatexCommand \label{sub:Overlaying}
12026 \begin_inset LatexCommand \index{Overlaying}
12034 \begin_inset LatexCommand \index{reentrant}
12038 functions SDCC will try to reduce internal ram space usage by overlaying
12039 parameters and local variables of a function (if possible).
12040 Parameters and local variables
12041 \begin_inset LatexCommand \index{local variables}
12045 of a function will be allocated to an overlayable segment if the function
12048 no other function calls and the function is non-reentrant and the memory
12050 \begin_inset LatexCommand \index{Memory model}
12057 If an explicit storage class
12058 \begin_inset LatexCommand \index{Storage class}
12062 is specified for a local variable, it will NOT be overlayed.
12065 Note that the compiler (not the linkage editor) makes the decision for overlayin
12067 Functions that are called from an interrupt service routine
12068 \begin_inset Marginal
12078 should be preceded by a #pragma\SpecialChar ~
12080 \begin_inset LatexCommand \index{\#pragma nooverlay}
12084 if they are not reentrant.
12087 Also note that the compiler does not do any processing of inline assembler
12088 code, so the compiler might incorrectly assign local variables and parameters
12089 of a function into the overlay segment if the inline assembler code calls
12090 other c-functions that might use the overlay.
12091 In that case the #pragma\SpecialChar ~
12092 nooverlay should be used.
12095 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12097 \begin_inset LatexCommand \index{Multiplication}
12102 \begin_inset LatexCommand \index{Division}
12106 will NOT be overlayed since these are implemented using external functions,
12115 \begin_inset LatexCommand \index{\#pragma nooverlay}
12121 void set_error(unsigned char errcd)
12138 some_isr () __interrupt
12139 \begin_inset LatexCommand \index{interrupt}
12169 \added_space_bottom bigskip
12170 In the above example the parameter
12178 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12180 not present, this could cause unpredictable runtime behavior when called
12181 from an interrupt service routine.
12182 The #pragma\SpecialChar ~
12183 nooverlay ensures that the parameters and local variables for
12184 the function are NOT overlayed.
12189 Interrupt Service Routines
12190 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12197 General Information
12212 outines to be coded in C, with some extended keywords.
12217 void timer_isr (void) __interrupt (1) __using (1)
12231 The optional number following the
12234 \begin_inset LatexCommand \index{interrupt}
12239 \begin_inset LatexCommand \index{\_\_interrupt}
12245 keyword is the interrupt number this routine will service.
12246 When present, the compiler will insert a call to this routine in the interrupt
12248 \begin_inset LatexCommand \index{interrupt vector table}
12252 for the interrupt number specified.
12253 If you have multiple source files in your project, interrupt service routines
12254 can be present in any of them, but a prototype of the isr MUST be present
12255 or included in the file that contains the function
12260 The optional (8051 specific) keyword
12263 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12268 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12274 can be used to tell the compiler to use the specified register bank when
12275 generating code for this function.
12278 Interrupt service routines open the door for some very interesting bugs:
12280 \layout Subsubsection
12281 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12285 Common interrupt pitfall: variable not declared
12290 If an interrupt service routine changes variables which are accessed by
12291 other functions these variables have to be declared
12296 \begin_inset LatexCommand \index{volatile}
12302 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12308 \layout Subsubsection
12309 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12313 Common interrupt pitfall:
12318 If the access to these variables is not
12321 \begin_inset LatexCommand \index{atomic}
12328 the processor needs more than one instruction for the access and could
12329 be interrupted while accessing the variable) the interrupt must be disabled
12330 during the access to avoid inconsistent data.
12333 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12334 and should be protected by disabling interrupts.
12335 You're not automatically on the safe side if you use 8 bit variables though.
12336 We need an example here: f.e.
12337 on the 8051 the harmless looking
12338 \begin_inset Quotes srd
12343 flags\SpecialChar ~
12348 \begin_inset Quotes sld
12357 \begin_inset Quotes srd
12362 flags\SpecialChar ~
12367 \begin_inset Quotes sld
12370 from within an interrupt routine might get lost if the interrupt occurs
12373 \begin_inset Quotes sld
12378 counter\SpecialChar ~
12383 \begin_inset Quotes srd
12386 is not atomic on the 8051 even if
12390 is located in data memory.
12392 Bugs like these are hard to reproduce and can
12393 cause a lot of trouble.
12396 \layout Subsubsection
12397 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12401 Common interrupt pitfall:
12406 The return address and the registers used in the interrupt service routine
12407 are saved on the stack
12408 \begin_inset LatexCommand \index{stack}
12412 so there must be sufficient stack space.
12413 If there isn't variables or registers (or even the return address itself)
12420 \begin_inset LatexCommand \index{stack overflow}
12424 is most likely to happen if the interrupt occurs during the
12425 \begin_inset Quotes sld
12429 \begin_inset Quotes srd
12432 subroutine when the stack is already in use for f.e.
12433 many return addresses.
12435 \layout Subsubsection
12436 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12440 Common interrupt pitfall:
12442 use of non-reentrant functions
12445 A special note here, int (16 bit) and long (32 bit) integer division
12446 \begin_inset LatexCommand \index{Division}
12451 \begin_inset LatexCommand \index{Multiplication}
12456 \begin_inset LatexCommand \index{Modulus}
12461 \begin_inset LatexCommand \index{Floating point support}
12465 operations are implemented using external support routines.
12466 If an interrupt service routine needs to do any of these operations then
12467 the support routines (as mentioned in a following section) will have to
12468 be recompiled using the
12483 \begin_inset LatexCommand \index{-\/-stack-auto}
12489 option and the source file will need to be compiled using the
12506 \begin_inset LatexCommand \index{-\/-int-long-reent}
12513 Note, the type promotion
12514 \begin_inset LatexCommand \index{type promotion}
12518 required by ANSI C can cause 16 bit routines to be used
12519 \begin_inset Marginal
12530 without the programmer being aware of it.
12534 (unsigned char)(tail-1)
12536 within the if clause in section
12537 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12544 \added_space_bottom bigskip
12545 Calling other functions from an interrupt service routine is not recommended,
12546 avoid it if possible.
12547 Note that when some function is called from an interrupt service routine
12548 it should be preceded by a #pragma\SpecialChar ~
12550 \begin_inset LatexCommand \index{\#pragma nooverlay}
12554 if it is not reentrant.
12555 Furthermore nonreentrant functions should not be called from the main program
12556 while the interrupt service routine might be active.
12557 They also must not be called from low priority interrupt service routines
12558 while a high priority interrupt service routine might be active.
12559 You could use semaphores or make the function
12563 if all parameters are passed in registers.
12566 \begin_inset LatexCommand \ref{sub:Overlaying}
12571 about Overlaying and section
12572 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12577 about Functions using private register banks.
12582 MCS51/DS390 Interrupt Service Routines
12586 \begin_inset LatexCommand \index{interrupt}
12590 numbers and the corresponding address & descriptions for the Standard 8051/8052
12592 SDCC will automatically adjust the
12593 \begin_inset LatexCommand \index{interrupt vector table}
12597 to the maximum interrupt number specified.
12603 \begin_inset Tabular
12604 <lyxtabular version="3" rows="9" columns="3">
12606 <column alignment="center" valignment="top" leftline="true" width="0in">
12607 <column alignment="left" valignment="top" leftline="true" width="0in">
12608 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12609 <row topline="true" bottomline="true">
12610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12635 <row topline="true">
12636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12661 <row topline="true">
12662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12687 <row topline="true">
12688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12713 <row topline="true">
12714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12739 <row topline="true">
12740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12765 <row topline="true">
12766 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12791 <row topline="true">
12792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12817 <row topline="true" bottomline="true">
12818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12852 If the interrupt service routine is defined without
12855 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12860 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12866 a register bank or with register bank 0 (
12870 0), the compiler will save the registers used by itself on the stack upon
12871 entry and restore them at exit, however if such an interrupt service routine
12872 calls another function then the entire register bank will be saved on the
12874 This scheme may be advantageous for small interrupt service routines which
12875 have low register usage.
12878 \added_space_bottom bigskip
12879 If the interrupt service routine is defined to be using a specific register
12884 & psw are saved and restored, if such an interrupt service routine calls
12885 another function (using another register bank) then the entire register
12886 bank of the called function will be saved on the stack
12887 \begin_inset LatexCommand \index{stack}
12892 This scheme is recommended for larger interrupt service routines.
12898 \begin_inset LatexCommand \index{HC08}
12902 Interrupt Service Routines
12905 \added_space_bottom bigskip
12906 Since the number of interrupts
12907 \begin_inset LatexCommand \index{HC08!interrupt}
12911 available is chip specific and the interrupt vector table always ends at
12912 the last byte of memory, the interrupt numbers corresponds to the interrupt
12913 vectors in reverse order of address.
12914 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12915 2 will use the interrupt vector at 0xfffa, and so on.
12916 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12917 this way; instead see section
12918 \begin_inset LatexCommand \ref{sub:Startup-Code}
12922 for details on customizing startup.
12927 Z80 Interrupt Service Routines
12931 \begin_inset LatexCommand \index{Z80}
12935 uses several different methods for determining the correct interrupt
12936 \begin_inset LatexCommand \index{Z80!interrupt}
12940 vector depending on the hardware implementation.
12941 Therefore, SDCC ignores the optional interrupt number and does not attempt
12942 to generate an interrupt vector table.
12945 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12946 instruction to return from the interrupt.
12947 To write an interrupt handler for the non-maskable interrupt, which needs
12948 a RETN instruction instead, add the
12957 void nmi_isr (void) critical interrupt
12971 \added_space_bottom bigskip
12972 However if you need to create a non-interruptable interrupt service routine
12973 you would also require the
12978 To distinguish between this and an nmi_isr you must provide an interrupt
12984 Enabling and Disabling Interrupts
12987 Critical Functions and Critical Statements
12990 A special keyword may be associated with a block or a function declaring
12996 SDCC will generate code to disable all interrupts
12997 \begin_inset LatexCommand \index{interrupt}
13001 upon entry to a critical function and restore the interrupt enable to the
13002 previous state before returning.
13003 Nesting critical functions will need one additional byte on the stack
13004 \begin_inset LatexCommand \index{stack}
13013 int foo () __critical
13014 \begin_inset LatexCommand \index{critical}
13019 \begin_inset LatexCommand \index{\_\_critical}
13044 The critical attribute maybe used with other attributes like
13054 may also be used to disable interrupts more locally:
13062 More than one statement could have been included in the block.
13065 Enabling and Disabling Interrupts directly
13069 \begin_inset LatexCommand \index{interrupt}
13073 can also be disabled and enabled directly (8051):
13078 EA = 0;\SpecialChar ~
13141 EA = 1;\SpecialChar ~
13208 On other architectures which have seperate opcodes for enabling and disabling
13209 interrupts you might want to make use of defines with inline assembly
13210 \begin_inset LatexCommand \index{Assembler routines}
13215 \begin_inset LatexCommand \index{HC08!interrupt}
13225 \begin_inset LatexCommand \index{\_asm}
13234 \begin_inset LatexCommand \index{\_endasm}
13243 #define SEI _asm\SpecialChar ~
13255 Note: it is sometimes sufficient to disable only a specific interrupt source
13257 a timer or serial interrupt by manipulating an
13260 \begin_inset LatexCommand \index{interrupt mask}
13270 Usually the time during which interrupts are disabled should be kept as
13272 This minimizes both
13277 \begin_inset LatexCommand \index{interrupt latency}
13281 (the time between the occurrence of the interrupt and the execution of
13282 the first code in the interrupt routine) and
13287 \begin_inset LatexCommand \index{interrupt jitter}
13291 (the difference between the shortest and the longest interrupt latency).
13292 These really are something different, f.e.
13293 a serial interrupt has to be served before its buffer overruns so it cares
13294 for the maximum interrupt latency, whereas it does not care about jitter.
13295 On a loudspeaker driven via a digital to analog converter which is fed
13296 by an interrupt a latency of a few milliseconds might be tolerable, whereas
13297 a much smaller jitter will be very audible.
13300 You can reenable interrupts within an interrupt routine and on some architecture
13301 s you can make use of two (or more) levels of
13303 interrupt priorities
13306 \begin_inset LatexCommand \index{interrupt priority}
13311 On some architectures which don't support interrupt priorities these can
13312 be implemented by manipulating the interrupt mask and reenabling interrupts
13313 within the interrupt routine.
13314 Check there is sufficient space on the stack
13315 \begin_inset LatexCommand \index{stack}
13319 and don't add complexity unless you have to.
13324 \begin_inset LatexCommand \index{semaphore}
13328 locking (mcs51/ds390)
13331 Some architectures (mcs51/ds390) have an atomic
13332 \begin_inset LatexCommand \index{atomic}
13345 These type of instructions are typically used in preemptive multitasking
13346 systems, where a routine f.e.
13347 claims the use of a data structure ('acquires a lock
13348 \begin_inset LatexCommand \index{lock}
13352 on it'), makes some modifications and then releases the lock when the data
13353 structure is consistent again.
13354 The instruction may also be used if interrupt and non-interrupt code have
13355 to compete for a resource.
13356 With the atomic bit test and clear instruction interrupts
13357 \begin_inset LatexCommand \index{interrupt}
13361 don't have to be disabled for the locking operation.
13365 SDCC generates this instruction if the source follows this pattern:
13371 \begin_inset LatexCommand \index{volatile}
13375 bit resource_is_free;
13379 if (resource_is_free)
13389 resource_is_free=0;
13402 resource_is_free=1;
13409 Note, mcs51 and ds390 support only an atomic
13410 \begin_inset LatexCommand \index{atomic}
13418 instruction (as opposed to atomic bit test and
13423 Functions using private register banks
13424 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13431 Some architectures have support for quickly changing register sets.
13432 SDCC supports this feature with the
13435 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13440 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13446 attribute (which tells the compiler to use a register bank
13447 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13451 other than the default bank zero).
13452 It should only be applied to
13455 \begin_inset LatexCommand \index{interrupt}
13461 functions (see footnote below).
13462 This will in most circumstances make the generated ISR code more efficient
13463 since it will not have to save registers on the stack.
13470 attribute will have no effect on the generated code for a
13474 function (but may occasionally be useful anyway
13479 possible exception: if a function is called ONLY from 'interrupt' functions
13480 using a particular bank, it can be declared with the same 'using' attribute
13481 as the calling 'interrupt' functions.
13482 For instance, if you have several ISRs using bank one, and all of them
13483 call memcpy(), it might make sense to create a specialized version of memcpy()
13484 'using 1', since this would prevent the ISR from having to save bank zero
13485 to the stack on entry and switch to bank zero before calling the function
13493 (pending: Note, nowadays the
13497 attribute has an effect on
13501 the generated code for a
13516 function using a non-zero bank will assume that it can trash that register
13517 bank, and will not save it.
13518 Since high-priority interrupts
13519 \begin_inset LatexCommand \index{interrupts}
13524 \begin_inset LatexCommand \index{interrupt priority}
13528 can interrupt low-priority ones on the 8051 and friends, this means that
13529 if a high-priority ISR
13533 a particular bank occurs while processing a low-priority ISR
13537 the same bank, terrible and bad things can happen.
13538 To prevent this, no single register bank should be
13542 by both a high priority and a low priority ISR.
13543 This is probably most easily done by having all high priority ISRs use
13544 one bank and all low priority ISRs use another.
13545 If you have an ISR which can change priority at runtime, you're on your
13546 own: I suggest using the default bank zero and taking the small performance
13550 \added_space_bottom bigskip
13551 It is most efficient if your ISR calls no other functions.
13552 If your ISR must call other functions, it is most efficient if those functions
13553 use the same bank as the ISR (see note 1 below); the next best is if the
13554 called functions use bank zero.
13555 It is very inefficient to call a function using a different, non-zero bank
13563 \begin_inset LatexCommand \label{sub:Startup-Code}
13568 \begin_inset LatexCommand \index{Startup code}
13575 MCS51/DS390 Startup Code
13578 The compiler triggers the linker to link certain initialization modules
13579 from the runtime library
13580 \begin_inset LatexCommand \index{Runtime library}
13584 called crt<something>.
13585 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
13586 GSINIT5) is not linked unless the --xstack option is used.
13587 These modules are highly entangled by the use of special segments/areas,
13588 but a common layout is shown below:
13621 ljmp __sdcc_gsinit_startup
13642 .area GSINIT0 (CODE)
13644 __sdcc_gsinit_startup::
13654 mov sp,#__start__stack - 1
13675 .area GSINIT1 (CODE)
13677 __sdcc_init_xstack::
13679 ; Need to initialize in GSINIT1 in
13680 case the user's __sdcc_external_startup uses the xstack.
13690 mov __XPAGE,#(__start__x
13701 mov _spx,#__start__xstack
13722 .area GSINIT2 (CODE)
13732 lcall __sdcc_external_startup
13752 jz __sdcc_init_data
13763 __sdcc_program_startup
13786 .area GSINIT3 (CODE)
13839 mov r2,#((l_XINIT+255) >> 8)
13870 __XPAGE,#(s_XISEG >> 8)
13872 00001$:\SpecialChar ~
13936 00002$:\SpecialChar ~
13981 .area GSINIT4 (CODE)
13983 __mcs51_genRAMCLEAR::
14005 00004$:\SpecialChar ~
14019 ; _mcs51_genRAMCLEAR() end
14040 .area GSINIT4 (CODE)
14042 __mcs51_genXRAMCLEAR::
14093 mov __XPAGE,#(s_PSEG >> 8)
14105 00005$:\SpecialChar ~
14159 orl a,#(l_XSEG >> 8)
14202 00007$:\SpecialChar ~
14257 .area GSINIT5 (CODE)
14259 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
14262 ; and __mcs51_genRAMCLEAR modifies _spx.
14272 mov __XPAGE,#(__start__x
14283 mov _spx,#__start__xstack
14290 (application modules)
14304 .area GSINIT (CODE)
14325 .area GSFINAL (CODE)
14335 ljmp __sdcc_program_startup
14337 ;---------------------------------
14338 -----------------------
14342 ;--------------------------------------------------
14365 __sdcc_program_startup:
14378 return from main will lock up
14391 One of these modules (crtstart.asm) contains a call to the C routine
14393 _sdcc_external_startup()
14394 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
14403 at the start of the CODE area.
14404 This routine is also in the runtime library
14405 \begin_inset LatexCommand \index{Runtime library}
14409 and returns 0 by default.
14410 If this routine returns a non-zero value, the static & global variable
14411 initialization will be skipped and the function main will be invoked.
14412 Otherwise static & global variables will be initialized before the function
14416 _sdcc_external_startup()
14418 routine to your program to override the default if you need to setup hardware
14419 or perform some other critical operation prior to static & global variable
14421 \begin_inset LatexCommand \index{Variable initialization}
14426 On some mcs51 variants xdata
14427 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
14431 memory has to be explicitly enabled before it can be accessed or if the
14433 \begin_inset LatexCommand \index{watchdog}
14437 needs to be disabled, this is the place to do it.
14438 The startup code clears all internal data memory, 256 bytes by default,
14439 but from 0 to n-1 if
14454 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
14461 (recommended for Chipcon CC1010).
14464 \added_space_bottom bigskip
14465 See also the compiler options
14486 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14507 \begin_inset LatexCommand \index{-\/-main-return}
14512 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14516 about MCS51-variants.
14524 \added_space_bottom bigskip
14526 \begin_inset LatexCommand \index{HC08}
14530 startup code follows the same scheme as the MCS51 startup code.
14538 \added_space_bottom bigskip
14540 \begin_inset LatexCommand \index{Z80}
14544 the startup code is inserted by linking with crt0.o which is generated from
14545 sdcc/device/lib/z80/crt0.s.
14546 If you need a different startup code you can use the compiler option
14569 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14573 and provide your own crt0.o.
14579 Inline Assembler Code
14580 \begin_inset LatexCommand \index{Assembler routines}
14587 A Step by Step Introduction
14588 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14595 Starting from a small snippet of c-code this example shows for the MCS51
14596 how to use inline assembly, access variables, a function parameter and
14597 an array in xdata memory.
14598 The example uses an MCS51 here but is easily adapted for other architectures.
14599 This is a buffer routine which should be optimized:
14605 unsigned char __far
14606 \begin_inset LatexCommand \index{far (storage class)}
14611 \begin_inset LatexCommand \index{\_\_far (storage class)}
14616 \begin_inset LatexCommand \index{at}
14621 \begin_inset LatexCommand \index{\_\_at}
14625 (0x7f00) buf[0x100];
14626 \begin_inset LatexCommand \index{Aligned array}
14632 unsigned char head, tail;\SpecialChar ~
14650 \begin_inset LatexCommand \index{interrupt}
14702 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14714 void to_buffer( unsigned char c )
14722 if( head != (unsigned char)(tail-1)
14729 \begin_inset LatexCommand \index{promotion to signed int}
14734 \begin_inset LatexCommand \index{type promotion}
14739 \begin_inset Marginal
14760 buf[ head++ ] = c;\SpecialChar ~
14776 /* access to a 256 byte aligned array */
14781 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14782 then a corresponding buffer.asm file is generated.
14783 We define a new function
14787 in file buffer.c in which we cut and paste the generated code, removing
14788 unwanted comments and some ':'.
14790 \begin_inset Quotes sld
14794 \begin_inset Quotes srd
14798 \begin_inset Quotes sld
14802 \begin_inset Quotes srd
14805 to the beginning and the end of the function body:
14811 /* With a cut and paste from the .asm file, we have something to start with.
14817 function is not yet OK! (registers aren't saved) */
14819 void to_buffer_asm(
14829 \begin_inset LatexCommand \index{\_asm}
14834 \begin_inset LatexCommand \index{\_\_asm}
14848 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14854 \begin_inset LatexCommand \index{promotion to signed int}
14859 \begin_inset LatexCommand \index{type promotion}
14912 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14913 \begin_inset LatexCommand \index{Aligned array}
14979 \begin_inset LatexCommand \index{\_endasm}
14984 \begin_inset LatexCommand \index{\_\_endasm}
14993 The new file buffer.c should compile with only one warning about the unreferenced
14994 function argument 'c'.
14995 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14996 (1) and finally have:
15002 unsigned char __far __at(0x7f00) buf[0x100];
15004 unsigned char head, tail;
15015 void to_buffer( unsigned char c )
15024 head != (unsigned char)(tail-1) )
15053 c; // to avoid warning: unreferenced function argument
15060 \begin_inset LatexCommand \index{\_asm}
15065 \begin_inset LatexCommand \index{\_\_asm}
15079 ; save used registers here.
15090 ; If we were still using r2,r3 we would have to push them here.
15093 ; if( head != (unsigned char)(tail-1) )
15137 could do an ANL a,#0x0f here to use a smaller buffer (see below)
15173 a,dpl \SpecialChar ~
15180 ; dpl holds lower byte of function argument
15192 dpl,_head \SpecialChar ~
15195 ; buf is 0x100 byte aligned so head can be used directly
15238 ; we could do an ANL _head,#0x0f here to use a
15239 smaller buffer (see above)
15251 ; restore used registers here
15258 \begin_inset LatexCommand \index{\_endasm}
15263 \begin_inset LatexCommand \index{\_\_endasm}
15274 The inline assembler code can contain any valid code understood by the assembler
15275 , this includes any assembler directives and comment lines.
15276 The assembler does not like some characters like ':' or ''' in comments.
15277 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
15278 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
15283 \begin_inset LatexCommand \index{Assembler documentation}
15288 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
15296 The compiler does not do any validation of the code within the
15299 \begin_inset LatexCommand \index{\_asm}
15304 \begin_inset LatexCommand \index{\_\_asm}
15312 \begin_inset LatexCommand \index{\_endasm}
15317 \begin_inset LatexCommand \index{\_\_endasm}
15326 Specifically it will not know which registers are used and thus register
15328 \begin_inset LatexCommand \index{push/pop}
15332 has to be done manually.
15336 It is recommended that each assembly instruction (including labels) be placed
15337 in a separate line (as the example shows).
15353 \begin_inset LatexCommand \index{-\/-peep-asm}
15359 command line option is used, the inline assembler code will be passed through
15360 the peephole optimizer
15361 \begin_inset LatexCommand \index{Peephole optimizer}
15366 There are only a few (if any) cases where this option makes sense, it might
15367 cause some unexpected changes in the inline assembler code.
15368 Please go through the peephole optimizer rules defined in file
15372 before using this option.
15376 \begin_inset LatexCommand \label{sub:Naked-Functions}
15381 \begin_inset LatexCommand \index{Naked functions}
15388 A special keyword may be associated with a function declaring it as
15391 \begin_inset LatexCommand \index{\_naked}
15396 \begin_inset LatexCommand \index{\_\_naked}
15407 function modifier attribute prevents the compiler from generating prologue
15408 \begin_inset LatexCommand \index{function prologue}
15413 \begin_inset LatexCommand \index{function epilogue}
15417 code for that function.
15418 This means that the user is entirely responsible for such things as saving
15419 any registers that may need to be preserved, selecting the proper register
15420 bank, generating the
15424 instruction at the end, etc.
15425 Practically, this means that the contents of the function must be written
15426 in inline assembler.
15427 This is particularly useful for interrupt functions, which can have a large
15428 (and often unnecessary) prologue/epilogue.
15429 For example, compare the code generated by these two functions:
15435 \begin_inset LatexCommand \index{volatile}
15439 data unsigned char counter;
15443 void simpleInterrupt(void) __interrupt
15444 \begin_inset LatexCommand \index{interrupt}
15449 \begin_inset LatexCommand \index{\_\_interrupt}
15467 void nakedInterrupt(void) __interrupt (2) __naked
15476 \begin_inset LatexCommand \index{\_asm}
15481 \begin_inset LatexCommand \index{\_\_asm}
15498 _counter ; does not change flags, no need to save psw
15511 include ret or reti in _naked function.
15518 \begin_inset LatexCommand \index{\_endasm}
15523 \begin_inset LatexCommand \index{\_\_endasm}
15532 For an 8051 target, the generated simpleInterrupt looks like:
15541 example, recent versions of SDCC generate
15547 code for simpleInterrupt() and nakedInterrupt()!
15688 whereas nakedInterrupt looks like:
15703 _counter ; does not change flags, no need to save psw
15722 MUST explicitly include ret or reti in _naked function
15725 The related directive #pragma exclude
15726 \begin_inset LatexCommand \index{\#pragma exclude}
15730 allows a more fine grained control over pushing & popping
15731 \begin_inset LatexCommand \index{push/pop}
15738 While there is nothing preventing you from writing C code inside a
15742 function, there are many ways to shoot yourself in the foot doing this,
15743 and it is recommended that you stick to inline assembler.
15746 Use of Labels within Inline Assembler
15749 SDCC allows the use of in-line assembler with a few restrictions regarding
15751 In older versions of the compiler all labels defined within inline assembler
15760 where nnnn is a number less than 100 (which implies a limit of utmost 100
15761 inline assembler labels
15775 \begin_inset LatexCommand \index{\_asm}
15780 \begin_inset LatexCommand \index{\_\_asm}
15810 \begin_inset LatexCommand \index{\_endasm}
15815 \begin_inset LatexCommand \index{\_\_endasm}
15822 Inline assembler code cannot reference any C-Labels, however it can reference
15824 \begin_inset LatexCommand \index{Labels}
15828 defined by the inline assembler, e.g.:
15853 ; some assembler code
15874 /* some more c code */
15876 clabel:\SpecialChar ~
15878 /* inline assembler cannot reference this
15891 $0003: ;label (can be referenced by inline assembler only)
15899 \begin_inset LatexCommand \index{\_endasm}
15904 \begin_inset LatexCommand \index{\_\_endasm}
15914 /* some more c code */
15919 In other words inline assembly code can access labels defined in inline
15920 assembly within the scope of the function.
15921 The same goes the other way, i.e.
15922 labels defines in inline assembly can not be accessed by C statements.
15925 Interfacing with Assembler Code
15926 \begin_inset LatexCommand \index{Assembler routines}
15933 Global Registers used for Parameter Passing
15934 \begin_inset LatexCommand \index{Parameter passing}
15941 The compiler always uses the global registers
15944 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15949 \begin_inset LatexCommand \index{DPTR}
15954 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15963 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15969 to pass the first parameter to a routine.
15970 The second parameter onwards is either allocated on the stack (for reentrant
15983 -stack-auto is used) or in data / xdata memory (depending on the memory
15988 Assembler Routine (non-reentrant)
15991 In the following example
15992 \begin_inset LatexCommand \index{reentrant}
15997 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
16001 the function c_func calls an assembler routine asm_func, which takes two
16003 \begin_inset LatexCommand \index{function parameter}
16012 extern int asm_func(unsigned char, unsigned char);
16016 int c_func (unsigned char
16017 i, unsigned char j)
16025 return asm_func(i,j);
16039 return c_func(10,9);
16044 The corresponding assembler function is:
16049 .globl _asm_func_PARM_2
16151 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
16168 Note here that the return values
16169 \begin_inset LatexCommand \index{return value}
16173 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
16175 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
16176 b' & 'acc' for four byte values.
16179 The parameter naming convention is _<function_name>_PARM_<n>, where n is
16180 the parameter number starting from 1, and counting from the left.
16181 The first parameter is passed in
16182 \begin_inset Quotes eld
16186 \begin_inset Quotes erd
16189 for a one byte parameter,
16190 \begin_inset Quotes eld
16194 \begin_inset Quotes erd
16198 \begin_inset Quotes eld
16202 \begin_inset Quotes erd
16205 for three bytes and
16206 \begin_inset Quotes eld
16210 \begin_inset Quotes erd
16213 for a four bytes parameter.
16214 The variable name for the second parameter will be _<function_name>_PARM_2.
16219 ble the assembler routine with the following command:
16226 asx8051 -losg asmfunc.asm
16233 Then compile and link the assembler routine to the C source file with the
16241 sdcc cfunc.c asmfunc.rel
16244 Assembler Routine (reentrant)
16248 \begin_inset LatexCommand \index{reentrant}
16253 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
16257 the second parameter
16258 \begin_inset LatexCommand \index{function parameter}
16262 onwards will be passed on the stack, the parameters are pushed from right
16264 after the call the leftmost parameter will be on the top of the stack.
16265 Here is an example:
16270 extern int asm_func(unsigned char, unsigned char);
16274 int c_func (unsigned char
16275 i, unsigned char j) reentrant
16283 return asm_func(i,j);
16303 The corresponding assembler routine is:
16405 \added_space_bottom bigskip
16406 The compiling and linking procedure remains the same, however note the extra
16407 entry & exit linkage required for the assembler code, _bp is the stack
16408 frame pointer and is used to compute the offset into the stack for parameters
16409 and local variables.
16415 \begin_inset LatexCommand \index{int (16 bit)}
16420 \begin_inset LatexCommand \index{long (32 bit)}
16427 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
16428 multiplication and modulus operations are implemented by support routines.
16429 These support routines are all developed in ANSI-C to facilitate porting
16430 to other MCUs, although some model specific assembler optimizations are
16432 The following files contain the described routines, all of them can be
16433 found in <installdir>/share/sdcc/lib.
16439 \begin_inset Tabular
16440 <lyxtabular version="3" rows="11" columns="2">
16442 <column alignment="left" valignment="top" leftline="true" width="0">
16443 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16444 <row topline="true" bottomline="true">
16445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16466 <row topline="true">
16467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16479 16 bit multiplication
16484 <row topline="true">
16485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16497 signed 16 bit division (calls _divuint)
16502 <row topline="true">
16503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16515 unsigned 16 bit division
16520 <row topline="true">
16521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16533 signed 16 bit modulus (calls _moduint)
16538 <row topline="true">
16539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16551 unsigned 16 bit modulus
16556 <row topline="true">
16557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16569 32 bit multiplication
16574 <row topline="true">
16575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16587 signed 32 division (calls _divulong)
16592 <row topline="true">
16593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16605 unsigned 32 division
16610 <row topline="true">
16611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16623 signed 32 bit modulus (calls _modulong)
16628 <row topline="true" bottomline="true">
16629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16641 unsigned 32 bit modulus
16655 Since they are compiled as
16660 \begin_inset LatexCommand \index{reentrant}
16665 \begin_inset LatexCommand \index{interrupt}
16669 service routines should not do any of the above operations.
16670 If this is unavoidable then the above routines will need to be compiled
16686 \begin_inset LatexCommand \index{-\/-stack-auto}
16692 option, after which the source program will have to be compiled with
16707 \begin_inset LatexCommand \index{-\/-int-long-reent}
16714 Notice that you don't have to call these routines directly.
16715 The compiler will use them automatically every time an integer operation
16719 Floating Point Support
16720 \begin_inset LatexCommand \index{Floating point support}
16727 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16728 The floating point support routines are derived from gcc's floatlib.c and
16729 consist of the following routines:
16737 \begin_inset Tabular
16738 <lyxtabular version="3" rows="17" columns="2">
16740 <column alignment="left" valignment="top" leftline="true" width="0">
16741 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16742 <row topline="true" bottomline="true">
16743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16769 <row topline="true">
16770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16800 add floating point numbers
16805 <row topline="true">
16806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16836 subtract floating point numbers
16841 <row topline="true">
16842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16872 divide floating point numbers
16877 <row topline="true">
16878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16908 multiply floating point numbers
16913 <row topline="true">
16914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16944 convert floating point to unsigned char
16949 <row topline="true">
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16980 convert floating point to signed char
16985 <row topline="true">
16986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17016 convert floating point to unsigned int
17021 <row topline="true">
17022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17052 convert floating point to signed int
17057 <row topline="true">
17058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17096 convert floating point to unsigned long
17101 <row topline="true">
17102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17132 convert floating point to signed long
17137 <row topline="true">
17138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17168 convert unsigned char to floating point
17173 <row topline="true">
17174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17204 convert char to floating point number
17209 <row topline="true">
17210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17240 convert unsigned int to floating point
17245 <row topline="true">
17246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17276 convert int to floating point numbers
17281 <row topline="true">
17282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17312 convert unsigned long to floating point number
17317 <row topline="true" bottomline="true">
17318 <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">
17348 convert long to floating point number
17362 \added_space_bottom bigskip
17363 These support routines are developed in ANSI-C so there is room for space
17364 and speed improvement
17369 These floating point routines (
17373 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
17379 Note if all these routines are used simultaneously the data space might
17381 For serious floating point usage the large model might be needed.
17382 Also notice that you don't have to call this routines directly.
17383 The compiler will use them automatically every time a floating point operation
17390 \begin_inset LatexCommand \index{Libraries}
17399 <pending: this is messy and incomplete - a little more information is in
17400 sdcc/doc/libdoc.txt
17405 Compiler support routines (_gptrget, _mulint etc.)
17408 Stdclib functions (puts, printf, strcat etc.)
17410 \layout Subsubsection
17414 getchar(), putchar()
17417 \begin_inset LatexCommand \index{<stdio.h>}
17421 As usual on embedded systems you have to provide your own
17424 \begin_inset LatexCommand \index{getchar()}
17433 \begin_inset LatexCommand \index{putchar()}
17440 SDCC does not know whether the system connects to a serial line with or
17441 without handshake, LCD, keyboard or other device.
17455 You'll find examples for serial routines f.e.
17456 in sdcc/device/lib.
17457 For the mcs51 this minimalistic polling
17461 routine might be a start:
17466 void putchar (char c) {
17472 while (!TI)\SpecialChar ~
17475 /* assumes UART is initialized */
17509 \begin_inset LatexCommand \index{printf()}
17519 does not support float (except on ds390).
17520 To enable this recompile it with the option
17535 \begin_inset LatexCommand \index{USE\_FLOATS}
17541 on the command line.
17557 \begin_inset LatexCommand \index{-\/-model-large}
17563 for the mcs51 port, since this uses a lot of memory.
17566 If you're short on code memory you might want to use
17569 \begin_inset LatexCommand \index{printf\_small()}
17584 For the mcs51 there additionally are assembly versions
17587 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17593 (subset of printf using less than 270 bytes) and
17596 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17605 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17611 (floating-point aware version of printf_fast) which should fit the requirements
17612 of many embedded systems (printf_fast() can be customized by unsetting
17617 support long variables and field widths).
17618 Be sure to use only one of these printf options within a project.
17623 Feature matrix of different
17630 \begin_inset Tabular
17631 <lyxtabular version="3" rows="14" columns="7">
17632 <features islongtable="true">
17633 <column alignment="left" valignment="center" leftline="true" width="14col%">
17634 <column alignment="center" valignment="top" leftline="true" width="0">
17635 <column alignment="center" valignment="top" leftline="true" width="12col%">
17636 <column alignment="center" valignment="top" leftline="true" width="10col%">
17637 <column alignment="center" valignment="top" leftline="true" width="0">
17638 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17639 <column alignment="center" valignment="top" rightline="true" width="0">
17640 <row topline="true" bottomline="true" endhead="true">
17641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17657 \begin_inset LatexCommand \index{printf}
17665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17708 <row topline="true" endhead="true">
17709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17778 <row topline="true" endhead="true">
17779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17783 \begin_inset Quotes sld
17787 \begin_inset Quotes srd
17797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17846 <row topline="true" endhead="true">
17847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17878 0.45k / 0.47k (+ _ltoa)
17882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17907 <row topline="true">
17908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18043 <row topline="true">
18044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18048 long (32 bit) support
18052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18110 <row topline="true">
18111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18115 byte arguments on stack
18119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18168 <row topline="true">
18169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18174 \begin_inset LatexCommand \index{Floating point support}
18182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18223 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
18231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18240 <row topline="true">
18241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18245 float formats %e %g
18249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18298 <row topline="true" bottomline="true">
18299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18356 <row bottomline="true">
18357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18366 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
18370 n'); standard 8051 @ 22.1184 MHz, empty putchar()
18381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18430 <row bottomline="true">
18431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18440 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18501 printf_tiny integer speed is data dependent, worst case is 0.33 ms
18510 <row bottomline="true">
18511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18520 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
18532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18581 <row bottomline="true">
18582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18591 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18658 \layout Subsubsection
18660 \begin_inset LatexCommand \index{malloc.h}
18667 As of SDCC 2.6.2 you no longer need to call an initialization routine before
18668 using dynamic memory allocation
18669 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
18674 \begin_inset LatexCommand \index{heap (malloc)}
18678 space of 1024 bytes is provided for malloc to allocate memory from.
18679 If you need a different heap size you need to recompile _heap.c with the
18680 required size defined in HEAP_SIZE.
18681 It is recommended to make a copy of this file into your project directory
18682 and compile it there with:
18687 sdcc -c _heap.c -D HEAD_SIZE=2048
18690 And then link it with:
18695 sdcc main.rel _heap.rel
18698 Math functions (sinf, powf, sqrtf etc.)
18700 \layout Subsubsection
18704 See definitions in file <math.h>.
18711 \begin_inset LatexCommand \index{Libraries}
18715 included in SDCC should have a license at least as liberal as the GNU Lesser
18716 General Public License
18717 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
18732 license statements for the libraries are missing.
18733 sdcc/device/lib/ser_ir.c
18737 come with a GPL (as opposed to LGPL) License - this will not be liberal
18738 enough for many embedded programmers.
18745 If you have ported some library or want to share experience about some code
18747 falls into any of these categories Busses (I
18748 \begin_inset Formula $^{\textrm{2}}$
18751 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
18752 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
18753 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
18754 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
18759 would certainly like to hear about it.
18762 \added_space_bottom bigskip
18763 Programmers coding for embedded systems are not especially famous for being
18764 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
18765 e these references are very valuable.
18766 Let's help to create a climate where information is shared.
18774 MCS51 Memory Models
18775 \begin_inset LatexCommand \index{Memory model}
18780 \begin_inset LatexCommand \index{MCS51 memory model}
18786 \layout Subsubsection
18787 Small, Medium and Large
18790 SDCC allows three memory models for MCS51 code,
18799 Modules compiled with different memory models should
18803 be combined together or the results would be unpredictable.
18804 The library routines supplied with the compiler are compiled as small,
18806 The compiled library modules are contained in separate directories as small,
18807 medium and large so that you can link to the appropriate set.
18810 When the medium or large model is used all variables declared without a
18811 storage class will be allocated into the external ram, this includes all
18812 parameters and local variables (for non-reentrant
18813 \begin_inset LatexCommand \index{reentrant}
18818 When the small model is used variables without storage class are allocated
18819 in the internal ram.
18822 Judicious usage of the processor specific storage classes
18823 \begin_inset LatexCommand \index{Storage class}
18827 and the 'reentrant' function type will yield much more efficient code,
18828 than using the large model.
18829 Several optimizations are disabled when the program is compiled using the
18830 large model, it is therefore recommended that the small model be used unless
18831 absolutely required.
18833 \layout Subsubsection
18835 \begin_inset LatexCommand \label{sub:External-Stack}
18840 \begin_inset LatexCommand \index{stack}
18845 \begin_inset LatexCommand \index{External stack (mcs51)}
18852 The external stack (-
18865 \begin_inset LatexCommand \index{-\/-xstack}
18869 ) is located in pdata
18870 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18874 memory (usually at the start of the external ram segment) and uses all
18875 unused space in pdata (max.
18889 -xstack option is used to compile the program, the parameters and local
18891 \begin_inset LatexCommand \index{local variables}
18895 of all reentrant functions are allocated in this area.
18896 This option is provided for programs with large stack space requirements.
18897 When used with the -
18910 \begin_inset LatexCommand \index{-\/-stack-auto}
18914 option, all parameters and local variables are allocated on the external
18915 stack (note: support libraries will need to be recompiled with the same
18917 There is a predefined target in the library makefile).
18920 The compiler outputs the higher order address byte of the external ram segment
18922 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18927 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18931 ), therefore when using the External Stack option, this port
18935 be used by the application program.
18939 \begin_inset LatexCommand \index{Memory model}
18944 \begin_inset LatexCommand \index{DS390 memory model}
18951 The only model supported is Flat 24
18952 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18957 This generates code for the 24 bit contiguous addressing mode of the Dallas
18959 In this mode, up to four meg of external RAM or code space can be directly
18961 See the data sheets at www.dalsemi.com for further information on this part.
18966 that the compiler does not generate any code to place the processor into
18967 24 bitmode (although
18971 in the ds390 libraries will do that for you).
18977 \begin_inset LatexCommand \index{Tinibios (DS390)}
18981 , the boot loader or similar code must ensure that the processor is in 24
18982 bit contiguous addressing mode before calling the SDCC startup code.
19003 option, variables will by default be placed into the XDATA segment.
19008 Segments may be placed anywhere in the 4 meg address space using the usual
19022 Note that if any segments are located above 64K, the -r flag must be passed
19023 to the linker to generate the proper segment relocations, and the Intel
19024 HEX output format must be used.
19025 The -r flag can be passed to the linker by using the option
19029 on the SDCC command line.
19030 However, currently the linker can not handle code segments > 64k.
19034 \begin_inset LatexCommand \label{sec:Pragmas}
19039 \begin_inset LatexCommand \index{Pragmas}
19046 SDCC supports the following #pragma directives:
19054 \begin_inset LatexCommand \index{\#pragma save}
19058 - this will save most current options to the save/restore stack.
19059 See #pragma\SpecialChar ~
19068 \begin_inset LatexCommand \index{\#pragma restore}
19072 - will restore saved options from the last save.
19073 saves & restores can be nested.
19074 SDCC uses a save/restore stack: save pushes current options to the stack,
19075 restore pulls current options from the stack.
19076 See #pragma\SpecialChar ~
19087 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19092 \begin_inset LatexCommand \index{function prologue}
19096 function1[,function2[,function3...]] - The compiler by default uses a caller
19097 saves convention for register saving across function calls, however this
19098 can cause unnecessary register pushing & popping
19099 \begin_inset LatexCommand \index{push/pop}
19103 when calling small functions from larger functions.
19104 This option can be used to switch off the register saving convention for
19105 the function names specified.
19106 The compiler will not save registers when calling these functions, extra
19107 code need to be manually inserted at the entry & exit for these functions
19108 to save & restore the registers used by these functions, this can SUBSTANTIALLY
19109 reduce code & improve run time performance of the generated code.
19110 In the future the compiler (with inter procedural analysis) may be able
19111 to determine the appropriate scheme to use for each function call.
19124 -callee-saves command line option is used, the function names specified
19125 in #pragma\SpecialChar ~
19127 \begin_inset LatexCommand \index{\#pragma callee\_saves}
19131 is appended to the list of functions specified in the command line.
19139 \begin_inset LatexCommand \index{\#pragma exclude}
19143 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
19144 of pairs of push/pop
19145 \begin_inset LatexCommand \index{push/pop}
19154 \begin_inset LatexCommand \index{interrupt}
19167 The directive should be placed immediately before the ISR function definition
19168 and it affects ALL ISR functions following it.
19169 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
19170 exclude\SpecialChar ~
19172 \begin_inset LatexCommand \index{\#pragma exclude}
19177 See also the related keyword _naked
19178 \begin_inset LatexCommand \index{\_naked}
19183 \begin_inset LatexCommand \index{\_\_naked}
19195 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
19199 - the compiler will not warn you anymore for obvious mistakes, you'r on
19208 \begin_inset LatexCommand \index{\#pragma disable\_warning}
19212 - the compiler will not warn you anymore about warning number <nnnn>.
19220 \begin_inset LatexCommand \index{\#pragma nogcse}
19224 - will stop global common subexpression elimination.
19232 \begin_inset LatexCommand \index{\#pragma noinduction}
19236 - will stop loop induction optimizations.
19244 \begin_inset LatexCommand \index{\#pragma noinvariant}
19248 - will not do loop invariant optimizations.
19249 For more details see Loop Invariants in section
19250 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
19262 \begin_inset LatexCommand \index{\#pragma noiv}
19266 - Do not generate interrupt
19267 \begin_inset LatexCommand \index{interrupt}
19272 \begin_inset LatexCommand \index{interrupt vector table}
19276 entries for all ISR functions defined after the pragma.
19277 This is useful in cases where the interrupt vector table must be defined
19278 manually, or when there is a secondary, manually defined interrupt vector
19280 for the autovector feature of the Cypress EZ-USB FX2).
19281 More elegantly this can be achieved by obmitting the optional interrupt
19282 number after the interrupt keyword, see section
19283 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
19296 \begin_inset LatexCommand \index{\#pragma nojtbound}
19300 - will not generate code for boundary value checking, when switch statements
19301 are turned into jump-tables (dangerous).
19302 For more details see section
19303 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
19315 \begin_inset LatexCommand \index{\#pragma noloopreverse}
19319 - Will not do loop reversal optimization
19327 \begin_inset LatexCommand \index{\#pragma nooverlay}
19331 - the compiler will not overlay the parameters and local variables of a
19340 \begin_inset LatexCommand \index{\#pragma stackauto}
19357 \begin_inset LatexCommand \index{-\/-stack-auto}
19362 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
19366 Parameters and Local Variables.
19374 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
19378 - The compiler will optimize code generation towards fast code, possibly
19379 at the expense of code size.
19380 Currently this has little effect.
19388 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
19392 - The compiler will optimize code generation towards compact code, possibly
19393 at the expense of code speed.
19394 Currently this has little effect.
19402 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
19406 - The compiler will attempt to generate code that is both compact and fast,
19407 as long as meeting one goal is not a detriment to the other (this is the
19417 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
19421 - Generally follow the C89 standard, but allow SDCC features that conflict
19422 with the standard (default).
19430 \begin_inset LatexCommand \index{\#pragma std\_c89}
19434 - Follow the C89 standard and disable SDCC features that conflict with the
19443 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
19447 - Generally follow the C99 standard, but allow SDCC features that conflict
19448 with the standard (incomplete support).
19456 \begin_inset LatexCommand \index{\#pragma std\_c99}
19460 - Follow the C99 standard and disable SDCC features that conflict with the
19461 standard (incomplete support).
19469 \begin_inset LatexCommand \index{\#pragma codeseg}
19473 - Use this name (max.
19474 8 characters) for the code segment.
19495 \begin_inset LatexCommand \index{\#pragma constseg}
19499 - Use this name (max.
19500 8 characters) for the const segment.
19516 The preprocessor SDCPP
19517 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
19521 supports the following #pragma directives:
19526 pedantic_parse_number
19529 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19533 (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
19534 parsed properly and the macro LO_B(3) gets expanded.
19536 Below is an example on how to use this pragma.
19539 Note: this functionality is not in conformance with standard!
19544 #pragma pedantic_parse_number +
19545 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
19553 #define LO_B(x) ((x) & 0xff)
19557 unsigned char foo(void)
19564 unsigned char c=0xfe-LO_B(3)
19584 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19588 (+ | -) - switch _asm _endasm block preprocessing on / off.
19590 You use this prama to define multilines of assembly code.
19591 This will prevent the preprocessor from changing the formating required
19593 Below is an example on how to use this pragma.
19598 #pragma preproc_asm -
19599 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19605 #define MYDELAY _asm
19610 nop ;my assembly comment...
19624 #pragma preproc_asm
19660 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19664 (+ | -) - Allow "naked" hash in macro definition, for example:
19668 #define DIR_LO(x) #(x & 0xff)
19673 Below is an example on how to use this pragma.
19678 #pragma preproc_asm +
19680 #pragma sdcc_hash +
19681 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19696 mov R6_B3, #(x & 0xff)
19703 mov R7_B3, #((x >> 8) & 0xff)
19727 The pragma's are intended to be used to turn-on or off certain optimizations
19728 which might cause the compiler to generate extra stack / data space to
19729 store compiler generated temporary variables.
19730 This usually happens in large functions.
19731 Pragma directives should be used as shown in the following example, they
19732 are used to control options & optimizations for a given function; pragmas
19733 should be placed before and/or after a function, placing pragma's inside
19734 a function body could have unpredictable results.
19740 \begin_inset LatexCommand \index{\#pragma save}
19751 /* save the current settings */
19754 \begin_inset LatexCommand \index{\#pragma nogcse}
19763 /* turnoff global subexpression elimination */
19765 #pragma noinduction
19766 \begin_inset LatexCommand \index{\#pragma noinduction}
19770 /* turn off induction optimizations */
19793 \begin_inset LatexCommand \index{\#pragma restore}
19797 /* turn the optimizations back on */
19800 The compiler will generate a warning message when extra space is allocated.
19801 It is strongly recommended that the save and restore pragma's be used when
19802 changing options for a function.
19811 Defines Created by the Compiler
19814 The compiler creates the following #defines
19815 \begin_inset LatexCommand \index{\#defines}
19820 \begin_inset LatexCommand \index{Defines created by the compiler}
19829 \begin_inset Tabular
19830 <lyxtabular version="3" rows="11" columns="2">
19832 <column alignment="left" valignment="top" leftline="true" width="3in">
19833 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
19834 <row topline="true" bottomline="true">
19835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19856 <row topline="true">
19857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19862 \begin_inset LatexCommand \index{SDCC}
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19875 Since version 2.5.6 the version number as an int (ex.
19881 <row topline="true">
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19887 \begin_inset LatexCommand \index{SDCC\_mcs51}
19892 \begin_inset LatexCommand \index{SDCC\_ds390}
19897 \begin_inset LatexCommand \index{SDCC\_z80}
19905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19909 depending on the model used (e.g.: -mds390)
19914 <row topline="true">
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19920 \begin_inset LatexCommand \index{\_\_mcs51}
19925 \begin_inset LatexCommand \index{\_\_ds390}
19930 \begin_inset LatexCommand \index{\_\_hc08}
19935 \begin_inset LatexCommand \index{\_\_z80}
19943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19947 depending on the model used (e.g.
19953 <row topline="true">
19954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19959 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19992 <row topline="true">
19993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19998 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20031 <row topline="true">
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20037 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
20045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20070 <row topline="true">
20071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20076 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
20084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20109 <row topline="true">
20110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20115 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
20123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20148 <row topline="true">
20149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20154 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
20162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20175 <row topline="true" bottomline="true">
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20181 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
20189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20209 Notes on supported Processors
20213 \begin_inset LatexCommand \label{sub:MCS51-variants}
20218 \begin_inset LatexCommand \index{MCS51 variants}
20225 MCS51 processors are available from many vendors and come in many different
20227 While they might differ considerably in respect to Special Function Registers
20228 the core MCS51 is usually not modified or is kept compatible.
20232 pdata access by SFR
20235 With the upcome of devices with internal xdata and flash memory devices
20237 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20241 as dedicated I/O port is becoming more popular.
20242 Switching the high byte for pdata
20243 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20247 access which was formerly done by port P2 is then achieved by a Special
20249 \begin_inset LatexCommand \index{sfr}
20254 In well-established MCS51 tradition the address of this
20258 is where the chip designers decided to put it.
20259 Needless to say that they didn't agree on a common name either.
20260 So that the startup code can correctly initialize xdata variables, you
20261 should define an sfr with the name _XPAGE
20264 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
20270 at the appropriate location if the default, port P2, is not used for this.
20276 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
20282 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
20289 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
20295 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20301 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
20305 For more exotic implementations further customizations may be needed.
20307 \begin_inset LatexCommand \ref{sub:Startup-Code}
20311 for other possibilities.
20314 Other Features available by SFR
20317 \added_space_bottom bigskip
20318 Some MCS51 variants offer features like Double DPTR
20319 \begin_inset LatexCommand \index{DPTR}
20323 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
20324 These are currently not used for the MCS51 port.
20325 If you absolutely need them you can fall back to inline assembly or submit
20334 \added_space_bottom bigskip
20336 \begin_inset LatexCommand \index{DS80C400}
20341 \begin_inset LatexCommand \index{DS400}
20345 microcontroller has a rich set of peripherals.
20346 In its built-in ROM library it includes functions to access some of the
20347 features, among them is a TCP stack with IP4 and IP6 support.
20348 Library headers (currently in beta status) and other files are provided
20352 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
20362 The Z80 and gbz80 port
20365 SDCC can target both the Zilog Z80
20366 \begin_inset LatexCommand \index{Z80}
20370 and the Nintendo Gameboy's Z80-like gbz80
20371 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
20376 The Z80 port is passed through the same
20379 \begin_inset LatexCommand \index{Regression test}
20386 \begin_inset LatexCommand \ref{sec:Quality-control}
20390 ) as the MCS51 and DS390 ports, so floating point support, support for long
20391 variables and bitfield support is fine.
20392 See mailing lists and forums about interrupt routines.
20395 \added_space_bottom bigskip
20396 As always, the code is the authoritative reference - see z80/ralloc.c and
20399 \begin_inset LatexCommand \index{Z80!stack}
20403 frame is similar to that generated by the IAR Z80 compiler.
20404 IX is used as the base pointer, HL and IY are used as a temporary registers,
20405 and BC and DE are available for holding variables.
20407 \begin_inset LatexCommand \index{Z80!return value}
20411 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
20413 The gbz80 port use the same set of registers for the return values, but
20414 in a different order of significance: E (one byte), DE (two bytes), or
20423 The port to the Freescale/Motorola HC08
20424 \begin_inset LatexCommand \index{HC08}
20428 family has been added in October 2003, and is still undergoing some basic
20430 The code generator is complete, but the register allocation is still quite
20432 Some of the SDCC's standard C library functions have embedded non-HC08
20433 inline assembly and so are not yet usable.
20437 \added_space_bottom bigskip
20438 The HC08 port passes the regression test suite (see section
20439 \begin_inset LatexCommand \ref{sec:Quality-control}
20453 \begin_inset LatexCommand \index{PIC14}
20457 port still requires a major effort from the development community.
20458 However it can work for simple code.
20459 It passes its (smaller set of) regression tests
20460 \begin_inset LatexCommand \index{Regression test (PIC14)}
20466 sdcc/src/regression
20471 C code and 14bit PIC code page
20472 \begin_inset LatexCommand \index{code page (pic14)}
20477 \begin_inset LatexCommand \index{RAM bank (pic14)}
20484 The linker organizes allocation for the code page and RAM banks.
20485 It does not have intimate knowledge of the code flow.
20486 It will put all the code section of a single asm file into a single code
20488 In order to make use of multiple code pages, separate asm files must be
20490 The compiler treats all functions of a single C file as being in the same
20491 code page unless it is non static.
20495 To get the best follow these guide lines:
20498 Make local functions static, as non static functions require code page selection
20502 For devices that have multiple code pages it is more efficient to use the
20503 same number of files as pages, i.e.
20504 for the 16F877 use 4 separate files and i.e.
20505 for the 16F874 use 2 separate files.
20506 This way the linker can put the code for each file into different code
20507 pages and there's less page selection overhead.
20510 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
20511 instruction set), use 'unsigned char' whereever possible instead of 'int'.
20514 Creating a device include file
20517 For generating a device include file
20518 \begin_inset LatexCommand \index{PIC14!Header files}
20522 use the support perl script inc2h.pl kept in directory support/script.
20528 For the interrupt function, use the keyword '__interrupt'
20529 \begin_inset LatexCommand \index{PIC14!interrupt}
20533 with level number of 0 (PIC14 only has 1 interrupt so this number is only
20534 there to avoid a syntax error - it ought to be fixed).
20540 void Intr(void) __interrupt 0
20546 T0IF = 0; /* Clear timer interrupt */
20551 Linking and assembling
20554 For assembling you can use either GPUTILS'
20555 \begin_inset LatexCommand \index{gputils (pic tools)}
20559 gpasm.exe or MPLAB's mpasmwin.exe.
20560 GPUTILS is available from
20561 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
20566 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
20567 If you use MPLAB and an interrupt function then the linker script file
20568 vectors section will need to be enlarged to link with mplink.
20591 sdcc -S -V -mpic14 -p16F877 $<
20605 $(PRJ).hex: $(OBJS)
20616 -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
20638 sdcc -S -V -mpic14 -p16F877 $<
20648 mpasmwin /q /o $*.asm
20652 $(PRJ).hex: $(OBJS)
20663 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
20666 Please note that indentations within a
20670 have to be done with a tabulator character.
20673 Command-line options
20676 Besides the switches common to all SDCC backends, the PIC14 port accepts
20677 the following options (for an updated list see sdcc -
20692 \labelwidthstring 00.00.0000
20706 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
20710 emit debug info in assembly output
20713 \labelwidthstring 00.00.0000
20727 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
20731 disable (slightly faulty) optimization on pCode
20734 \labelwidthstring 00.00.0000
20748 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
20752 sets the lowest address of the argument passing stack (defaults to a suitably
20753 large shared databank to reduce BANKSEL overhead)
20756 \labelwidthstring 00.00.0000
20770 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
20774 sets the size if the argument passing stack (default: 16, minimum: 4)
20779 \layout Subsubsection
20780 error: missing definition for symbol
20781 \begin_inset Quotes sld
20785 \begin_inset Quotes srd
20791 The PIC14 port uses library routines to provide more complex operations
20792 like multiplication, division/modulus and (generic) pointer dereferencing.
20793 In order to add these routines to your project, you must link with PIC14's
20799 For single source file projects this is done automatically, more complex
20804 to the linker's arguments.
20805 Make sure you also add an include path for the library (using the -I switch
20808 \layout Subsubsection
20809 Processor mismatch in file
20810 \begin_inset Quotes sld
20814 \begin_inset Quotes srd
20820 This warning can usually be ignored due to the very good compatibility amongst
20822 \begin_inset LatexCommand \index{PIC14}
20829 You might also consider recompiling the library for your specific device
20830 by changing the ARCH=p16f877 (default target) entry in
20832 device/lib/pic/Makefile.in
20836 device/lib/pic/Makefile
20838 to reflect your device.
20839 This might even improve performance for smaller devices as unneccesary
20840 BANKSELs migth be removed.
20845 \layout Subsubsection
20850 Currently, data can only be initialized if it resides in the source file
20856 Data in other source files will silently
20864 \begin_inset Marginal
20882 \begin_inset LatexCommand \index{PIC16}
20890 \begin_inset LatexCommand \index{PIC16}
20894 port is the portion of SDCC that is responsible to produce code for the
20896 \begin_inset LatexCommand \index{Microchip}
20900 (TM) microcontrollers with 16 bit core.
20901 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20902 Currently supported devices are:
20906 \begin_inset Tabular
20907 <lyxtabular version="3" rows="4" columns="6">
20909 <column alignment="center" valignment="top" leftline="true" width="0">
20910 <column alignment="center" valignment="top" leftline="true" width="0">
20911 <column alignment="center" valignment="top" leftline="true" width="0">
20912 <column alignment="center" valignment="top" leftline="true" width="0">
20913 <column alignment="center" valignment="top" leftline="true" width="0">
20914 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20915 <row topline="true">
20916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20965 <row topline="true">
20966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21015 <row topline="true">
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21065 <row topline="true" bottomline="true">
21066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21125 PIC16 port supports the standard command line arguments as supposed, with
21126 the exception of certain cases that will be mentioned in the following
21130 \labelwidthstring 00.00.0000
21144 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
21163 \labelwidthstring 00.00.0000
21177 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
21181 All function arguments are passed on stack by default.
21184 There is no need to specify this in the command line.
21187 \labelwidthstring 00.00.0000
21200 -fommit-frame-pointer
21201 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
21205 Frame pointer will be omitted when the function uses no local variables.
21208 Port Specific Options
21209 \begin_inset LatexCommand \index{Options PIC16}
21216 The port specific options appear after the global options in the sdcc --help
21219 \layout Subsubsection
21223 General options enable certain port features and optimizations.
21226 \labelwidthstring 00.00.0000
21239 -pstack-model=[model] Used in conjuction with the command above.
21240 Defines the stack model to be used, valid stack models are :
21244 \labelwidthstring 00.00.0000
21249 Selects small stack model.
21250 8 bit stack and frame pointers.
21251 Supports 256 bytes stack size.
21254 \labelwidthstring 00.00.0000
21259 Selects large stack model.
21260 16 bit stack and frame pointers.
21261 Supports 65536 bytes stack size.
21265 \labelwidthstring 00.00.0000
21278 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
21279 unitialized data variables with [kword].
21280 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
21283 \labelwidthstring 00.00.0000
21296 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
21297 Useful for bootloaders.
21300 \labelwidthstring 00.00.0000
21313 -asm= sets the full path and name of an external assembler to call.
21316 \labelwidthstring 00.00.0000
21329 -link= sets the full path and name of an external linker to call.
21332 \labelwidthstring 00.00.0000
21346 \begin_inset LatexCommand \index{PIC16!MPLAB}
21350 compatibility option.
21351 Currently only suppresses special gpasm directives.
21353 \layout Subsubsection
21354 Optimization Options
21357 \labelwidthstring 00.00.0000
21370 -optimize-goto Try to use (conditional) BRA instead of GOTO
21373 \labelwidthstring 00.00.0000
21386 -optimize-cmp Try to optimize some compares.
21389 \labelwidthstring 00.00.0000
21402 -optimize-df Analyze the dataflow of the generated code and improve it.
21405 \labelwidthstring 00.00.0000
21418 -obanksel=nn Set optimization level for inserting BANKSELs.
21424 \labelwidthstring 00.00.0000
21428 \labelwidthstring 00.00.0000
21429 1 checks previous used register and if it is the same then does not emit
21430 BANKSEL, accounts only for labels.
21433 \labelwidthstring 00.00.0000
21434 2 tries to check the location of (even different) symbols and removes BANKSELs
21435 if they are in the same bank.
21440 Important: There might be problems if the linker script has data sections
21441 across bank borders!
21444 \layout Subsubsection
21448 \labelwidthstring 00.00.0000
21461 -nodefaultlibs do not link default libraries when linking
21464 \labelwidthstring 00.00.0000
21477 -no-crt Don't link the default run-time modules
21480 \labelwidthstring 00.00.0000
21493 -use-crt= Use a custom run-time module instead of the defaults.
21495 \layout Subsubsection
21499 Debugging options enable extra debugging information in the output files.
21502 \labelwidthstring 00.00.0000
21515 -debug-xtra Similar to -
21528 \begin_inset LatexCommand \index{-\/-debug}
21532 , but dumps more information.
21535 \labelwidthstring 00.00.0000
21548 -debug-ralloc Force register allocator to dump <source>.d file with debugging
21550 <source> is the name of the file compiled.
21553 \labelwidthstring 00.00.0000
21566 -pcode-verbose Enable pcode debugging information in translation.
21569 \labelwidthstring 00.00.0000
21582 -denable-peeps Force the usage of peepholes.
21586 \labelwidthstring 00.00.0000
21599 -gstack Trace push/pops for stack pointer overflow
21602 \labelwidthstring 00.00.0000
21615 -call-tree dump call tree in .calltree file
21618 Enviromental Variables
21621 There is a number of enviromental variables that can be used when running
21622 SDCC to enable certain optimizations or force a specific program behaviour.
21623 these variables are primarily for debugging purposes so they can be enabled/dis
21627 Currently there is only two such variables available:
21630 \labelwidthstring 00.00.0000
21631 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
21632 bitfields is optimized by directly loading FSR0 with the address of the
21633 bitfield structure.
21634 Normally SDCC will cast the bitfield structure to a bitfield pointer and
21636 This step saves data ram and code space for functions that perform heavy
21639 80 bytes of code space are saved when compiling malloc.c with this option).
21643 \labelwidthstring 00.00.0000
21644 NO_REG_OPT do not perform pCode registers optimization.
21645 This should be used for debugging purposes.
21646 In some where bugs in the pcode optimizer are found, users can benefit
21647 from temporarily disabling the optimizer until the bug is fixed.
21650 Preprocessor Macros
21654 \begin_inset LatexCommand \index{PIC16}
21658 port defines the following preprocessor macros while translating a source.
21662 \begin_inset Tabular
21663 <lyxtabular version="3" rows="6" columns="2">
21665 <column alignment="center" valignment="top" leftline="true" width="0">
21666 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21667 <row topline="true" bottomline="true">
21668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21685 <row topline="true">
21686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21698 Port identification
21703 <row topline="true">
21704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21728 Port identification (same as above)
21733 <row topline="true">
21734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21746 MCU Identification.
21751 is the microcontrol identification number, i.e.
21757 <row topline="true">
21758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21782 MCU Identification (same as above)
21787 <row topline="true" bottomline="true">
21788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21800 nnn = SMALL or LARGE respectively according to the stack model used
21812 In addition the following macros are defined when calling assembler:
21816 \begin_inset Tabular
21817 <lyxtabular version="3" rows="4" columns="2">
21819 <column alignment="center" valignment="top" leftline="true" width="0">
21820 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21821 <row topline="true" bottomline="true">
21822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21839 <row topline="true">
21840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21852 MCU Identification.
21857 is the microcontrol identification number, i.e.
21863 <row topline="true">
21864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21876 nnn = SMALL or LARGE respectively according to the memory model used for
21882 <row topline="true" bottomline="true">
21883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21895 nnn = SMALL or LARGE respectively according to the stack model used
21911 \begin_inset LatexCommand \index{PIC16}
21915 port uses the following directories for searching header files and libraries.
21919 \begin_inset Tabular
21920 <lyxtabular version="3" rows="3" columns="4">
21922 <column alignment="center" valignment="top" leftline="true" width="0">
21923 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21924 <column alignment="center" valignment="top" width="0">
21925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21926 <row topline="true" bottomline="true">
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21960 <row topline="true">
21961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21965 PREFIX/sdcc/include/pic16
21969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21973 PIC16 specific headers
21977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21994 <row topline="true" bottomline="true">
21995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21999 PREFIX/sdcc/lib/pic16
22003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22007 PIC16 specific libraries
22011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22036 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
22044 \begin_inset LatexCommand \index{PIC16}
22048 port currently supports the following pragmas:
22051 \labelwidthstring 00.00.0000
22053 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
22058 \begin_inset LatexCommand \index{PIC16!stack}
22062 forces the code generator to initialize the stack & frame pointers at a
22064 This is an adhoc solution for cases where no STACK directive is available
22065 in the linker script or gplink is not instructed to create a stack section.
22068 stack pragma should be used only once in a project.
22069 Multiple pragmas may result in indeterminate behaviour of the program.
22074 The old format (ie.
22075 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
22076 cross page boundaries (or even exceed the available data RAM) and crash
22078 Make sure that stack does not cross page boundaries when using the SMALL
22085 The format is as follows:
22088 #pragma stack bottom_address [stack_size]
22095 is the lower bound of the stack section.
22096 The stack pointer initially will point at address (bottom_address+stack_size-1).
22105 /* initializes stack of 100 bytes at RAM address 0x200 */
22108 #pragma stack 0x200 100
22111 If the stack_size field is omitted then a stack is created with the default
22113 This size might be enough for most programs, but its not enough for operations
22114 with deep function nesting or excessive stack usage.
22117 \labelwidthstring 00.00.0000
22119 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
22123 place a function symbol at static FLASH address
22132 /* place function test_func at 0x4000 */
22135 #pragma code test_func 0x4000
22141 \labelwidthstring 00.00.0000
22142 library instructs the linker to use a library module.
22147 #pragma library module_name
22154 can be any library or object file (including its path).
22155 Note that there are four reserved keywords which have special meaning.
22160 \begin_inset Tabular
22161 <lyxtabular version="3" rows="6" columns="3">
22163 <column alignment="center" valignment="top" leftline="true" width="0">
22164 <column alignment="block" valignment="top" leftline="true" width="20page%">
22165 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
22166 <row topline="true" bottomline="true">
22167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22192 <row topline="true">
22193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22207 ignore all library pragmas
22211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22222 <row topline="true">
22223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22254 <row topline="true">
22255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22269 link the Math libarary
22273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22286 <row topline="true">
22287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22301 link the I/O library
22305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22318 <row topline="true" bottomline="true">
22319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22333 link the debug library
22337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22356 * is the device number, i.e.
22357 452 for PIC18F452 MCU.
22360 This feature allows for linking with specific libraries withoug having to
22361 explicit name them in the command line.
22366 keyword will reject all modules specified by the library pragma.
22369 \labelwidthstring 00.00.0000
22370 udata pragma udata instructs the compiler to emit code so that linker will
22371 place a variable at a specific memory bank
22380 /* places variable foo at bank2 */
22383 #pragma udata bank2 foo
22389 In order for this pragma to work extra SECTION directives should be added
22390 in the .lkr script.
22391 In the following example a sample .lkr file is shown:
22397 // Sample linker script for the PIC18F452 processor
22403 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
22406 CODEPAGE NAME=page START=0x2A END=0x7FFF
22409 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
22412 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
22415 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
22418 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
22421 ACCESSBANK NAME=accessram START=0x0 END=0x7F
22427 DATABANK NAME=gpr0 START=0x80 END=0xFF
22430 DATABANK NAME=gpr1 START=0x100 END=0x1FF
22433 DATABANK NAME=gpr2 START=0x200 END=0x2FF
22436 DATABANK NAME=gpr3 START=0x300 END=0x3FF
22439 DATABANK NAME=gpr4 START=0x400 END=0x4FF
22442 DATABANK NAME=gpr5 START=0x500 END=0x5FF
22445 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
22451 SECTION NAME=CONFIG ROM=config
22457 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
22460 SECTION NAME=bank1 RAM=gpr1 # should be added to link
22463 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
22466 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
22469 SECTION NAME=bank4 RAM=gpr4
22472 SECTION NAME=bank5 RAM=gpr5
22475 The linker will recognise the section name set in the pragma statement and
22476 will position the variable at the memory bank set with the RAM field at
22477 the SECTION line in the linker script file.
22481 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
22488 There is one main header file
22489 \begin_inset LatexCommand \index{PIC16!Header files}
22493 that can be included to the source files using the pic16
22494 \begin_inset LatexCommand \index{PIC16}
22504 This header file contains the definitions for the processor special registers,
22505 so it is necessary if the source accesses them.
22506 It can be included by adding the following line in the beginning of the
22510 #include <pic18fregs.h>
22513 The specific microcontroller is selected within the pic18fregs.h automatically,
22514 so the same source can be used with a variety of devices.
22521 \begin_inset LatexCommand \index{PIC16!Libraries}
22526 \begin_inset LatexCommand \index{PIC16}
22530 port depends on are the microcontroller device libraries which contain
22531 the symbol definitions for the microcontroller special function registers.
22532 These libraries have the format pic18fxxxx.lib, where
22536 is the microcontroller identification number.
22537 The specific library is selected automatically by the compiler at link
22538 stage according to the selected device.
22541 Libraries are created with gplib which is part of the gputils package
22542 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22548 \layout Subsubsection*
22549 Building the libraries
22552 Before using SDCC/pic16 there are some libraries that need to be compiled.
22553 This process is not done automatically by SDCC since not all users use
22554 SDCC for pic16 projects.
22555 So each user should compile the libraries separately.
22558 The steps to compile the pic16 libraries under Linux are:
22561 cd device/lib/pic16
22576 su -c 'make install' # install the libraries, you need the root password
22579 If you need to install the headers too, do:
22585 su -c 'make install' # install the headers, you need the root password
22588 There exist a special target to build the I/O libraries.
22589 This target is not automatically build because it will build the I/O library
22595 This way building will take quite a lot of time.
22596 Users are advised to edit the
22598 device/lib/pic16/pics.build
22600 file and then execute:
22609 The following memory models are supported by the PIC16 port:
22618 Memory model affects the default size of pointers within the source.
22619 The sizes are shown in the next table:
22623 \begin_inset Tabular
22624 <lyxtabular version="3" rows="3" columns="3">
22626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22627 <column alignment="center" valignment="top" leftline="true" width="0">
22628 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22629 <row topline="true" bottomline="true">
22630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22634 Pointer sizes according to memory model
22638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22655 <row topline="true" bottomline="true">
22656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22664 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22681 <row topline="true" bottomline="true">
22682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22690 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
22698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22714 It is advisable that all sources within a project are compiled with the
22716 If one wants to override the default memory model, this can be done by
22717 declaring a pointer as
22726 Far selects large memory model's pointers, while near selects small memory
22730 The standard device libraries (see
22731 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
22735 ) contain no reference to pointers, so they can be used with both memory
22743 \begin_inset LatexCommand \index{PIC16!stack}
22747 implementation for the PIC16 port uses two indirect registers, FSR1 and
22751 \labelwidthstring 00.00.0000
22752 FSR1 is assigned as stack pointer
22755 \labelwidthstring 00.00.0000
22756 FSR2 is assigned as frame pointer
22759 The following stack models are supported by the PIC16 port
22780 model means that only the FSRxL byte is used to access stack and frame,
22787 uses both FSRxL and FSRxH registers.
22788 The following table shows the stack/frame pointers sizes according to stack
22789 model and the maximum space they can address:
22793 \begin_inset Tabular
22794 <lyxtabular version="3" rows="3" columns="3">
22796 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22797 <column alignment="center" valignment="top" leftline="true" width="0">
22798 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22799 <row topline="true" bottomline="true">
22800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22804 Stack & Frame pointer sizes according to stack model
22808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22825 <row topline="true">
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22842 <cell alignment="center" valignment="top" topline="true" leftline="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" usebox="none">
22888 stack model is currently not working properly throughout the code generator.
22889 So its use is not advised.
22890 Also there are some other points that need special care:
22895 Do not create stack sections with size more than one physical bank (that
22899 Stack sections should no cross physical bank limits (i.e.
22900 #pragma stack 0x50 0x100)
22903 These limitations are caused by the fact that only FSRxL is modified when
22904 using SMALL stack model, so no more than 256 bytes of stack can be used.
22905 This problem will disappear after LARGE model is fully implemented.
22911 In addition to the standard SDCC function keywords, PIC16
22912 \begin_inset LatexCommand \index{PIC16}
22916 port makes available two more:
22919 \labelwidthstring 00.00.0000
22921 \begin_inset LatexCommand \index{PIC16!wparam}
22925 Use the WREG to pass one byte of the first function argument.
22926 This improves speed but you may not use this for functions with arguments
22927 that are called via function pointers, otherwise the first byte of the
22928 first parameter will get lost.
22932 void func_wparam(int a) wparam
22938 /* WREG hold the lower part of a */
22941 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22951 \labelwidthstring 00.00.0000
22953 \begin_inset LatexCommand \index{PIC16!shadowregs}
22957 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22958 hardware shadow registers which hold the values of WREG, STATUS and BSR
22960 This can be done by adding the keyword
22968 keyword in the function's header.
22971 void isr_shadow(void) shadowregs interrupt 1
22987 instructs the code generator not to store/restore WREG, STATUS, BSR when
22988 entering/exiting the ISR.
22991 Function return values
22994 Return values from functions are placed to the appropriate registers following
22995 a modified Microchip policy optimized for SDCC.
22996 The following table shows these registers:
23000 \begin_inset Tabular
23001 <lyxtabular version="3" rows="6" columns="2">
23003 <column alignment="center" valignment="top" leftline="true" width="0">
23004 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23005 <row topline="true" bottomline="true">
23006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23018 destination register
23023 <row topline="true">
23024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23041 <row topline="true">
23042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23059 <row topline="true">
23060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23077 <row topline="true">
23078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23090 FSR0L:PRODH:PRODL:WREG
23095 <row topline="true" bottomline="true">
23096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23108 on stack, FSR0 points to the beginning
23124 \begin_inset LatexCommand \index{PIC16!interrupt}
23128 service routine (ISR) is declared using the
23135 void isr(void) interrupt
23153 is the interrupt number, which for PIC18F devices can be:
23157 \begin_inset Tabular
23158 <lyxtabular version="3" rows="4" columns="3">
23160 <column alignment="center" valignment="top" leftline="true" width="0">
23161 <column alignment="center" valignment="top" leftline="true" width="0">
23162 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23163 <row topline="true" bottomline="true">
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23186 Interrupt Vector Address
23191 <row topline="true">
23192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23248 HIGH priority interrupts
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23261 <row topline="true" bottomline="true">
23262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23274 LOW priority interrupts
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23294 When generating assembly code for ISR the code generator places a
23300 Interrupt Vector Address
23302 which points at the genetated ISR.
23303 This single GOTO instruction is part of an automatically generated
23305 interrupt entry point
23308 The actuall ISR code is placed as normally would in the code space.
23309 Upon interrupt request, the GOTO instruction is executed which jumps to
23311 When declaring interrupt functions as _naked this GOTO instruction is
23316 The whole interrupt functions is therefore placed at the Interrupt Vector
23317 Address of the specific interrupt.
23318 This is not a problem for the LOW priority interrupts, but it is a problem
23319 for the RESET and the HIGH priority interrupts because code may be written
23320 at the next interrupt´s vector address and cause undeterminate program
23321 behaviour if that interrupt is raised.
23326 This is not a problem when
23329 this is a HIGH interrupt ISR and LOW interrupts are
23336 when the ISR is small enough not to reach the next interrupt´s vector address.
23347 is possible to be omitted.
23348 This way a function is generated similar to an ISR, but it is not assigned
23352 When entering an interrupt, currently the PIC16
23353 \begin_inset LatexCommand \index{PIC16}
23357 port automatically saves the following registers:
23369 PROD (PRODL and PRODH)
23372 FSR0 (FSR0L and FSR0H)
23375 These registers are restored upon return from the interrupt routine.
23380 NOTE that when the _naked attribute is specified for an interrupt routine,
23381 then NO registers are stored or restored.
23391 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
23392 There are 3 types of generic pointers currently implemented data, code
23393 and eeprom pointers.
23394 They are differentiated by the value of the 7th and 6th bits of the upper
23399 \begin_inset Tabular
23400 <lyxtabular version="3" rows="5" columns="5">
23402 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23403 <column alignment="center" valignment="top" width="0">
23404 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23405 <column alignment="center" valignment="top" width="0">
23406 <column alignment="left" valignment="top" rightline="true" width="0">
23407 <row topline="true" bottomline="true">
23408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23436 rest of the pointer
23440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23449 <row topline="true" bottomline="true">
23450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23482 uuuuuu uuuuxxxx xxxxxxxx
23486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23490 a 12-bit data pointer in data RAM memory
23495 <row bottomline="true">
23496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23528 uxxxxx xxxxxxxx xxxxxxxx
23532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23536 a 21-bit code pointer in FLASH memory
23541 <row bottomline="true">
23542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
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">
23566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23574 uuuuuu uuuuuuxx xxxxxxxx
23578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23582 a 10-bit eeprom pointer in EEPROM memory
23587 <row bottomline="true">
23588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23620 xxxxxx xxxxxxxx xxxxxxxx
23624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23628 unimplemented pointer type
23640 Generic pointer are read and written with a set of library functions which
23641 read/write 1, 2, 3, 4 bytes.
23646 \layout Subsubsection
23647 Standard I/O Streams
23654 the type FILE is defined as:
23657 typedef char * FILE;
23660 This type is the stream type implemented I/O in the PIC18F devices.
23661 Also the standard input and output streams are declared in stdio.h:
23664 extern FILE * stdin;
23667 extern FILE * stdout;
23670 The FILE type is actually a generic pointer which defines one more type
23671 of generic pointers, the
23676 This new type has the format:
23680 \begin_inset Tabular
23681 <lyxtabular version="3" rows="2" columns="7">
23683 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23684 <column alignment="center" valignment="top" width="0">
23685 <column alignment="center" valignment="top" leftline="true" width="0">
23686 <column alignment="center" valignment="top" leftline="true" width="0">
23687 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23688 <column alignment="center" valignment="top" width="0">
23689 <column alignment="left" valignment="top" rightline="true" width="0">
23690 <row topline="true" bottomline="true">
23691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23735 rest of the pointer
23739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23748 <row topline="true" bottomline="true">
23749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23805 upper byte high nubble is 0x2n, the rest are zeroes
23817 Currently implemented there are 3 types of streams defined:
23821 \begin_inset Tabular
23822 <lyxtabular version="3" rows="4" columns="4">
23824 <column alignment="center" valignment="top" leftline="true" width="0">
23825 <column alignment="center" valignment="top" leftline="true" width="0">
23826 <column alignment="center" valignment="top" leftline="true" width="0">
23827 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23828 <row topline="true" bottomline="true">
23829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23862 <row topline="true">
23863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23893 Writes/Reads characters via the USART peripheral
23898 <row topline="true">
23899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23929 Writes/Reads characters via the MSSP peripheral
23934 <row topline="true" bottomline="true">
23935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23965 Writes/Reads characters via used defined functions
23977 The stream identifiers are declared as macros in the stdio.h header.
23980 In the libc library there exist the functions that are used to write to
23981 each of the above streams.
23985 \labelwidthstring 00.00.0000
23998 _stream_usart_putchar writes a character at the USART stream
24001 \labelwidthstring 00.00.0000
24014 _stream_mssp_putchar writes a character at the MSSP stream
24017 \labelwidthstring 00.00.0000
24018 putchar dummy function.
24019 This writes a character to a user specified manner.
24022 In order to increase performance
24026 is declared in stdio.h as having its parameter in WREG (it has the wparam
24028 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
24029 in a user-friendly way.
24034 is the name of the variable that holds the character to print.
24035 An example follows:
24038 #include <pic18fregs.h>
24050 PORTA = c; /* dump character c to PORTA */
24063 stdout = STREAM_USER; /* this is not necessary, since stdout points
24066 * by default to STREAM_USER */
24069 printf (¨This is a printf test
24079 \layout Subsubsection
24083 PIC16 contains an implementation of the printf-family of functions.
24084 There exist the following functions:
24087 extern unsigned int sprintf(char *buf, char *fmt, ...);
24090 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
24096 extern unsigned int printf(char *fmt, ...);
24099 extern unsigned int vprintf(char *fmt, va_lista ap);
24105 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
24108 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
24111 For sprintf and vsprintf
24115 should normally be a data pointer where the resulting string will be placed.
24116 No range checking is done so the user should allocate the necessery buffer.
24117 For fprintf and vfprintf
24121 should be a stream pointer (i.e.
24122 stdout, STREAM_MSSP, etc...).
24124 \layout Subsubsection
24128 The PIC18F family of microcontrollers supports a number of interrupt sources.
24129 A list of these interrupts is shown in the following table:
24133 \begin_inset Tabular
24134 <lyxtabular version="3" rows="11" columns="4">
24136 <column alignment="left" valignment="top" leftline="true" width="0">
24137 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24138 <column alignment="left" valignment="top" leftline="true" width="0">
24139 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24140 <row topline="true" bottomline="true">
24141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24174 <row topline="true">
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24183 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24187 PORTB change interrupt
24191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24203 EEPROM/FLASH write complete interrupt
24208 <row topline="true">
24209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24221 INT0 external interrupt
24225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24237 Bus collision interrupt
24242 <row topline="true">
24243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24255 INT1 external interrupt
24259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24271 Low voltage detect interrupt
24276 <row topline="true">
24277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24289 INT2 external interrupt
24293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24305 Parallel slave port interrupt
24310 <row topline="true">
24311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24323 CCP1 module interrupt
24327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24339 AD convertion complete interrupt
24344 <row topline="true">
24345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24357 CCP2 module interrupt
24361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24373 USART receive interrupt
24378 <row topline="true">
24379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24391 TMR0 overflow interrupt
24395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24407 USART transmit interrupt
24412 <row topline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24425 TMR1 overflow interrupt
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24441 SSP receive/transmit interrupt
24446 <row topline="true">
24447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24459 TMR2 matches PR2 interrupt
24463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24480 <row topline="true" bottomline="true">
24481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24493 TMR3 overflow interrupt
24497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24521 The prototypes for these names are defined in the header file
24528 In order to simplify signal handling, a number of macros is provided:
24531 \labelwidthstring 00.00.0000
24532 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
24533 high priority interrupts.
24538 is the function name to use.
24541 \labelwidthstring 00.00.0000
24542 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
24543 low priority interrupt.
24548 is the function name to use.
24551 \labelwidthstring 00.00.0000
24552 DEF_HANDLER(sig,handler) define a handler for signal
24557 \labelwidthstring 00.00.0000
24558 END_DEF end the declaration of the dispatch table.
24561 Additionally there are two more macros to simplify the declaration of the
24565 \labelwidthstring 00.00.0000
24568 SIGHANDLER(handler)
24570 this declares the function prototype for the
24577 \labelwidthstring 00.00.0000
24578 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
24581 An example of using the macros above is shown below:
24584 #include <pic18fregs.h>
24587 #include <signal.h>
24591 DEF_INTHIGH(high_int)
24594 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
24597 DEF_HANDLER(SIG_BCOL, _bcol_handler)
24604 SIGHANDLER(_tmr0_handler)
24610 /* action to be taken when timer 0 overflows */
24617 SIGHANDLERNAKED(_bcol_handler)
24626 /* action to be taken when bus collision occurs */
24642 Special care should be taken when using the above scheme:
24645 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
24648 when declaring SIGHANDLERNAKED handler never forget to use
24652 for proper returning.
24658 Here you can find some general tips for compiling programs with SDCC/pic16.
24660 \layout Subsubsection
24665 \begin_inset LatexCommand \index{PIC16!stack}
24669 size (that is 64 bytes) probably is enough for many programs.
24670 One must take care that when there are many levels of function nesting,
24671 or there is excessive usage of stack, its size should be extended.
24672 An example of such a case is the printf/sprintf family of functions.
24673 If you encounter problems like not being able to print integers, then you
24674 need to set the stack size around the maximum (256 for small stack model).
24675 The following diagram shows what happens when calling printf to print an
24679 printf () --> ltoa () --> ultoa () --> divschar ()
24682 It is should be understood that stack is easily consumed when calling complicate
24684 Using command line arguments like -
24696 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
24698 Other ways to reduce stack usage may exist.
24704 The PIC16 Port currently does not pass SDCC's regression test
24705 \begin_inset LatexCommand \index{Regression test (PIC16)}
24710 \begin_inset LatexCommand \ref{sec:Quality-control}
24714 ) and thus the nightly regression tests for the PIC16 target are currently
24715 disabled for all hosts except for
24720 This means you can see the result of the PIC16 regression tests f.e.
24721 by checking the log files in
24722 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
24726 (pick the most up to date file there, scroll down, lend a hand).
24732 There are several approaches to debugging your code.
24733 This chapter is meant to show your options and to give detail on some of
24738 When writing your code:
24741 write your code with debugging in mind (avoid duplicating code, put conceptually
24742 similar variables into structs, use structured code, have strategic points
24743 within your code where all variables are consistent, ...)
24746 run a syntax-checking tool like splint
24747 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24752 \begin_inset LatexCommand \index{lint (syntax checking tool)}
24769 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24776 for the high level code use a C-compiler (like f.e.
24777 GCC) to compile run and debug the code on your host.
24791 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24795 ) on howto handle syntax extensions like __xdata, __at(), ...
24799 use another C-compiler to compile code for your target.
24800 Always an option but not recommended:) And not very likely to help you.
24801 If you seriously consider walking this path you should at least occasionally
24802 check portability of your code.
24803 Most commercial compiler vendors will offer an evaluation version so you
24804 can test compile your code or snippets of your code.
24807 Debugging on a simulator:
24810 there is a separate section about SDCDB (section
24811 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
24818 or (8051 specific) use a freeware/commercial simulator which interfaces
24820 \begin_inset LatexCommand \index{AOMF, AOMF51}
24825 \begin_inset LatexCommand \ref{OMF file}
24829 ) optionally generated by SDCC.
24832 Debugging On-target:
24835 use a MCU port pin to serially output debug data to the RS232 port of your
24837 You'll probably want some level shifting device typically involving a MAX232
24839 If the hardware serial port of the MCU is not available search for 'Software
24840 UART' in your favourite search machine.
24843 use an on-target monitor.
24844 In this context a monitor is a small program which usually accepts commands
24845 via a serial line and allows to set program counter, to single step through
24846 a program and read/write memory locations.
24847 For the 8051 good examples of monitors are paulmon and cmon51 (see section
24849 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
24856 toggle MCU port pins at strategic points within your code and use an oscilloscop
24860 digital oscilloscope
24863 \begin_inset LatexCommand \index{Oscilloscope}
24867 with deep trace memory is really helpful especially if you have to debug
24868 a realtime application.
24869 If you need to monitor more pins than your oscilloscope provides you can
24870 sometimes get away with a small R-2R network.
24871 On a single channel oscilloscope you could f.e.
24872 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24874 \begin_inset Formula $\Omega$
24877 resistor and the other one by a 5\SpecialChar ~
24879 \begin_inset Formula $\Omega$
24882 resistor to the oscilloscope probe (check output drive capability of the
24883 pins you want to monitor).
24884 If you need to monitor many more pins a
24904 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24909 Usually very expensive.
24910 And very nice to have too.
24911 And usually locks you (for years...) to the devices the ICE can emulate.
24915 use a remote debugger.
24916 In most 8-bit systems the symbol information is not available on the target,
24917 and a complete debugger is too bulky for the target system.
24918 Therefore usually a debugger on the host system connects to an on-target
24919 debugging stub which accepts only primitive commands.
24922 Terms to enter into your favourite search engine could be 'remote debugging',
24923 'gdb stub' or 'inferior debugger'.
24927 use an on target hardware debugger.
24928 Some of the more modern MCUs include hardware support for setting break
24929 points and monitoring/changing variables by using dedicated hardware pins.
24930 This facility doesn't require additional code to run on the target and
24935 doesn't affect runtime behaviour until a breakpoint is hit.
24936 For the mcs51 most hardware debuggers use the AOMF
24937 \begin_inset LatexCommand \index{AOMF, AOMF51}
24942 \begin_inset LatexCommand \ref{OMF file}
24953 if you are not familiar with any of the following terms you're likely to
24954 run into problems rather sooner than later:
24971 As an embedded programmer you
24975 to know them so why not look them up
24979 you have problems?)
24982 tell someone else about your problem (actually this is a surprisingly effective
24983 means to hunt down the bug even if the listener is not familiar with your
24985 As 'failure to communicate' is probably one of the job-induced deformations
24986 of an embedded programmer this is highly encouraged.
24989 Debugging with SDCDB
24990 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24995 \begin_inset LatexCommand \index{SDCDB (debugger)}
25002 SDCC is distributed with a source level debugger
25003 \begin_inset LatexCommand \index{Debugger}
25008 The debugger uses a command line interface, the command repertoire of the
25009 debugger has been kept as close to gdb
25010 \begin_inset LatexCommand \index{gdb}
25014 (the GNU debugger) as possible.
25015 The configuration and build process is part of the standard compiler installati
25016 on, which also builds and installs the debugger in the target directory
25017 specified during configuration.
25018 The debugger allows you debug BOTH at the C source and at the ASM source
25022 Compiling for Debugging
25038 \begin_inset LatexCommand \index{-\/-debug}
25042 option must be specified for all files for which debug information is to
25044 The compiler generates a .adb file for each of these files.
25045 The linker creates the .cdb
25046 \begin_inset LatexCommand \index{<file>.cdb}
25051 \begin_inset LatexCommand \index{<file>.adb}
25055 files and the address information.
25056 This .cdb is used by the debugger.
25059 How the Debugger Works
25074 -debug option is specified the compiler generates extra symbol information
25075 some of which are put into the assembler source and some are put into the
25077 Then the linker creates the .cdb file from the individual .adb files with
25078 the address information for the symbols.
25079 The debugger reads the symbolic information generated by the compiler &
25080 the address information generated by the linker.
25081 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
25082 execution is controlled by the debugger.
25083 When a command is issued for the debugger, it translates it into appropriate
25084 commands for the simulator.
25085 (Currently SDCDM only connects to the simulator but
25090 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
25094 is an effort to connect directly to the hardware.)
25097 Starting the Debugger SDCDB
25100 The debugger can be started using the following command line.
25101 (Assume the file you are debugging has the file name foo).
25115 The debugger will look for the following files.
25118 foo.c - the source file.
25121 foo.cdb - the debugger symbol information file.
25124 foo.ihx - the Intel hex format
25125 \begin_inset LatexCommand \index{Intel hex format}
25132 SDCDB Command Line Options
25147 -directory=<source file directory> this option can used to specify the directory
25149 The debugger will look into the directory list specified for source, cdb
25151 The items in the directory list must be separated by ':', e.g.
25152 if the source files can be in the directories /home/src1 and /home/src2,
25165 -directory option should be -
25177 -directory=/home/src1:/home/src2.
25178 Note there can be no spaces in the option.
25182 -cd <directory> - change to the <directory>.
25185 -fullname - used by GUI front ends.
25188 -cpu <cpu-type> - this argument is passed to the simulator please see the
25189 simulator docs for details.
25192 -X <Clock frequency > this options is passed to the simulator please see
25193 the simulator docs for details.
25196 -s <serial port file> passed to simulator see the simulator docs for details.
25199 -S <serial in,out> passed to simulator see the simulator docs for details.
25202 -k <port number> passed to simulator see the simulator docs for details.
25205 SDCDB Debugger Commands
25208 As mentioned earlier the command interface for the debugger has been deliberatel
25209 y kept as close the GNU debugger gdb, as possible.
25210 This will help the integration with existing graphical user interfaces
25211 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
25212 If you use a graphical user interface for the debugger you can skip this
25215 \layout Subsubsection*
25216 break [line | file:line | function | file:function]
25219 Set breakpoint at specified line or function:
25228 sdcdb>break foo.c:100
25230 sdcdb>break funcfoo
25232 sdcdb>break foo.c:funcfoo
25234 \layout Subsubsection*
25235 clear [line | file:line | function | file:function ]
25238 Clear breakpoint at specified line or function:
25247 sdcdb>clear foo.c:100
25249 sdcdb>clear funcfoo
25251 sdcdb>clear foo.c:funcfoo
25253 \layout Subsubsection*
25257 Continue program being debugged, after breakpoint.
25259 \layout Subsubsection*
25263 Execute till the end of the current function.
25265 \layout Subsubsection*
25269 Delete breakpoint number 'n'.
25270 If used without any option clear ALL user defined break points.
25272 \layout Subsubsection*
25273 info [break | stack | frame | registers ]
25276 info break - list all breakpoints
25279 info stack - show the function call stack.
25282 info frame - show information about the current execution frame.
25285 info registers - show content of all registers.
25287 \layout Subsubsection*
25291 Step program until it reaches a different source line.
25292 Note: pressing <return> repeats the last command.
25294 \layout Subsubsection*
25298 Step program, proceeding through subroutine calls.
25300 \layout Subsubsection*
25304 Start debugged program.
25306 \layout Subsubsection*
25310 Print type information of the variable.
25312 \layout Subsubsection*
25316 print value of variable.
25318 \layout Subsubsection*
25322 load the given file name.
25323 Note this is an alternate method of loading file for debugging.
25325 \layout Subsubsection*
25329 print information about current frame.
25331 \layout Subsubsection*
25335 Toggle between C source & assembly source.
25337 \layout Subsubsection*
25338 ! simulator command
25341 Send the string following '!' to the simulator, the simulator response is
25343 Note the debugger does not interpret the command being sent to the simulator,
25344 so if a command like 'go' is sent the debugger can loose its execution
25345 context and may display incorrect values.
25347 \layout Subsubsection*
25353 My name is Bobby Brown"
25356 Interfacing SDCDB with DDD
25363 The screenshot was converted from png to eps with:
25364 \begin_inset Quotes sld
25367 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
25368 \begin_inset Quotes srd
25371 which produces a pretty compact eps file which is free from compression
25375 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
25376 as this broke the build system on Sourceforge (pdf-file was broken.
25377 pdflatex does not accept eps files).
25399 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
25405 shows a screenshot of a debugging session with DDD
25406 \begin_inset LatexCommand \index{DDD (debugger)}
25410 (Unix only) on a simulated 8032.
25411 The debugging session might not run as smoothly as the screenshot suggests.
25412 The debugger allows setting of breakpoints, displaying and changing variables,
25413 single stepping through C and assembler code.
25416 The source was compiled with
25441 -debug ddd_example.c
25454 and DDD was invoked with
25461 ddd -debugger "sdcdb -cpu 8032 ddd_example"
25468 Check that the double quotes or an apostroph within the command line survive
25469 the LyX tool chain.
25470 Previously the apostrophs got slanted in the PDF output so a cut and paste
25478 Interfacing SDCDB with XEmacs
25479 \begin_inset LatexCommand \index{XEmacs}
25484 \begin_inset LatexCommand \index{Emacs}
25491 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
25492 sdcdb.el and sdcdbsrc.el.
25493 These two files can be found in the $(prefix)/bin directory after the installat
25495 These files need to be loaded into XEmacs for the interface to work.
25496 This can be done at XEmacs startup time by inserting the following into
25497 your '.xemacs' file (which can be found in your HOME directory):
25503 (load-file sdcdbsrc.el)
25509 .xemacs is a lisp file so the () around the command is REQUIRED.
25510 The files can also be loaded dynamically while XEmacs is running, set the
25511 environment variable 'EMACSLOADPATH' to the installation bin directory
25512 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
25513 To start the interface enter the following command:
25527 You will prompted to enter the file name to be debugged.
25532 The command line options that are passed to the simulator directly are
25533 bound to default values in the file sdcdbsrc.el.
25534 The variables are listed below, these values maybe changed as required.
25537 sdcdbsrc-cpu-type '51
25540 sdcdbsrc-frequency '11059200
25543 sdcdbsrc-serial nil
25546 The following is a list of key mapping for the debugger interface.
25558 ;;key\SpecialChar ~
25572 binding\SpecialChar ~
25596 ;;---\SpecialChar ~
25610 -------\SpecialChar ~
25653 m-src\SpecialChar ~
25681 sdcdb-back-from-src\SpecialChar ~
25710 rom-src\SpecialChar ~
25720 SDCDB continue command
25738 sdcdb-step-from-src\SpecialChar ~
25767 hatis-c-sexp\SpecialChar ~
25777 SDCDB ptypecommand for data at
25844 sdcdbsrc-delete\SpecialChar ~
25859 B Delete all breakpoints if no arg
25908 given or delete arg (C-u arg x)
25927 -frame\SpecialChar ~
25942 SDCDB Display current frame if no arg,
25991 given or display frame arg
26059 sdcdbsrc-goto-sdcdb\SpecialChar ~
26069 Goto the SDCDB output buffer
26088 t-c-sexp\SpecialChar ~
26099 SDCDB print command for data at
26166 sdcdbsrc-goto-sdcdb\SpecialChar ~
26177 o the SDCDB output buffer
26195 sdcdbsrc-mode\SpecialChar ~
26211 Toggles Sdcdbsrc mode (turns it
26227 sdcdb-finish-from-src\SpecialChar ~
26235 SDCDB finish command
26269 Set break for line with point
26284 sdcdbsrc-mode\SpecialChar ~
26300 Toggle Sdcdbsrc mode
26316 dbsrc-srcmode\SpecialChar ~
26342 Here are a few guidelines that will help the compiler generate more efficient
26343 code, some of the tips are specific to this compiler others are generally
26344 good programming practice.
26347 Use the smallest data type to represent your data-value.
26348 If it is known in advance that the value is going to be less than 256 then
26349 use an 'unsigned char' instead of a 'short' or 'int'.
26350 Please note, that ANSI C requires both signed and unsigned chars to be
26351 promoted to 'signed int'
26352 \begin_inset LatexCommand \index{promotion to signed int}
26357 \begin_inset Marginal
26368 before doing any operation.
26370 \begin_inset LatexCommand \index{type promotion}
26375 \begin_inset LatexCommand \label{type promotion}
26379 can be omitted, if the result is the same.
26380 The effect of the promotion rules together with the sign-extension is often
26387 unsigned char uc = 0xfe;
26389 if (uc * uc < 0) /* this is true! */
26408 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
26418 (unsigned char) -12 / (signed char) -3 = ...
26421 No, the result is not 4:
26426 (int) (unsigned char) -12 / (int) (signed char) -3 =
26428 (int) (unsigned char)
26429 0xf4 / (int) (signed char) 0xfd =
26431 (int) 0x00f4 / (int) 0xfffd =
26436 (int) 244 / (int) -3 =
26438 (int) -81 = (int) 0xffaf;
26441 Don't complain, that gcc gives you a different result.
26442 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
26443 Therefore the results are different.
26446 \begin_inset Quotes sld
26450 \begin_inset Quotes srd
26458 If well-defined overflow characteristics are important and negative values
26459 are not, or if you want to steer clear of sign-extension problems when
26460 manipulating bits or bytes, use one of the corresponding unsigned types.
26461 (Beware when mixing signed and unsigned values in expressions, though.)
26464 character types (especially unsigned char) can be used as "tiny" integers,
26465 doing so is sometimes more trouble than it's worth, due to unpredictable
26466 sign extension and increased code size.
26470 Use unsigned when it is known in advance that the value is not going to
26472 This helps especially if you are doing division or multiplication, bit-shifting
26473 or are using an array index.
26476 NEVER jump into a LOOP.
26479 Declare the variables to be local
26480 \begin_inset LatexCommand \index{local variables}
26484 whenever possible, especially loop control variables (induction).
26487 Have a look at the assembly listing to get a
26488 \begin_inset Quotes sld
26492 \begin_inset Quotes srd
26495 for the code generation.
26498 Porting code from or to other compilers
26499 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
26506 check whether endianness of the compilers differs and adapt where needed.
26509 check the device specific header files
26510 \begin_inset LatexCommand \index{Header files}
26515 \begin_inset LatexCommand \index{Include files}
26519 for compiler specific syntax.
26520 Eventually include the file <compiler.h
26521 \begin_inset LatexCommand \index{compiler.h (include file)}
26526 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
26530 to allow using common header files.
26533 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
26540 check whether the startup code contains the correct initialization (watchdog,
26544 check whether the sizes of short, int, long match.
26547 check if some 16 or 32 bit hardware registers require a specific addressing
26548 order (least significant or most significant byte first) and adapt if needed
26557 relate to time and not to lower/upper memory location here, so this is
26562 the same as endianness).
26565 check whether the keyword
26569 is used where needed.
26570 The compilers might differ in their optimization characteristics (as different
26571 versions of the same compiler might also use more clever optimizations
26572 this is good idea anyway).
26574 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
26581 check that the compilers are not told to supress warnings.
26584 check and convert compiler specific extensions (interrupts, memory areas,
26588 check for differences in type promotion.
26589 Especially check for math operations on
26598 For the sake of C99 compatibility SDCC will probably promote these to
26602 more often than other compilers.
26603 Eventually insert explicit casts to
26612 Also check that the ~\SpecialChar ~
26614 \begin_inset LatexCommand \index{\~\/ Operator}
26621 \begin_inset LatexCommand \index{bit}
26627 variables, use the !\SpecialChar ~
26630 \begin_inset LatexCommand \ref{type promotion}
26635 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26642 check the assembly code generated for interrupt routines (f.e.
26643 for calls to possibly non-reentrant library functions).
26646 check whether timing loops result in proper timing (or preferably consider
26647 a rewrite of the code with timer based delays instead).
26650 check for differences in printf parameters (some compilers push (va_arg
26651 \begin_inset LatexCommand \index{vararg, va\_arg}
26655 ) char variables as
26659 others push them as
26665 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
26672 check the resulting memory map
26673 \begin_inset LatexCommand \index{Memory map}
26678 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
26679 ly idata, pdata, xdata).
26680 Eventually check if unexpected library functions are included.
26684 \begin_inset LatexCommand \index{Tools}
26688 included in the distribution
26692 \begin_inset Tabular
26693 <lyxtabular version="3" rows="12" columns="3">
26695 <column alignment="left" valignment="top" leftline="true" width="0pt">
26696 <column alignment="left" valignment="top" leftline="true" width="0pt">
26697 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26698 <row topline="true" bottomline="true">
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26709 <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">
26730 <row topline="true">
26731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26736 \begin_inset LatexCommand \index{uCsim}
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26748 Simulator for various architectures
26752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26761 <row topline="true">
26762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26775 \begin_inset LatexCommand \index{Header files}
26780 \begin_inset LatexCommand \index{Include files}
26788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26792 sdcc/support/scripts
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 header file conversion
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26818 sdcc/support/scripts
26823 <row topline="true">
26824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26858 <row topline="true">
26859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26893 <row topline="true">
26894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26928 <row topline="true">
26929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26963 <row topline="true">
26964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26998 <row topline="true">
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27033 <row topline="true">
27034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27068 <row topline="true" bottomline="true">
27069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27082 \begin_inset LatexCommand \index{packihx (tool)}
27090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27118 \begin_inset LatexCommand \index{Documentation}
27122 included in the distribution
27126 \begin_inset Tabular
27127 <lyxtabular version="3" rows="10" columns="2">
27129 <column alignment="block" valignment="top" leftline="true" width="40col%">
27130 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
27131 <row topline="true" bottomline="true" endhead="true">
27132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27148 Filename / Where to get
27153 <row topline="true">
27154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27158 SDCC Compiler User Guide
27162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27166 You're reading it right now
27178 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
27187 <row topline="true">
27188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27212 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
27221 <row topline="true">
27222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27227 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
27232 \begin_inset LatexCommand \index{Assembler documentation}
27239 \begin_inset LatexCommand \index{aslink}
27244 \begin_inset LatexCommand \index{Linker documentation}
27252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27256 sdcc/as/doc/asxhtm.html
27268 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
27277 <row topline="true">
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27282 SDCC regression test
27283 \begin_inset LatexCommand \index{Regression test}
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27295 sdcc/doc/test_suite_spec.pdf
27307 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
27316 <row topline="true">
27317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27341 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
27350 <row topline="true">
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27355 Notes on debugging with SDCDB
27356 \begin_inset LatexCommand \index{SDCDB (debugger)}
27364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27368 sdcc/debugger/README
27380 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
27389 <row topline="true">
27390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27395 \begin_inset LatexCommand \index{uCsim}
27399 Software simulator for microcontrollers
27403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27436 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
27445 <row topline="true">
27446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27450 Temporary notes on the pic16
27451 \begin_inset LatexCommand \index{PIC16}
27459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27463 sdcc/src/pic16/NOTES
27475 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
27484 <row topline="true" bottomline="true">
27485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27489 SDCC internal documentation (debugging file format)
27493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27526 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
27544 Related open source tools
27545 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
27550 \begin_inset LatexCommand \index{Related tools}
27558 \begin_inset Tabular
27559 <lyxtabular version="3" rows="14" columns="3">
27561 <column alignment="left" valignment="top" leftline="true" width="0pt">
27562 <column alignment="block" valignment="top" leftline="true" width="30line%">
27563 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27564 <row topline="true" bottomline="true">
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27596 <row topline="true">
27597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27602 \begin_inset LatexCommand \index{gpsim (pic simulator)}
27610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27622 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
27631 <row topline="true">
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27637 \begin_inset LatexCommand \index{gputils (pic tools)}
27645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27657 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
27666 <row topline="true">
27667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27687 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
27696 <row topline="true">
27697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27709 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
27714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27718 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
27727 <row topline="true">
27728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27733 \begin_inset LatexCommand \index{indent (source formatting tool)}
27741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27745 Formats C source - Master of the white spaces
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27753 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
27762 <row topline="true">
27763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27768 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
27776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27780 Object file conversion, checksumming, ...
27784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27788 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
27797 <row topline="true">
27798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27803 \begin_inset LatexCommand \index{objdump (tool)}
27811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27815 Object file conversion, ...
27819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27823 Part of binutils (should be there anyway)
27828 <row topline="true">
27829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27841 8051 monitor (hex up-/download, single step, disassemble)
27845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27849 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
27858 <row topline="true">
27859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27864 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27876 Source code documentation system
27880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27884 \begin_inset LatexCommand \url{http://www.doxygen.org}
27893 <row topline="true">
27894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27906 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27914 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27923 <row topline="true">
27924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27936 8051 monitor (hex up-/download, single step, disassemble)
27940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27944 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27953 <row topline="true">
27954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27959 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27971 Statically checks c sources (see
27972 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27984 \begin_inset LatexCommand \url{http://www.splint.org}
27993 <row topline="true" bottomline="true">
27994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27999 \begin_inset LatexCommand \index{DDD (debugger)}
28007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28011 Debugger, serves nicely as GUI to SDCDB
28012 \begin_inset LatexCommand \index{SDCDB (debugger)}
28020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28024 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
28042 Related documentation / recommended reading
28046 \begin_inset Tabular
28047 <lyxtabular version="3" rows="7" columns="3">
28049 <column alignment="left" valignment="top" leftline="true" width="0pt">
28050 <column alignment="left" valignment="top" leftline="true" width="0">
28051 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
28052 <row topline="true" bottomline="true">
28053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28084 <row topline="true">
28085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28107 \begin_inset LatexCommand \index{C Reference card}
28115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28119 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
28128 <row topline="true">
28129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28142 \begin_inset LatexCommand \index{C FAQ}
28150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28154 \begin_inset LatexCommand \url{http://www.c-faq.com}
28163 <row topline="true">
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28176 \begin_inset Quotes sld
28180 \begin_inset Quotes srd
28187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28193 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
28202 <row topline="true">
28203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28215 \begin_inset Quotes sld
28218 Extensions for Embedded C
28219 \begin_inset Quotes srd
28226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28232 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
28241 <row topline="true">
28242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28254 Latest datasheet of target CPU
28258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28267 <row topline="true" bottomline="true">
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28280 Revision history of datasheet
28284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28302 Application notes specifically for SDCC
28305 SDCC makes no claims about the completeness of this list and about up-to-datenes
28306 s or correctness of the application notes
28307 \begin_inset LatexCommand \index{Application notes}
28317 \begin_inset Tabular
28318 <lyxtabular version="3" rows="7" columns="3">
28320 <column alignment="block" valignment="top" leftline="true" width="17col%">
28321 <column alignment="block" valignment="top" leftline="true" width="27col%">
28322 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
28323 <row topline="true" bottomline="true">
28324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28335 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
28346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28358 <row topline="true">
28359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28375 Using the SDCC Compiler for the DS80C400
28376 \begin_inset LatexCommand \index{DS80C400}
28384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28390 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
28399 <row topline="true">
28400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28410 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
28416 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
28417 \begin_inset LatexCommand \index{DS89C4x0}
28421 Family of Microcontrollers
28425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28431 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
28440 <row topline="true">
28441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28447 Silicon Laboratories / Cygnal
28451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28457 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
28458 \begin_inset LatexCommand \index{IDE}
28466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28472 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
28481 <row topline="true">
28482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28488 Ramtron / Goal Semiconductor
28492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28498 Interfacing SDCC to Syn and Textpad
28502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28508 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28517 <row topline="true">
28518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28524 Ramtron / Goal Semiconductor
28528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28534 Installing and Configuring SDCC and Crimson Editor
28538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28544 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
28553 <row topline="true" bottomline="true">
28554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28570 MSC12xx Programming with SDCC
28574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28580 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
28599 Some questions answered, some pointers given - it might be time to in turn
28607 can you solve your project with the selected microcontroller? Would you
28608 find out early or rather late that your target is too small/slow/whatever?
28609 Can you switch to a slightly better device if it doesn't fit?
28612 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
28613 and/or another programming language be more adequate? Would an operating
28614 system on the target device help?
28617 if you solved the problem, will the marketing department be happy?
28620 if the marketing department is happy, will customers be happy?
28623 if you're the project manager, marketing department and maybe even the customer
28624 in one person, have you tried to see the project from the outside?
28627 is the project done if you think it is done? Or is just that other interface/pro
28628 tocol/feature/configuration/option missing? How about website, manual(s),
28629 internationali(z|s)ation, packaging, labels, 2nd source for components,
28630 electromagnetic compatability/interference, documentation for production,
28631 production test software, update mechanism, patent issues?
28634 is your project adequately positioned in that magic triangle: fame, fortune,
28638 Maybe not all answers to these questions are known and some answers may
28643 , nevertheless knowing these questions may help you to avoid burnout
28648 burnout is bad for electronic devices, programmers and motorcycle tyres
28653 Chances are you didn't want to hear some of them...
28657 \begin_inset LatexCommand \index{Support}
28664 SDCC has grown to be a large project.
28665 The compiler alone (without the preprocessor, assembler and linker) is
28666 well over 150,000 lines of code (blank stripped).
28667 The open source nature of this project is a key to its continued growth
28669 You gain the benefit and support of many active software developers and
28671 Is SDCC perfect? No, that's why we need your help.
28672 The developers take pride in fixing reported bugs.
28673 You can help by reporting the bugs and helping other SDCC users.
28674 There are lots of ways to contribute, and we encourage you to take part
28675 in making SDCC a great software package.
28679 The SDCC project is hosted on the SDCC sourceforge site at
28680 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
28685 You'll find the complete set of mailing lists
28686 \begin_inset LatexCommand \index{Mailing list(s)}
28690 , forums, bug reporting system, patch submission
28691 \begin_inset LatexCommand \index{Patch submission}
28696 \begin_inset LatexCommand \index{download}
28700 area and Subversion code repository
28701 \begin_inset LatexCommand \index{Subversion code repository}
28709 \begin_inset LatexCommand \index{Bug reporting}
28714 \begin_inset LatexCommand \index{Reporting bugs}
28721 The recommended way of reporting bugs is using the infrastructure of the
28723 You can follow the status of bug reports there and have an overview about
28727 Bug reports are automatically forwarded to the developer mailing list and
28728 will be fixed ASAP.
28729 When reporting a bug, it is very useful to include a small test program
28730 (the smaller the better) which reproduces the problem.
28731 If you can isolate the problem by looking at the generated assembly code,
28732 this can be very helpful.
28733 Compiling your program with the -
28746 \begin_inset LatexCommand \index{-\/-dumpall}
28750 option can sometimes be useful in locating optimization problems.
28751 When reporting a bug please make sure you:
28754 Attach the code you are compiling with SDCC.
28758 Specify the exact command you use to run SDCC, or attach your Makefile.
28762 Specify the SDCC version (type "
28768 "), your platform, and operating system.
28772 Provide an exact copy of any error message or incorrect output.
28776 Put something meaningful in the subject of your message.
28779 Please attempt to include these 5 important parts, as applicable, in all
28780 requests for support or when reporting any problems or bugs with SDCC.
28781 Though this will make your message lengthy, it will greatly improve your
28782 chance that SDCC users and developers will be able to help you.
28783 Some SDCC developers are frustrated by bug reports without code provided
28784 that they can use to reproduce and ultimately fix the problem, so please
28785 be sure to provide sample code if you are reporting a bug!
28788 Please have a short check that you are using a recent version of SDCC and
28789 the bug is not yet known.
28790 This is the link for reporting bugs:
28791 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
28796 With SDCC on average having more than 200 downloads
28797 \begin_inset LatexCommand \index{download}
28801 on sourceforge per day
28806 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
28807 between 2002 and 2005.
28808 This does not include other methods of distribution.
28812 there must be some users.
28813 So it's not exactly easy to find a new bug.
28814 If you find one we need it:
28816 reporting bugs is good
28821 Requesting Features
28822 \begin_inset LatexCommand \label{sub:Requesting-Features}
28827 \begin_inset LatexCommand \index{Feature request}
28832 \begin_inset LatexCommand \index{Requesting features}
28839 Like bug reports feature requests are forwarded to the developer mailing
28841 This is the link for requesting features:
28842 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28852 Like bug reports contributed patches are forwarded to the developer mailing
28854 This is the link for submitting patches
28855 \begin_inset LatexCommand \index{Patch submission}
28860 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28867 You need to specify some parameters to the
28871 command for the patches to be useful.
28872 If you modified more than one file a patch created f.e.
28877 \begin_inset Quotes sld
28880 diff -Naur unmodified_directory modified_directory >my_changes.patch
28881 \begin_inset Quotes srd
28887 will be fine, otherwise
28891 \begin_inset Quotes sld
28894 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28895 \begin_inset Quotes srd
28908 These links should take you directly to the
28909 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28918 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28919 automated messages (mid 2003)
28924 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28929 \begin_inset LatexCommand \index{Mailing list(s)}
28933 and forums are archived and searchable so if you are lucky someone already
28934 had a similar problem.
28935 While mails to the lists themselves are delivered promptly their web front
28936 end on sourceforge sometimes shows a severe time lag (up to several weeks),
28937 if you're seriously using SDCC please consider subscribing to the lists.
28943 You can follow the status of the Subversion version
28944 \begin_inset LatexCommand \index{version}
28948 of SDCC by watching the Changelog
28949 \begin_inset LatexCommand \index{Changelog}
28953 in the Subversion repository
28956 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28963 Subversion Source Code Repository
28972 or the filenames of the snapshot versions of SDCC include date and its
28974 \begin_inset LatexCommand \index{Subversion code repository}
28979 Subversion allows to download the source of recent or previous versions
28981 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28985 (by number or by date).
28986 An on-line source code browser and detailled instructions are also available
28988 SDCC versions starting from 1999 up to now are available (currently the
28989 versions prior to the conversion from cvs
28990 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28994 to Subversion (April 2006) are either by accessible by Subversion or by
28999 \begin_inset LatexCommand \index{Release policy}
29006 Historically there often were long delays between official releases and
29007 the sourceforge download area tends to get not updated at all.
29008 Excuses in the past might have referred to problems with live range analysis,
29009 but as this was fixed a while ago, the current problem is that another
29010 excuse has to be found.
29011 Kidding aside, we have to get better there! On the other hand there are
29012 daily snapshots available at
29013 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
29017 , and you can always build the very last version (hopefully with many bugs
29018 fixed, and features added) from the source code available at
29019 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
29025 \begin_inset LatexCommand \index{wiki}
29030 \begin_inset LatexCommand \index{Release wiki}
29035 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
29039 also holds some information about past and future releases.
29043 \begin_inset LatexCommand \index{Examples}
29050 You'll find some small examples in the directory
29052 sdcc/device/examples/.
29055 More examples and libraries are available at
29057 The SDCC Open Knowledge Resource
29058 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
29065 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
29076 I did insert a reference to Paul's web site here although it seems rather
29077 dedicated to a specific 8032 board (I think it's okay because it f.e.
29078 shows LCD/Harddisc interface and has a free 8051 monitor.
29079 Independent 8032 board vendors face hard competition of heavily subsidized
29080 development boards anyway).
29083 Maybe we should include some links to real world applications.
29084 Preferably pointer to pointers (one for each architecture) so this stays
29093 \begin_inset LatexCommand \label{sec:Quality-control}
29098 \begin_inset LatexCommand \index{Quality control}
29105 The compiler is passed through nightly compile and build checks.
29111 \begin_inset LatexCommand \index{Regression test}
29115 check that SDCC itself compiles flawlessly on several host platforms (i386,
29116 Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
29117 the quality of the code generated by SDCC by running the code for several
29118 target platforms through simulators.
29119 The regression test suite comprises more than 100 files which expand to
29120 more than 500 test cases which include more than 4500 tests.
29121 The results of these tests are published daily on SDCC's snapshot page
29122 (click on the red or green symbols on the right side of
29123 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
29130 There is a separate document
29133 \begin_inset LatexCommand \index{Test suite}
29140 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
29144 about the regression test suite.
29147 You'll find the test code in the directory
29149 sdcc/support/regression
29152 You can run these tests manually by running
29156 in this directory (or f.e.
29161 \begin_inset Quotes sld
29165 \begin_inset Quotes srd
29171 if you don't want to run the complete tests).
29172 The test code might also be interesting if you want to look for examples
29173 \begin_inset LatexCommand \index{Examples}
29177 checking corner cases of SDCC or if you plan to submit patches
29178 \begin_inset LatexCommand \index{Patch submission}
29185 The 14bit pic port uses a different set of regression tests
29186 \begin_inset LatexCommand \index{Regression test (PIC14)}
29190 , you'll find them in the directory
29192 sdcc/src/regression
29197 Use of SDCC in Education
29209 the phrase "use in education" might evoke the association "
29213 fit for use in education".
29214 This connotation is not intended but nevertheless risked as the licensing
29215 of SDCC makes it difficult to offer educational discounts
29220 If your rationales are to:
29223 give students a chance to understand the
29227 steps of code generation
29230 have a curriculum that can be extended for years.
29231 Then you could use an fpga board as target and your curriculum will seamlessly
29232 extend from logic synthesis (
29233 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
29238 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
29242 ), over assembly programming, to C to FPGA compilers (
29243 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
29250 be able to insert excursions about skills like using a revision control
29251 system, submitting/applying patches, using a type-setting (as opposed to
29252 word-processing) engine LyX/LaTeX, using
29253 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
29258 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
29262 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
29263 Source Software, CPU simulation, compiler regression tests
29264 \begin_inset LatexCommand \index{Regression test}
29271 And if there should be a shortage of ideas then you can always point students
29272 to the ever-growing feature request list
29273 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
29280 not tie students to a specific host platform and instead allow them to use
29285 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
29287 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
29294 not encourage students to use illegal copies of educational software
29297 be immune to licensing/availability/price changes of the chosen tool chain
29300 be able to change to a new target platform without having to adopt a new
29304 have complete control over and insight into the tool chain
29307 make your students aware about the pros and cons of open source software
29311 give back to the public as you are probably at least partially publically
29315 give students a chance to publically prove their skills and to possibly
29316 see a world wide impact
29320 then SDCC is probably among the first choices.
29321 Well, probably SDCC might be the only choice.
29325 SDCC Technical Data
29329 \begin_inset LatexCommand \index{Optimizations}
29336 SDCC performs a host of standard optimizations in addition to some MCU specific
29341 Sub-expression Elimination
29342 \begin_inset LatexCommand \index{Subexpression elimination}
29349 The compiler does local and
29375 will be translated to
29387 Some subexpressions are not as obvious as the above example, e.g.:
29397 In this case the address arithmetic a->b[i] will be computed only once;
29398 the equivalent code in C would be.
29410 The compiler will try to keep these temporary variables in registers.
29413 Dead-Code Elimination
29414 \begin_inset LatexCommand \index{Dead-code elimination}
29435 i = 1; \SpecialChar ~
29444 global = 1;\SpecialChar ~
29458 global = 3;\SpecialChar ~
29483 \begin_inset LatexCommand \index{Copy propagation}
29539 Note: the dead stores created by this copy propagation will be eliminated
29540 by dead-code elimination.
29544 \begin_inset LatexCommand \index{Loop optimization}
29549 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
29556 Two types of loop optimizations are done by SDCC
29564 of loop induction variables.
29565 In addition to the strength reduction the optimizer marks the induction
29566 variables and the register allocator tries to keep the induction variables
29567 in registers for the duration of the loop.
29568 Because of this preference of the register allocator
29569 \begin_inset LatexCommand \index{Register allocation}
29573 , loop induction optimization causes an increase in register pressure, which
29574 may cause unwanted spilling of other temporary variables into the stack
29575 \begin_inset LatexCommand \index{stack}
29580 The compiler will generate a warning message when it is forced to allocate
29581 extra space either on the stack or data space.
29582 If this extra space allocation is undesirable then induction optimization
29583 can be eliminated either for the entire source file (with -
29595 -noinduction option) or for a given function only using #pragma\SpecialChar ~
29597 \begin_inset LatexCommand \index{\#pragma noinduction}
29610 for (i = 0 ; i < 100 ; i ++)
29626 for (i = 0; i < 100; i++)
29635 As mentioned previously some loop invariants are not as apparent, all static
29636 address computations are also moved out of the loop.
29641 \begin_inset LatexCommand \index{Strength reduction}
29645 , this optimization substitutes an expression by a cheaper expression:
29650 for (i=0;i < 100; i++)
29668 for (i=0;i< 100;i++) {
29674 ar[itemp1] = itemp2;
29692 The more expensive multiplication
29693 \begin_inset LatexCommand \index{Multiplication}
29697 is changed to a less expensive addition.
29701 \begin_inset LatexCommand \index{Loop reversing}
29708 This optimization is done to reduce the overhead of checking loop boundaries
29709 for every iteration.
29710 Some simple loops can be reversed and implemented using a
29711 \begin_inset Quotes eld
29714 decrement and jump if not zero
29715 \begin_inset Quotes erd
29719 SDCC checks for the following criterion to determine if a loop is reversible
29720 (note: more sophisticated compilers use data-dependency analysis to make
29721 this determination, SDCC uses a more simple minded analysis).
29724 The 'for' loop is of the form
29730 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
29740 The <for body> does not contain
29741 \begin_inset Quotes eld
29745 \begin_inset Quotes erd
29749 \begin_inset Quotes erd
29755 All goto's are contained within the loop.
29758 No function calls within the loop.
29761 The loop control variable <sym> is not assigned any value within the loop
29764 The loop control variable does NOT participate in any arithmetic operation
29768 There are NO switch statements in the loop.
29771 Algebraic Simplifications
29774 SDCC does numerous algebraic simplifications, the following is a small sub-set
29775 of these optimizations.
29780 i = j + 0;\SpecialChar ~
29784 /* changed to: */\SpecialChar ~
29790 i /= 2;\SpecialChar ~
29797 /* changed to: */\SpecialChar ~
29804 = j - j;\SpecialChar ~
29808 /* changed to: */\SpecialChar ~
29814 i = j / 1;\SpecialChar ~
29818 /* changed to: */\SpecialChar ~
29825 Note the subexpressions
29826 \begin_inset LatexCommand \index{Subexpression}
29830 given above are generally introduced by macro expansions or as a result
29831 of copy/constant propagation.
29834 'switch' Statements
29835 \begin_inset LatexCommand \label{sub:'switch'-Statements}
29840 \begin_inset LatexCommand \index{switch statement}
29847 SDCC can optimize switch statements to jump tables
29848 \begin_inset LatexCommand \index{jump tables}
29853 It makes the decision based on an estimate of the generated code size.
29854 SDCC is quite liberal in the requirements for jump table generation:
29857 The labels need not be in order, and the starting number need not be one
29858 or zero, the case labels are in numerical sequence or not too many case
29859 labels are missing.
29865 switch(i) {\SpecialChar ~
29896 case 4: ...\SpecialChar ~
29928 case 5: ...\SpecialChar ~
29960 case 3: ...\SpecialChar ~
29991 case 6: ...\SpecialChar ~
30023 case 7: ...\SpecialChar ~
30055 case 8: ...\SpecialChar ~
30087 case 9: ...\SpecialChar ~
30119 case 10: ...\SpecialChar ~
30150 case 11: ...\SpecialChar ~
30217 Both the above switch statements will be implemented using a jump-table.
30218 The example to the right side is slightly more efficient as the check for
30219 the lower boundary of the jump-table is not needed.
30223 The number of case labels is not larger than supported by the target architectur
30227 If the case labels are not in numerical sequence ('gaps' between cases)
30228 SDCC checks whether a jump table with additionally inserted dummy cases
30229 is still attractive.
30233 If the starting number is not zero and a check for the lower boundary of
30234 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
30239 Switch statements which have large gaps in the numeric sequence or those
30240 that have too many case labels can be split into more than one switch statement
30241 for efficient code generation, e.g.:
30321 If the above switch statement is broken down into two switch statements
30411 then both the switch statements will be implemented using jump-tables whereas
30412 the unmodified switch statement will not be.
30419 There might be reasons which SDCC cannot know about to either favour or
30420 not favour jump tables.
30421 If the target system has to be as quick for the last switch case as for
30422 the first (pro jump table), or if the switch argument is known to be zero
30423 in the majority of the cases (contra jump table).
30430 The pragma nojtbound
30431 \begin_inset LatexCommand \index{\#pragma nojtbound}
30435 can be used to turn off checking the
30448 It has no effect if a default label is supplied.
30449 Use of this pragma is dangerous: if the switch
30450 \begin_inset LatexCommand \index{switch statement}
30454 argument is not matched by a case statement the processor will happily
30458 Bit-shifting Operations
30459 \begin_inset LatexCommand \index{Bit shifting}
30466 Bit shifting is one of the most frequently used operation in embedded programmin
30468 SDCC tries to implement bit-shift operations in the most efficient way
30484 generates the following code:
30501 In general SDCC will never setup a loop if the shift count is known.
30544 \begin_inset LatexCommand \index{Bit rotation}
30551 A special case of the bit-shift operation is bit rotation
30552 \begin_inset LatexCommand \index{rotating bits}
30556 , SDCC recognizes the following expression to be a left bit-rotation:
30566 char i;\SpecialChar ~
30577 /* unsigned is needed for rotation */
30582 i = ((i << 1) | (i >> 7));
30591 will generate the following code:
30610 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
30611 ns of this case will also be recognized as bit-rotation, i.e.:
30616 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
30619 Nibble and Byte Swapping
30622 Other special cases of the bit-shift operations are nibble or byte swapping
30623 \begin_inset LatexCommand \index{swapping nibbles/bytes}
30627 , SDCC recognizes the following expressions:
30650 i = ((i << 4) | (i >> 4));
30656 j = ((j << 8) | (j >> 8));
30659 and generates a swap instruction for the nibble swapping
30660 \begin_inset LatexCommand \index{Nibble swapping}
30664 or move instructions for the byte swapping
30665 \begin_inset LatexCommand \index{Byte swapping}
30671 \begin_inset Quotes sld
30675 \begin_inset Quotes srd
30678 example can be used to convert from little to big-endian or vice versa.
30679 If you want to change the endianness of a
30683 integer you have to cast to
30690 Note that SDCC stores numbers in little-endian
30695 Usually 8-bit processors don't care much about endianness.
30696 This is not the case for the standard 8051 which only has an instruction
30702 \begin_inset LatexCommand \index{DPTR}
30710 so little-endian is the more efficient byte order.
30715 \begin_inset LatexCommand \index{little-endian}
30720 \begin_inset LatexCommand \index{Endianness}
30725 lowest order first).
30729 \begin_inset LatexCommand \index{Highest Order Bit}
30734 \begin_inset LatexCommand \index{Any Order Bit}
30741 It is frequently required to obtain the highest order bit of an integral
30742 type (long, int, short or char types).
30743 Also obtaining any other order bit is not uncommon.
30744 SDCC recognizes the following expressions to yield the highest order bit
30745 and generates optimized code for it, e.g.:
30758 unsigned char hob1, aob1;
30762 bit hob2, hob3, aob2,
30772 hob1 = (gint >> 15) & 1;
30776 hob2 = (gint >> 15) & 1;
30780 hob3 = gint & 0x8000;
30785 aob1 = (gint >> 9) & 1;
30789 aob2 = (gint >> 8) & 1;
30793 aob3 = gint & 0x0800;
30803 will generate the following code:
30836 000A E5*01\SpecialChar ~
30863 000C 23\SpecialChar ~
30894 000D 54 01\SpecialChar ~
30922 000F F5*02\SpecialChar ~
30977 0011 E5*01\SpecialChar ~
31005 0013 33\SpecialChar ~
31035 0014 92*00\SpecialChar ~
31091 0016 E5*01\SpecialChar ~
31118 0018 33\SpecialChar ~
31148 0019 92*01\SpecialChar ~
31204 001B E5*01\SpecialChar ~
31263 001E 54 01\SpecialChar ~
31290 0020 F5*03\SpecialChar ~
31346 0022 E5*01\SpecialChar ~
31373 0024 13\SpecialChar ~
31403 0025 92*02\SpecialChar ~
31459 0027 E5*01\SpecialChar ~
31487 A2 E3\SpecialChar ~
31514 002B 92*03\SpecialChar ~
31542 Other variations of these cases however will
31547 They are standard C expressions, so I heartily recommend these be the only
31548 way to get the highest order bit, (it is portable).
31549 Of course it will be recognized even if it is embedded in other expressions,
31555 xyz = gint + ((gint >> 15) & 1);
31558 will still be recognized.
31562 \begin_inset LatexCommand \index{Higher Order Byte}
31566 / Higher Order Word
31567 \begin_inset LatexCommand \index{Higher Order Word}
31574 It is also frequently required to obtain a higher order byte or word of
31575 a larger integral type (long, int or short types).
31576 SDCC recognizes the following expressions to yield the higher order byte
31577 or word and generates optimized code for it, e.g.:
31584 unsigned long int glong;
31592 unsigned char hob1,
31597 unsigned int how1, how2;
31606 hob1 = (gint >> 8) & 0xFF;
31610 hob2 = glong >> 24;
31614 how1 = (glong >> 16) & 0xFFFF;
31629 will generate the following code:
31662 0037 85*01*06\SpecialChar ~
31684 _foo_hob1_1_1,(_gint + 1)
31715 003A 85*05*07\SpecialChar ~
31737 _foo_hob2_1_1,(_glong + 3)
31767 003D 85*04*08\SpecialChar ~
31790 _foo_how1_1_1,(_glong + 2)
31792 0040 85*05*09\SpecialChar ~
31817 0043 85*03*0A\SpecialChar ~
31839 _foo_how2_1_1,(_glong + 1)
31841 0046 85*04*0B\SpecialChar ~
31864 (_foo_how2_1_1 + 1),(_glong + 2)
31867 Again, variations of these cases may
31872 They are standard C expressions, so I heartily recommend these be the only
31873 way to get the higher order byte/word, (it is portable).
31874 Of course it will be recognized even if it is embedded in other expressions,
31880 xyz = gint + ((gint >> 8) & 0xFF);
31883 will still be recognized.
31887 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31892 \begin_inset LatexCommand \index{Peephole optimizer}
31899 The compiler uses a rule based, pattern matching and re-writing mechanism
31900 for peep-hole optimization.
31905 a peep-hole optimizer by Christopher W.
31906 Fraser (cwfraser\SpecialChar ~
31909 A default set of rules are compiled into the compiler, additional rules
31910 may be added with the
31925 \begin_inset LatexCommand \index{-\/-peep-file}
31932 The rule language is best illustrated with examples.
31956 The above rule will change the following assembly
31957 \begin_inset LatexCommand \index{Assembler routines}
31979 Note: All occurrences of a
31983 (pattern variable) must denote the same string.
31984 With the above rule, the assembly sequence:
31994 will remain unmodified.
31998 Other special case optimizations may be added by the
32017 some variants of the 8051 MCU
32018 \begin_inset LatexCommand \index{MCS51 variants}
32031 The following two rules will change all
32050 replace { lcall %1 } by { acall %1 }
32052 replace { ljmp %1 } by { ajmp %1 }
32057 inline-assembler code
32059 is also passed through the peep hole optimizer, thus the peephole optimizer
32060 can also be used as an assembly level macro expander.
32061 The rules themselves are MCU dependent whereas the rule language infra-structur
32062 e is MCU independent.
32063 Peephole optimization rules for other MCU can be easily programmed using
32068 The syntax for a rule is as follows:
32073 rule := replace [ restart ] '{' <assembly sequence> '
32111 <assembly sequence> '
32129 '}' [if <functionName> ] '
32134 <assembly sequence> := assembly instruction (each instruction including
32135 labels must be on a separate line).
32139 The optimizer will apply to the rules
32140 one by one from the top in the sequence of their appearance, it will terminate
32141 when all rules are exhausted.
32142 If the 'restart' option is specified, then the optimizer will start matching
32143 the rules again from the top, this option for a rule is expensive (performance)
32144 , it is intended to be used in situations where a transformation will trigger
32145 the same rule again.
32146 An example of this (not a good one, it has side effects) is the following
32169 Note that the replace pattern cannot be a blank, but can be a comment line.
32170 Without the 'restart' option only the innermost 'pop' 'push' pair would
32171 be eliminated, i.e.:
32201 the restart option the rule will be applied again to the resulting code
32202 and then all the pop-push pairs will be eliminated to yield:
32212 A conditional function can be attached to a rule.
32213 Attaching rules are somewhat more involved, let me illustrate this with
32240 The optimizer does a look-up of a function name table defined in function
32245 in the source file SDCCpeeph.c, with the name
32250 If it finds a corresponding entry the function is called.
32251 Note there can be no parameters specified for these functions, in this
32256 is crucial, since the function
32260 expects to find the label in that particular variable (the hash table containin
32261 g the variable bindings is passed as a parameter).
32262 If you want to code more such functions, take a close look at the function
32263 labelInRange and the calling mechanism in source file SDCCpeeph.c.
32264 Currently implemented are
32266 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
32267 24bitMode, portIsDS390, 24bitModeAndPortDS390
32276 I know this whole thing is a little kludgey, but maybe some day we will
32277 have some better means.
32278 If you are looking at this file, you will see the default rules that are
32279 compiled into the compiler, you can add your own rules in the default set
32280 there if you get tired of specifying the -
32296 \begin_inset LatexCommand \index{ANSI-compliance}
32301 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
32308 The latest publically available version of the standard
32310 ISO/IEC 9899 - Programming languages - C
32312 should be available at:
32313 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32322 Deviations from the compliance:
32325 functions are not reentrant
32326 \begin_inset LatexCommand \index{reentrant}
32330 unless explicitly declared as such or the
32345 \begin_inset LatexCommand \index{-\/-stack-auto}
32351 command line option is specified.
32355 \begin_inset LatexCommand \index{struct}
32360 \begin_inset LatexCommand \index{union}
32364 cannot be assigned values directly, cannot be passed as function parameters
32365 or assigned to each other and cannot be a return value
32366 \begin_inset LatexCommand \index{return value}
32370 from a function, e.g.:
32396 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
32415 s parms) /* invalid in SDCC although allowed in ANSI */
32437 return rets; /* is invalid in SDCC although allowed in ANSI */
32443 initialization of structure arrays must be fully braced.
32449 struct s { char x } a[] = {1, 2};\SpecialChar ~
32454 /* invalid in SDCC */
32457 } a[] = {{1}, {2}}; /* OK */
32462 \begin_inset LatexCommand \index{long long (not supported)}
32467 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
32475 \begin_inset LatexCommand \index{double (not supported)}
32479 ' precision floating point
32480 \begin_inset LatexCommand \index{Floating point support}
32488 \begin_inset LatexCommand \index{K\&R style}
32492 function declarations are NOT allowed.
32498 foo(i,j) /* this old style of function declarations */
32500 int i,j; /* are valid
32501 in ANSI but not valid in SDCC */
32516 Most enhancements in C99 are not supported, f.e.:
32524 \begin_inset LatexCommand \index{inline (not supported)}
32530 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
32536 can be used as a work around */
32544 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
32548 Certain words that are valid identifiers in the standard may be reserved
32549 words in SDCC unless the
32564 \begin_inset LatexCommand \index{-\/-std-c89}
32581 \begin_inset LatexCommand \index{-\/-std-c99}
32587 command line options are used.
32588 These may include (depending on the selected processor): 'at', 'banked',
32589 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
32590 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
32591 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
32593 Compliant equivalents of these keywords are always available in a form
32594 that begin with two underscores
32595 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
32600 '__data' instead of 'data'.
32603 Cyclomatic Complexity
32604 \begin_inset LatexCommand \index{Cyclomatic complexity}
32611 Cyclomatic complexity of a function is defined as the number of independent
32612 paths the program can take during execution of the function.
32613 This is an important number since it defines the number test cases you
32614 have to generate to validate the function.
32615 The accepted industry standard for complexity number is 10, if the cyclomatic
32616 complexity reported by SDCC exceeds 10 you should think about simplification
32617 of the function logic.
32618 Note that the complexity level is not related to the number of lines of
32619 code in a function.
32620 Large functions can have low complexity, and small functions can have large
32626 SDCC uses the following formula to compute the complexity:
32631 complexity = (number of edges in control flow graph) - (number of nodes
32632 in control flow graph) + 2;
32636 Having said that the industry standard is 10,
32637 you should be aware that in some cases it be may unavoidable to have a
32638 complexity level of less than 10.
32639 For example if you have switch statement with more than 10 case labels,
32640 each case label adds one to the complexity level.
32641 The complexity level is by no means an absolute measure of the algorithmic
32642 complexity of the function, it does however provide a good starting point
32643 for which functions you might look at for further optimization.
32646 Retargetting for other Processors
32649 The issues for retargetting the compiler are far too numerous to be covered
32651 What follows is a brief description of each of the seven phases of the
32652 compiler and its MCU dependency.
32655 Parsing the source and building the annotated parse tree.
32656 This phase is largely MCU independent (except for the language extensions).
32657 Syntax & semantic checks are also done in this phase, along with some initial
32658 optimizations like back patching labels and the pattern matching optimizations
32659 like bit-rotation etc.
32662 The second phase involves generating an intermediate code which can be easy
32663 manipulated during the later phases.
32664 This phase is entirely MCU independent.
32665 The intermediate code generation assumes the target machine has unlimited
32666 number of registers, and designates them with the name iTemp.
32667 The compiler can be made to dump a human readable form of the code generated
32683 This phase does the bulk of the standard optimizations and is also MCU independe
32685 This phase can be broken down into several sub-phases:
32689 Break down intermediate
32690 code (iCode) into basic blocks.
32692 Do control flow & data flow analysis on the
32695 Do local common subexpression elimination, then global subexpressio
32698 Dead code elimination
32702 If loop optimizations
32703 caused any changes then do 'global subexpression elimination' and 'dead
32704 code elimination' again.
32707 This phase determines the live-ranges; by live range I mean those iTemp
32708 variables defined by the compiler that still survive after all the optimization
32710 Live range analysis
32711 \begin_inset LatexCommand \index{Live range analysis}
32715 is essential for register allocation, since these computation determines
32716 which of these iTemps will be assigned to registers, and for how long.
32719 Phase five is register allocation.
32720 There are two parts to this process.
32724 The first part I call 'register packing'
32725 (for lack of a better term).
32726 In this case several MCU specific expression folding is done to reduce
32731 The second part is more MCU independent and deals with
32732 allocating registers to the remaining live ranges.
32733 A lot of MCU specific code does creep into this phase because of the limited
32734 number of index registers available in the 8051.
32737 The Code generation phase is (unhappily), entirely MCU dependent and very
32738 little (if any at all) of this code can be reused for other MCU.
32739 However the scheme for allocating a homogenized assembler operand for each
32740 iCode operand may be reused.
32743 As mentioned in the optimization section the peep-hole optimizer is rule
32744 based system, which can reprogrammed for other MCUs.
32747 More information is available in a wiki
32748 \begin_inset LatexCommand \index{wiki}
32753 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
32757 ) and in the thread
32758 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
32766 \begin_inset LatexCommand \index{Compiler internals}
32773 The anatomy of the compiler
32774 \begin_inset LatexCommand \label{sub:The-anatomy-of}
32783 This is an excerpt from an article published in Circuit Cellar Magazine
32789 It's a little outdated (the compiler is much more efficient now and user/develo
32790 per friendly), but pretty well exposes the guts of it all.
32796 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
32797 It is fairly easy to retarget for other 8-bit MCU.
32798 Here we take a look at some of the internals of the compiler.
32803 \begin_inset LatexCommand \index{Parsing}
32810 Parsing the input source file and creating an AST (Annotated Syntax Tree
32811 \begin_inset LatexCommand \index{Annotated syntax tree}
32816 This phase also involves propagating types (annotating each node of the
32817 parse tree with type information) and semantic analysis.
32818 There are some MCU specific parsing rules.
32819 For example the storage classes, the extended storage classes are MCU specific
32820 while there may be a xdata storage class for 8051 there is no such storage
32821 class for z80 or Atmel AVR.
32822 SDCC allows MCU specific storage class extensions, i.e.
32823 xdata will be treated as a storage class specifier when parsing 8051 C
32824 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
32829 \begin_inset LatexCommand \index{iCode}
32836 Intermediate code generation.
32837 In this phase the AST is broken down into three-operand form (iCode).
32838 These three operand forms are represented as doubly linked lists.
32839 ICode is the term given to the intermediate form generated by the compiler.
32840 ICode example section shows some examples of iCode generated for some simple
32841 C source functions.
32845 \begin_inset LatexCommand \index{Optimizations}
32852 Bulk of the target independent optimizations is performed in this phase.
32853 The optimizations include constant propagation, common sub-expression eliminati
32854 on, loop invariant code movement, strength reduction of loop induction variables
32855 and dead-code elimination.
32858 Live range analysis
32859 \begin_inset LatexCommand \index{Live range analysis}
32866 During intermediate code generation phase, the compiler assumes the target
32867 machine has infinite number of registers and generates a lot of temporary
32869 The live range computation determines the lifetime of each of these compiler-ge
32870 nerated temporaries.
32871 A picture speaks a thousand words.
32872 ICode example sections show the live range annotations for each of the
32874 It is important to note here, each iCode is assigned a number in the order
32875 of its execution in the function.
32876 The live ranges are computed in terms of these numbers.
32877 The from number is the number of the iCode which first defines the operand
32878 and the to number signifies the iCode which uses this operand last.
32881 Register Allocation
32882 \begin_inset LatexCommand \index{Register allocation}
32889 The register allocation determines the type and number of registers needed
32891 In most MCUs only a few registers can be used for indirect addressing.
32892 In case of 8051 for example the registers R0 & R1 can be used to indirectly
32893 address the internal ram and DPTR to indirectly address the external ram.
32894 The compiler will try to allocate the appropriate register to pointer variables
32896 ICode example section shows the operands annotated with the registers assigned
32898 The compiler will try to keep operands in registers as much as possible;
32899 there are several schemes the compiler uses to do achieve this.
32900 When the compiler runs out of registers the compiler will check to see
32901 if there are any live operands which is not used or defined in the current
32902 basic block being processed, if there are any found then it will push that
32903 operand and use the registers in this block, the operand will then be popped
32904 at the end of the basic block.
32908 There are other MCU specific considerations in this phase.
32909 Some MCUs have an accumulator; very short-lived operands could be assigned
32910 to the accumulator instead of a general-purpose register.
32916 Figure II gives a table of iCode
32917 \begin_inset LatexCommand \index{iCode}
32921 operations supported by the compiler.
32922 The code generation involves translating these operations into corresponding
32923 assembly code for the processor.
32924 This sounds overly simple but that is the essence of code generation.
32925 Some of the iCode operations are generated on a MCU specific manner for
32926 example, the z80 port does not use registers to pass parameters so the
32927 SEND and RECV iCode operations will not be generated, and it also does
32928 not support JUMPTABLES.
32937 \begin_inset Tabular
32938 <lyxtabular version="3" rows="39" columns="4">
32939 <features islongtable="true" headBottomDL="true">
32940 <column alignment="block" valignment="top" leftline="true" width="13col%">
32941 <column alignment="left" valignment="top" leftline="true" width="13col%">
32942 <column alignment="block" valignment="top" leftline="true" width="22col%">
32943 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32944 <row topline="true" bottomline="true" endhead="true">
32945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32954 \begin_inset LatexCommand \index{iCode}
32962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32993 <row topline="true">
32994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33010 IC_LEFT() IC_RESULT()
33014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33030 IC_RESULT = ! IC_LEFT;
33035 <row topline="true">
33036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33052 IC_LEFT() IC_RESULT()
33056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33062 Bitwise complement of
33066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33072 IC_RESULT = ~IC_LEFT;
33077 <row topline="true">
33078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33094 IC_LEFT() IC_RESULT()
33098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33104 Rotate right with carry
33108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33114 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
33119 <row topline="true">
33120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33136 IC_LEFT() IC_RESULT()
33140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33146 Rotate left with carry
33150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33156 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
33161 <row topline="true">
33162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33178 IC_LEFT() IC_RESULT()
33182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33188 Get the highest order bit of IC_LEFT
33192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33198 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
33203 <row topline="true">
33204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33220 IC_LEFT() IC_RESULT()
33224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33240 IC_RESULT = - IC_LEFT;
33245 <row topline="true">
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33272 Push the operand into stack
33276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33287 <row topline="true">
33288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33314 Pop the operand from the stack
33318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33329 <row topline="true">
33330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33346 IC_LEFT() IC_RESULT()
33350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33356 Call the function represented by IC_LEFT
33360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33366 IC_RESULT = IC_LEFT();
33371 <row topline="true">
33372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33388 IC_LEFT() IC_RESULT()
33392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33398 Call via function pointer
33402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33408 IC_RESULT = (*IC_LEFT)();
33413 <row topline="true">
33414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33440 Return the value in operand IC_LEFT
33444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33455 <row topline="true">
33456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33497 <row topline="true">
33498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33539 <row topline="true">
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33556 IC_LEFT() IC_RIGHT() IC_RESULT()
33560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33576 IC_RESULT = IC_LEFT + IC_RIGHT
33581 <row topline="true">
33582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33598 IC_LEFT() IC_RIGHT() IC_RESULT()
33602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33618 IC_RESULT = IC_LEFT - IC_RIGHT
33623 <row topline="true">
33624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33640 IC_LEFT() IC_RIGHT() IC_RESULT()
33644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33660 IC_RESULT = IC_LEFT * IC_RIGHT;
33665 <row topline="true">
33666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33682 IC_LEFT() IC_RIGHT() IC_RESULT()
33686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33702 IC_RESULT = IC_LEFT / IC_RIGHT;
33707 <row topline="true">
33708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33724 IC_LEFT() IC_RIGHT() IC_RESULT()
33728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33744 IC_RESULT = IC_LEFT % IC_RIGHT;
33749 <row topline="true">
33750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33766 IC_LEFT() IC_RIGHT() IC_RESULT()
33770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33786 IC_RESULT = IC_LEFT < IC_RIGHT;
33791 <row topline="true">
33792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33808 IC_LEFT() IC_RIGHT() IC_RESULT()
33812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33828 IC_RESULT = IC_LEFT > IC_RIGHT;
33833 <row topline="true">
33834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33850 IC_LEFT() IC_RIGHT() IC_RESULT()
33854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33870 IC_RESULT = IC_LEFT == IC_RIGHT;
33875 <row topline="true">
33876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33892 IC_LEFT() IC_RIGHT() IC_RESULT()
33896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33902 Logical and operation
33906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33912 IC_RESULT = IC_LEFT && IC_RIGHT;
33917 <row topline="true">
33918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33934 IC_LEFT() IC_RIGHT() IC_RESULT()
33938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33944 Logical or operation
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33954 IC_RESULT = IC_LEFT || IC_RIGHT;
33959 <row topline="true">
33960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33976 IC_LEFT() IC_RIGHT() IC_RESULT()
33980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33996 IC_RESULT = IC_LEFT ^ IC_RIGHT;
34001 <row topline="true">
34002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34018 IC_LEFT() IC_RIGHT() IC_RESULT()
34022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34038 IC_RESULT = IC_LEFT | IC_RIGHT;
34043 <row topline="true">
34044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34060 IC_LEFT() IC_RIGHT() IC_RESULT()
34064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34080 IC_RESULT = IC_LEFT & IC_RIGHT;
34085 <row topline="true">
34086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34102 IC_LEFT() IC_RIGHT() IC_RESULT()
34106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34122 IC_RESULT = IC_LEFT << IC_RIGHT
34127 <row topline="true">
34128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34144 IC_LEFT() IC_RIGHT() IC_RESULT()
34148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34164 IC_RESULT = IC_LEFT >> IC_RIGHT
34169 <row topline="true">
34170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34188 IC_LEFT() IC_RESULT()
34192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34208 IC_RESULT = (*IC_LEFT);
34213 <row topline="true">
34214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34230 IC_RIGHT() IC_RESULT()
34234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34250 (*IC_RESULT) = IC_RIGHT;
34255 <row topline="true">
34256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34272 IC_RIGHT() IC_RESULT()
34276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34292 IC_RESULT = IC_RIGHT;
34297 <row topline="true">
34298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34314 IC_COND IC_TRUE IC_LABEL
34318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34325 If true label is present then jump to true label if condition is true else
34326 jump to false label if condition is false
34330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34336 if (IC_COND) goto IC_TRUE;
34342 If (!IC_COND) goto IC_FALSE;
34347 <row topline="true">
34348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34364 IC_LEFT() IC_RESULT()
34368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34384 IC_RESULT = &IC_LEFT();
34389 <row topline="true">
34390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34406 IC_JTCOND IC_JTLABELS
34410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34416 Jump to list of labels depending on the value of JTCOND
34420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34431 <row topline="true">
34432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34448 IC_RIGHT() IC_LEFT() IC_RESULT()
34452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34468 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
34473 <row topline="true">
34474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34500 This is used for passing parameters in registers;
34502 move IC_LEFT to the next
34503 available parameter register.
34507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34518 <row topline="true">
34519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34545 This is used for receiving parameters passed in registers;
34548 in the next parameter register to IC_RESULT
34552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34563 <row topline="true" bottomline="true">
34564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34571 (some more have been added)
34575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34621 In the original article Figure II was announced to be downloadable on
34626 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
34634 \begin_inset LatexCommand \index{iCode}
34641 This section shows some details of iCode.
34642 The example C code does not do anything useful; it is used as an example
34643 to illustrate the intermediate code generated by the compiler.
34655 /* This function does nothing useful.
34662 for the purpose of explaining iCode */
34665 short function (data
34674 short i=10; \SpecialChar ~
34676 /* dead initialization eliminated */
34682 /* dead initialization eliminated */
34710 /* compiler detects i,j to be induction
34715 for (i = 0, j = 10 ; i < 10 ; i++, j
34743 mul += i * 3; \SpecialChar ~
34745 /* this multiplication remains */
34752 j * 3;\SpecialChar ~
34754 /* this multiplication changed to addition */
34768 In addition to the operands each iCode contains information about the filename
34769 and line it corresponds to in the source file.
34770 The first field in the listing should be interpreted as follows:
34775 Filename(linenumber: iCode Execution sequence number : ICode hash table
34776 key : loop depth of the iCode).
34781 Then follows the human readable form of the ICode operation.
34782 Each operand of this triplet form can be of three basic types a) compiler
34783 generated temporary b) user defined variable c) a constant value.
34784 Note that local variables and parameters are replaced by compiler generated
34787 \begin_inset LatexCommand \index{Live range analysis}
34791 are computed only for temporaries (i.e.
34792 live ranges are not computed for global variables).
34794 \begin_inset LatexCommand \index{Register allocation}
34798 are allocated for temporaries only.
34799 Operands are formatted in the following manner:
34804 Operand Name [lr live-from : live-to ] { type information } [ registers
34810 As mentioned earlier the live ranges are computed in terms of the execution
34811 sequence number of the iCodes, for example
34813 the iTemp0 is live from (i.e.
34814 first defined in iCode with execution sequence number 3, and is last used
34815 in the iCode with sequence number 5).
34816 For induction variables such as iTemp21 the live range computation extends
34817 the lifetime from the start to the end of the loop.
34819 The register allocator
34820 used the live range information to allocate registers, the same registers
34821 may be used for different temporaries if their live ranges do not overlap,
34822 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
34823 ranges do not overlap.
34824 In addition the allocator also takes into consideration the type and usage
34825 of a temporary, for example itemp6 is a pointer to near space and is used
34826 as to fetch data from (i.e.
34827 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
34828 Some short lived temporaries are allocated to special registers which have
34829 meaning to the code generator e.g.
34830 iTemp13 is allocated to a pseudo register CC which tells the back end that
34831 the temporary is used only for a conditional jump the code generation makes
34832 use of this information to optimize a compare and jump ICode.
34836 \begin_inset LatexCommand \index{Loop optimization}
34840 performed by the compiler.
34841 It can detect induction variables iTemp21(i) and iTemp23(j).
34842 Also note the compiler does selective strength reduction
34843 \begin_inset LatexCommand \index{Strength reduction}
34848 the multiplication of an induction variable in line 18 (gint = j * 3) is
34849 changed to addition, a new temporary iTemp17 is allocated and assigned
34850 a initial value, a constant 3 is then added for each iteration of the loop.
34851 The compiler does not change the multiplication
34852 \begin_inset LatexCommand \index{Multiplication}
34856 in line 17 however since the processor does support an 8 * 8 bit multiplication.
34859 Note the dead code elimination
34860 \begin_inset LatexCommand \index{Dead-code elimination}
34864 optimization eliminated the dead assignments in line 7 & 8 to I and sum
34872 Sample.c (5:1:0:0) _entry($9) :
34877 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34882 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
34887 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34892 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34898 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34903 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34909 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34914 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34920 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34926 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34932 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34938 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34939 * int}[r0] + 0x2 {short}
34944 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34949 Sample.c(11:17:21:0)_whilebreak_0($3) :
34954 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34959 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34964 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34969 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34974 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34979 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34984 Sample.c(15:24:26:1)_forcond_0($4) :
34989 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34995 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
35000 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
35001 + ITemp21 [lr21:38]{short}[r4]
35006 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
35012 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
35013 + iTemp15 [lr29:30]{short}[r1]
35018 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
35024 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
35030 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
35036 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
35042 Sample.c(19:38:47:1) goto _forcond_0($4)
35047 Sample.c(19:39:48:0)_forbreak_0($7) :
35052 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
35053 + ITemp11 [lr19:40]{short}[r3]
35058 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
35063 Sample.c(20:42:51:0)_return($8) :
35068 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
35074 Finally the code generated for this function:
35115 ; ----------------------------------------------
35120 ; function function
35125 ; ----------------------------------------------
35135 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
35147 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
35159 ;_whilecontinue_0($1) :
35169 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
35174 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
35233 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
35252 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
35299 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
35339 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
35365 ; iTemp6 [lr5:16]{_near * int}[r0] =
35370 ; iTemp6 [lr5:16]{_near * int}[r0] +
35387 ; goto _whilecontinue_0($1)
35399 ; _whilebreak_0($3) :
35409 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
35421 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
35433 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
35445 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
35464 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
35493 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
35498 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
35543 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
35548 ; iTemp21 [lr21:38]{short}[r4]
35574 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
35607 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
35612 ; iTemp15 [lr29:30]{short}[r1]
35631 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
35678 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
35725 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
35737 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
35751 cjne r5,#0xff,00104$
35763 ; goto _forcond_0($4)
35775 ; _forbreak_0($7) :
35785 ; ret iTemp24 [lr40:41]{short}
35828 A few words about basic block successors, predecessors and dominators
35831 Successors are basic blocks
35832 \begin_inset LatexCommand \index{Basic blocks}
35836 that might execute after this basic block.
35838 Predecessors are basic blocks
35839 that might execute before reaching this basic block.
35841 Dominators are basic
35842 blocks that WILL execute before reaching this basic block.
35875 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35878 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35881 c) domVect of [BB4] = BB1 ...
35882 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35889 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35899 Thanks to all the other volunteer developers who have helped with coding,
35900 testing, web-page creation, distribution sets, etc.
35901 You know who you are :-)
35909 Also thanks to Sourceforge
35910 \begin_inset LatexCommand \url{http://www.sf.net}
35914 which has hosted the project since 1999 and donates significant download
35915 bandwidth and probably more than
35925 CPU cycles per day.
35932 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35933 minutes for (configure+make+regression test), and there is (i386, amd64,
35934 alpha, ppc64, (mingw32), sparc, macosx).
35942 This document was initially written by Sandeep Dutta
35945 All product names mentioned herein may be trademarks
35946 \begin_inset LatexCommand \index{Trademarks}
35950 of their respective companies.
35957 To avoid confusion, the installation and building options for SDCC itself
35958 (chapter 2) are not part of the index.
35961 \begin_inset LatexCommand \printindex{}