1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
5 \pdfoptionpdfminorversion=3
7 pdftitle={SDCC Compiler User Guide},
8 pdfauthor={SDCC development team},
9 pdfsubject={installation, user manual},
10 pdfkeywords={68hc08 8032 8051 ansi c compiler CPU DS390 embedded free Freescale GPL HC08 Intel manual Maxim mcs51 Microchip microcontroller open source PIC Z80 Zilog},
11 pdfpagemode=UseOutlines,
13 linkcolor=blue] {hyperref}
17 \emergencystretch=30pt
22 \inputencoding default
25 \paperfontsize default
27 \papersize letterpaper
32 \use_numerical_citations 0
33 \paperorientation portrait
40 \paragraph_separation indent
42 \quotes_language swedish
50 Please note: double dashed longoptions (e.g.
51 --version) are written this way: -
65 three consecutive dashes simply result in a long resp.
69 Architecture specific stuff (like memory models, code examples) should maybe
73 into seperate sections/chapters/appendices (it is hard to document PIC or
77 a 8051 centered document) - for now simply add.
80 SDCC Compiler User Guide
94 The above strings enclosed in $ are automatically updated by Subversion
98 \begin_inset LatexCommand \tableofcontents{}
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
136 designed for 8 bit Microprocessors.
137 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144 Zilog Z80 based MCUs.
145 It can be retargetted for other microprocessors, support for Microchip
146 PIC, Atmel AVR is under development.
147 The entire source code for the compiler is distributed under GPL.
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
154 \begin_inset LatexCommand \index{aslink}
158 , an open source retargettable assembler & linker.
159 SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
165 In addition to the MCU specific optimizations SDCC also does a host of standard
169 global sub expression elimination,
172 loop optimizations (loop invariant, strength reduction of induction variables
176 constant folding & propagation,
182 dead code elimination
192 For the back-end SDCC uses a global register allocation scheme which should
193 be well suited for other 8 bit MCUs.
198 The peep hole optimizer uses a rule based substitution mechanism which is
204 Supported data-types are:
209 <lyxtabular version="3" rows="8" columns="5">
211 <column alignment="center" valignment="top" leftline="true" width="0">
212 <column alignment="center" valignment="top" leftline="true" width="0">
213 <column alignment="center" valignment="top" leftline="true" width="0">
214 <column alignment="center" valignment="top" leftline="true" width="0">
215 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
216 <row topline="true" bottomline="true">
217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
426 <row topline="true" bottomline="true">
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
456 -2.147.483.648, +2.147.483.647
459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
468 <row topline="true" bottomline="true">
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
508 <row topline="true" bottomline="true">
509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
554 The compiler also allows
556 inline assembler code
558 to be embedded anywhere in a function.
559 In addition, routines developed in assembly can also be called.
563 SDCC also provides an option (-
573 -cyclomatic) to report the relative complexity of a function.
574 These functions can then be further optimized, or hand coded in assembly
580 SDCC also comes with a companion source level debugger SDCDB, the debugger
581 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
582 SDCDB and ucSim are currently not available on Win32 platforms.
587 The latest version can be downloaded from
588 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
598 Please note: the compiler will probably always be some steps ahead of this
603 \begin_inset LatexCommand \index{Status of documentation}
613 Obviously this has pros and cons
622 All packages used in this compiler system are
630 ; source code for all the sub-packages (pre-processor, assemblers, linkers
631 etc) is distributed with the package.
632 This documentation is maintained using a freeware word processor (LyX).
634 This program is free software; you can redistribute it and/or modify it
635 under the terms of the GNU General Public License
636 \begin_inset LatexCommand \index{GNU General Public License, GPL}
640 as published by the Free Software Foundation; either version 2, or (at
641 your option) any later version.
642 This program is distributed in the hope that it will be useful, but WITHOUT
643 ANY WARRANTY; without even the implied warranty
644 \begin_inset LatexCommand \index{warranty}
648 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
649 See the GNU General Public License for more details.
650 You should have received a copy of the GNU General Public License along
651 with this program; if not, write to the Free Software Foundation, 59 Temple
652 Place - Suite 330, Boston, MA 02111-1307, USA.
653 In other words, you are welcome to use, share and improve this program.
654 You are forbidden to forbid anyone else to use, share and improve what
656 Help stamp out software-hoarding!
659 Typographic conventions
660 \begin_inset LatexCommand \index{Typographic conventions}
667 Throughout this manual, we will use the following convention.
668 Commands you have to type in are printed in
676 Code samples are printed in
681 Interesting items and new terms are printed in
687 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
691 with previous versions
692 \begin_inset LatexCommand \index{Compatibility with previous versions}
699 This version has numerous bug fixes compared with the previous version.
700 But we also introduced some incompatibilities with older versions.
701 Not just for the fun of it, but to make the compiler more stable, efficient
703 \begin_inset LatexCommand \index{ANSI-compliance}
708 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
712 for ANSI-Compliance).
718 short is now equivalent to int (16 bits), it used to be equivalent to char
719 (8 bits) which is not ANSI compliant.
722 the default directory for gcc-builds where include, library and documentation
723 files are stored is now in /usr/local/share.
726 char type parameters to vararg functions are casted to int unless explicitly
743 will push a as an int and as a char resp.
756 -regextend has been removed.
769 -noregparms has been removed.
782 -stack-after-data has been removed.
786 \begin_inset LatexCommand \index{bit}
791 \begin_inset LatexCommand \index{sbit}
796 \begin_inset LatexCommand \index{\_\_sbit}
800 types now consistently behave like the C99 _Bool type with respect to type
802 \begin_inset LatexCommand \index{type conversion}
807 \begin_inset LatexCommand \index{type promotion}
812 The most common incompatibility resulting from this change is related to
814 \begin_inset LatexCommand \index{Bit toggling}
828 b = ~b; /* equivalent to b=1 instead of toggling b */
829 \begin_inset Marginal
843 b = !b; /* toggles b */
847 In previous versions, both forms would have toggled the bit.
852 <pending: more incompatibilities?>
858 What do you need before you start installation of SDCC? A computer, and
860 The preferred method of installation is to compile SDCC from source using
862 For Windows some pre-compiled binary distributions are available for your
864 You should have some experience with command line tools and compiler use.
870 The SDCC home page at
871 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
875 is a great place to find distribution sets.
876 You can also find links to the user mailing lists that offer help or discuss
877 SDCC with other SDCC users.
878 Web links to other SDCC related sites can also be found here.
879 This document can be found in the DOC directory of the source package as
881 A pdf version of this document is available at
882 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
887 Some of the other tools (simulator and assembler) included with SDCC contain
888 their own documentation and can be found in the source distribution.
889 If you want the latest unreleased software, the complete source package
890 is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
894 Wishes for the future
897 There are (and always will be) some things that could be done.
898 Here are some I can think of:
905 char KernelFunction3(char p) at 0x340;
913 \begin_inset LatexCommand \index{code banking (limited support)}
923 If you can think of some more, please see the section
924 \begin_inset LatexCommand \ref{sub:Requesting-Features}
928 about filing feature requests
929 \begin_inset LatexCommand \index{Requesting features}
934 \begin_inset LatexCommand \index{Feature request}
944 \begin_inset LatexCommand \index{Installation}
951 For most users it is sufficient to skip to either section
952 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
957 \begin_inset LatexCommand \ref{sub:Windows-Install}
962 More detailled instructions follow below.
966 \begin_inset LatexCommand \index{Options SDCC configuration}
973 The install paths, search paths and other options are defined when running
975 The defaults can be overridden by:
977 \labelwidthstring 00.00.0000
989 -prefix see table below
991 \labelwidthstring 00.00.0000
1003 -exec_prefix see table below
1005 \labelwidthstring 00.00.0000
1017 -bindir see table below
1019 \labelwidthstring 00.00.0000
1031 -datadir see table below
1033 \labelwidthstring 00.00.0000
1035 docdir environment variable, see table below
1037 \labelwidthstring 00.00.0000
1039 include_dir_suffix environment variable, see table below
1041 \labelwidthstring 00.00.0000
1043 lib_dir_suffix environment variable, see table below
1045 \labelwidthstring 00.00.0000
1047 sdccconf_h_dir_separator environment variable, either / or
1052 This character will only be used in sdccconf.h; don't forget it's a C-header,
1053 therefore a double-backslash is needed there.
1055 \labelwidthstring 00.00.0000
1067 -disable-mcs51-port Excludes the Intel mcs51 port
1069 \labelwidthstring 00.00.0000
1081 -disable-gbz80-port Excludes the Gameboy gbz80 port
1083 \labelwidthstring 00.00.0000
1095 -disable-z80-port Excludes the z80 port
1097 \labelwidthstring 00.00.0000
1109 -disable-avr-port Excludes the AVR port
1111 \labelwidthstring 00.00.0000
1123 -disable-ds390-port Excludes the DS390 port
1125 \labelwidthstring 00.00.0000
1137 -disable-hc08-port Excludes the HC08 port
1139 \labelwidthstring 00.00.0000
1151 -disable-pic-port Excludes the PIC port
1153 \labelwidthstring 00.00.0000
1165 -disable-xa51-port Excludes the XA51 port
1167 \labelwidthstring 00.00.0000
1179 -disable-ucsim Disables configuring and building of ucsim
1181 \labelwidthstring 00.00.0000
1193 -disable-device-lib Disables automatically building device libraries
1195 \labelwidthstring 00.00.0000
1207 -disable-packihx Disables building packihx
1209 \labelwidthstring 00.00.0000
1221 -enable-doc Build pdf, html and txt files from the lyx sources
1223 \labelwidthstring 00.00.0000
1235 -enable-libgc Use the Bohem memory allocator.
1236 Lower runtime footprint.
1239 Furthermore the environment variables CC, CFLAGS, ...
1240 the tools and their arguments can be influenced.
1241 Please see `configure -
1251 -help` and the man/info pages of `configure` for details.
1255 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1256 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1257 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1258 At the moment it's not possible to change the default settings (it was
1259 simply never required).
1263 These configure options are compiled into the binaries, and can only be
1264 changed by rerunning 'configure' and recompiling SDCC.
1265 The configure options are written in
1269 to distinguish them from run time environment variables (see section search
1275 \begin_inset Quotes sld
1279 \begin_inset Quotes srd
1282 are used by the SDCC team to build the official Win32 binaries.
1283 The SDCC team uses Mingw32 to build the official Windows binaries, because
1290 a gcc compiler and last but not least
1293 the binaries can be built by cross compiling on Sourceforge's compile farm.
1296 See the examples, how to pass the Win32 settings to 'configure'.
1297 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1298 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1309 \begin_inset Tabular
1310 <lyxtabular version="3" rows="8" columns="3">
1312 <column alignment="block" valignment="top" leftline="true" width="0in">
1313 <column alignment="block" valignment="top" leftline="true" width="0in">
1314 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1315 <row topline="true" bottomline="true">
1316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1341 <row topline="true">
1342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1371 <row topline="true">
1372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1403 <row topline="true">
1404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1441 <row topline="true">
1442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1475 <row topline="true">
1476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1513 <row topline="true">
1514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1541 <row topline="true" bottomline="true">
1542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1578 'configure' also computes relative paths.
1579 This is needed for full relocatability of a binary package and to complete
1580 search paths (see section search paths below):
1586 \begin_inset Tabular
1587 <lyxtabular version="3" rows="4" columns="3">
1589 <column alignment="block" valignment="top" leftline="true" width="0in">
1590 <column alignment="block" valignment="top" leftline="true" width="0in">
1591 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1592 <row topline="true" bottomline="true">
1593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1618 <row topline="true" bottomline="true">
1619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1646 <row bottomline="true">
1647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1674 <row bottomline="true">
1675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1726 \begin_inset Quotes srd
1730 \begin_inset Quotes srd
1744 \begin_inset Quotes srd
1748 \begin_inset Quotes srd
1776 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1785 \begin_inset Quotes srd
1788 i586-mingw32msvc-gcc
1789 \begin_inset Quotes srd
1793 \begin_inset Quotes srd
1796 i586-mingw32msvc-g++
1797 \begin_inset Quotes srd
1805 \begin_inset Quotes srd
1808 i586-mingw32msvc-ranlib
1809 \begin_inset Quotes srd
1817 \begin_inset Quotes srd
1820 i586-mingw32msvc-strip
1821 \begin_inset Quotes srd
1839 \begin_inset Quotes srd
1843 \begin_inset Quotes srd
1861 \begin_inset Quotes srd
1865 \begin_inset Quotes srd
1873 \begin_inset Quotes srd
1877 \begin_inset Quotes srd
1885 \begin_inset Quotes srd
1889 \begin_inset Quotes srd
1897 \begin_inset Quotes srd
1901 \begin_inset Quotes srd
1908 sdccconf_h_dir_separator=
1909 \begin_inset Quotes srd
1921 \begin_inset Quotes srd
1966 -host=i586-mingw32msvc -
1976 -build=unknown-unknown-linux-gnu
1980 \begin_inset Quotes sld
1984 \begin_inset Quotes srd
1987 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1996 \begin_inset Quotes srd
2000 \begin_inset Quotes srd
2008 \begin_inset Quotes srd
2012 \begin_inset Quotes srd
2030 \begin_inset Quotes srd
2034 \begin_inset Quotes srd
2052 \begin_inset Quotes srd
2056 \begin_inset Quotes srd
2064 \begin_inset Quotes srd
2068 \begin_inset Quotes srd
2076 \begin_inset Quotes srd
2080 \begin_inset Quotes srd
2088 \begin_inset Quotes srd
2092 \begin_inset Quotes srd
2099 sdccconf_h_dir_separator=
2100 \begin_inset Quotes srd
2112 \begin_inset Quotes srd
2132 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2143 -C' turns on caching, which gives a little bit extra speed.
2144 However if options are changed, it can be necessary to delete the config.cache
2149 \begin_inset LatexCommand \label{sub:Install-paths}
2154 \begin_inset LatexCommand \index{Install paths}
2160 \added_space_top medskip \align center
2162 \begin_inset Tabular
2163 <lyxtabular version="3" rows="5" columns="4">
2165 <column alignment="left" valignment="top" leftline="true" width="0">
2166 <column alignment="left" valignment="top" leftline="true" width="0">
2167 <column alignment="left" valignment="top" leftline="true" width="0">
2168 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2169 <row topline="true" bottomline="true">
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2211 <row topline="true">
2212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2251 <row topline="true">
2252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2267 $DATADIR/ $INCLUDE_DIR_SUFFIX
2270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2275 /usr/local/share/sdcc/include
2278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2291 <row topline="true">
2292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2307 $DATADIR/$LIB_DIR_SUFFIX
2310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2315 /usr/local/share/sdcc/lib
2318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2331 <row topline="true" bottomline="true">
2332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2355 /usr/local/share/sdcc/doc
2358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2380 *compiler, preprocessor, assembler, and linker
2386 is auto-appended by the compiler, e.g.
2387 small, large, z80, ds390 etc
2390 The install paths can still be changed during `make install` with e.g.:
2393 make install prefix=$(HOME)/local/sdcc
2396 Of course this doesn't change the search paths compiled into the binaries.
2400 Moreover the install path can be changed by defining DESTDIR
2401 \begin_inset LatexCommand \index{DESTDIR}
2408 make install DESTDIR=$(HOME)/sdcc.rpm/
2411 Please note that DESTDIR must have a trailing slash!
2415 \begin_inset LatexCommand \label{sub:Search-Paths}
2420 \begin_inset LatexCommand \index{Search path}
2427 Some search paths or parts of them are determined by configure variables
2432 , see section above).
2433 Further search paths are determined by environment variables during runtime.
2436 The paths searched when running the compiler are as follows (the first catch
2442 Binary files (preprocessor, assembler and linker)
2448 \begin_inset Tabular
2449 <lyxtabular version="3" rows="4" columns="3">
2451 <column alignment="block" valignment="top" leftline="true" width="0in">
2452 <column alignment="block" valignment="top" leftline="true" width="0in">
2453 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2454 <row topline="true" bottomline="true">
2455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2480 <row topline="true">
2481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2510 <row topline="true">
2511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2516 Path of argv[0] (if available)
2519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2536 <row topline="true" bottomline="true">
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2578 \begin_inset Tabular
2579 <lyxtabular version="3" rows="6" columns="3">
2581 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2582 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2583 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2584 <row topline="true" bottomline="true">
2585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2610 <row topline="true">
2611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2666 <row topline="true">
2667 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2692 <row topline="true">
2693 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2707 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2730 <row topline="true">
2731 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2812 <row topline="true" bottomline="true">
2813 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2829 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2834 /usr/local/share/sdcc/
2839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2867 -nostdinc disables the last two search paths.
2877 With the exception of
2878 \begin_inset Quotes sld
2892 \begin_inset Quotes srd
2899 is auto-appended by the compiler (e.g.
2900 small, large, z80, ds390 etc.).
2907 \begin_inset Tabular
2908 <lyxtabular version="3" rows="6" columns="3">
2910 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2911 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2912 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2913 <row topline="true" bottomline="true">
2914 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2922 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2939 <row topline="true">
2940 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2995 <row topline="true">
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3008 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3035 <row topline="true">
3036 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3047 $LIB_DIR_SUFFIX/<model>
3050 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3064 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 <row topline="true">
3082 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3097 $LIB_DIR_SUFFIX/<model>
3100 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3209 <row topline="true" bottomline="true">
3210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3219 $LIB_DIR_SUFFIX/<model>
3222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3227 /usr/local/share/sdcc/
3234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3252 Don't delete any of the stray spaces in the table above without checking
3253 the HTML output (last line)!
3269 -nostdlib disables the last two search paths.
3273 \begin_inset LatexCommand \index{Building SDCC}
3280 Building SDCC on Linux
3281 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3290 Download the source package
3292 either from the SDCC Subversion repository or from the nightly snapshots
3294 , it will be named something like sdcc
3305 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3314 Bring up a command line terminal, such as xterm.
3319 Unpack the file using a command like:
3322 "tar -xvzf sdcc.src.tar.gz
3327 , this will create a sub-directory called sdcc with all of the sources.
3330 Change directory into the main SDCC directory, for example type:
3347 This configures the package for compilation on your system.
3363 All of the source packages will compile, this can take a while.
3379 This copies the binary executables, the include files, the libraries and
3380 the documentation to the install directories.
3381 Proceed with section
3382 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3389 Building SDCC on OSX 2.x
3392 Follow the instruction for Linux.
3396 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3397 )) fails to compile SDCC.
3398 Fortunately there's also gcc 2.9.x installed, which works fine.
3399 This compiler can be selected by running 'configure' with:
3402 ./configure CC=gcc2 CXX=g++2
3405 Cross compiling SDCC on Linux for Windows
3408 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3409 See section 'Configure Options'.
3412 Building SDCC on Windows
3415 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3417 They use Unix-sockets, which are not available on Win32.
3420 Building SDCC using Cygwin and Mingw32
3423 For building and installing a Cygwin executable follow the instructions
3429 \begin_inset Quotes sld
3433 \begin_inset Quotes srd
3436 Win32-binary can be built, which will not need the Cygwin-DLL.
3437 For the necessary 'configure' options see section 'configure options' or
3438 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3442 In order to install Cygwin on Windows download setup.exe from
3443 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3449 \begin_inset Quotes sld
3452 default text file type
3453 \begin_inset Quotes srd
3457 \begin_inset Quotes sld
3461 \begin_inset Quotes srd
3464 and download/install at least the following packages.
3465 Some packages are selected by default, others will be automatically selected
3466 because of dependencies with the manually selected packages.
3467 Never deselect these packages!
3476 gcc ; version 3.x is fine, no need to use the old 2.9x
3479 binutils ; selected with gcc
3485 rxvt ; a nice console, which makes life much easier under windoze (see below)
3488 man ; not really needed for building SDCC, but you'll miss it sooner or
3492 less ; not really needed for building SDCC, but you'll miss it sooner or
3496 svn ; only if you use Subversion access
3499 If you want to develop something you'll need:
3502 python ; for the regression tests
3505 gdb ; the gnu debugger, together with the nice GUI
3506 \begin_inset Quotes sld
3510 \begin_inset Quotes srd
3516 openssh ; to access the CF or commit changes
3519 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3520 use autoconf-stable!
3523 rxvt is a nice console with history.
3524 Replace in your cygwin.bat the line
3543 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3546 -bg black -fg white -geometry 100x65 -e bash -
3559 Text selected with the mouse is automatically copied to the clipboard, pasting
3560 works with shift-insert.
3564 The other good tip is to make sure you have no //c/-style paths anywhere,
3565 use /cygdrive/c/ instead.
3566 Using // invokes a network lookup which is very slow.
3568 \begin_inset Quotes sld
3572 \begin_inset Quotes srd
3575 is too long, you can change it with e.g.
3581 SDCC sources use the unix line ending LF.
3582 Life is much easier, if you store the source tree on a drive which is mounted
3584 And use an editor which can handle LF-only line endings.
3585 Make sure not to commit files with windows line endings.
3586 The tabulator spacing
3587 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3591 used in the project is 8.
3592 Although a tabulator spacing of 8 is a sensible choice for programmers
3593 (it's a power of 2 and allows to display 8/16 bit signed variables without
3594 loosing columns) the plan is to move towards using only spaces in the source.
3597 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3602 Download the source package
3604 either from the SDCC Subversion repository or from the
3605 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3611 , it will be named something like sdcc
3618 SDCC is distributed with all the projects, workspaces, and files you need
3619 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3620 doesn't build under MSVC).
3621 The workspace name is 'sdcc.dsw'.
3622 Please note that as it is now, all the executables are created in a folder
3626 Once built you need to copy the executables from sdcc
3630 bin before running SDCC.
3635 WARNING: Visual studio is very picky with line terminations; it expects
3636 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3637 When using the Subversion repository it's easiest to configure the svn
3638 client to convert automatically for you.
3639 If however you are getting a message such as "This makefile was not generated
3640 by Developer Studio etc.
3642 \begin_inset Quotes srd
3645 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3646 need to convert the Unix style line endings to DOS style line endings.
3647 To do so you can use the
3648 \begin_inset Quotes sld
3652 \begin_inset Quotes srd
3655 utility freely available on the internet.
3656 Doug Hawkins reported in the sdcc-user list that this works:
3664 SDCC> unix2dos sdcc.dsw
3670 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3674 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3675 flex.exe, and gawk.exe.
3676 One good place to get them is
3677 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3685 Download the file UnxUtils
3686 \begin_inset LatexCommand \index{UnxUtils}
3691 Now you have to install the utilities and setup MSVC so it can locate the
3693 Here there are two alternatives (choose one!):
3700 a) Extract UnxUtils.zip to your C:
3702 hard disk PRESERVING the original paths, otherwise bison won't work.
3703 (If you are using WinZip make certain that 'Use folder names' is selected)
3707 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3708 in 'Show directories for:' select 'Executable files', and in the directories
3709 window add a new path: 'C:
3719 (As a side effect, you get a bunch of Unix utilities that could be useful,
3720 such as diff and patch.)
3727 This one avoids extracting a bunch of files you may not use, but requires
3732 a) Create a directory were to put the tools needed, or use a directory already
3740 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3741 to such directory WITHOUT preserving the original paths.
3742 (If you are using WinZip make certain that 'Use folder names' is not selected)
3746 c) Rename bison.exe to '_bison.exe'.
3750 d) Create a batch file 'bison.bat' in 'C:
3754 ' and add these lines:
3774 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3778 Steps 'c' and 'd' are needed because bison requires by default that the
3779 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3780 '/usr/local/share/' I think.
3781 So it is necessary to tell bison where those files are located if they
3782 are not in such directory.
3783 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3787 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3788 in 'Show directories for:' select 'Executable files', and in the directories
3789 window add a new path: 'c:
3792 Note that you can use any other path instead of 'c:
3794 util', even the path where the Visual C++ tools are, probably: 'C:
3798 Microsoft Visual Studio
3803 So you don't have to execute step 'e' :)
3807 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3808 the executables from sdcc
3812 bin, and you can compile using SDCC.
3815 Building SDCC Using Borland
3818 From the sdcc directory, run the command "make -f Makefile.bcc".
3819 This should regenerate all the .exe files in the bin directory except for
3820 sdcdb.exe (which currently doesn't build under Borland C++).
3823 If you modify any source files and need to rebuild, be aware that the dependenci
3824 es may not be correctly calculated.
3825 The safest option is to delete all .obj files and run the build again.
3826 From a Cygwin BASH prompt, this can easily be done with the command (be
3827 sure you are in the sdcc directory):
3837 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3839 ) -print -exec rm {}
3848 or on Windows NT/2000/XP from the command prompt with the command:
3855 del /s *.obj *.lib *.rul
3858 from the sdcc directory.
3861 Windows Install Using a ZIP Package
3864 Download the binary zip package from
3865 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3869 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3870 This should unpack to a group of sub-directories.
3871 An example directory structure after unpacking the mingw32 package is:
3876 bin for the executables, c:
3884 lib for the include and libraries.
3887 Adjust your environment variable PATH to include the location of the bin
3888 directory or start sdcc using the full path.
3891 Windows Install Using the Setup Program
3892 \begin_inset LatexCommand \label{sub:Windows-Install}
3899 Download the setup program
3901 sdcc-x.y.z-setup.exe
3903 for an official release from
3906 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3910 or a setup program for one of the snapshots
3912 sdcc-yyyymmdd-xxxx-setup.exe
3915 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3920 A windows typical installer will guide you through the installation process.
3924 \begin_inset LatexCommand \index{VPATH}
3931 SDCC supports the VPATH feature provided by configure and make.
3932 It allows to separate the source and build trees.
3964 tar -xzf sdcc.src.tar.gz\SpecialChar ~
3965 # extract source to directory sdcc
3970 mkdir sdcc.build\SpecialChar ~
3979 # put output in sdcc.build
3989 ../sdcc/configure\SpecialChar ~
3997 # configure is doing all the magic!
4009 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4010 It automagically computes the variables srcdir, top_srcdir and top_buildir
4016 the generated files will be in ~/sdcc.build, while the source files stay
4019 This is not only usefull for building different binaries, e.g.
4020 when cross compiling.
4021 It also gives you a much better overview in the source tree when all the
4022 generated files are not scattered between the source files.
4023 And the best thing is: if you want to change a file you can leave the original
4024 file untouched in the source directory.
4025 Simply copy it to the build directory, edit it, enter `make clean`, `rm
4026 Makefile.dep` and `make`.
4031 will do the rest for you!
4034 Building the Documentation
4047 -enable-doc to the configure arguments to build the documentation together
4048 with all the other stuff.
4049 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4050 dvips and makeindex) to get the job done.
4051 Another possibility is to change to the doc directory and to type
4055 \begin_inset Quotes srd
4059 \begin_inset Quotes srd
4066 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4069 \begin_inset LatexCommand \url{http://www.lyx.org}
4073 as editor is straightforward.
4074 Prebuilt documentation in html and pdf format is available from
4075 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4082 Reading the Documentation
4085 Currently reading the document in pdf format is recommended, as for unknown
4086 reason the hyperlinks are working there whereas in the html version they
4093 If you should know why please drop us a note
4099 You'll find the pdf version
4100 \begin_inset LatexCommand \index{PDF version of this document}
4105 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4113 \begin_inset LatexCommand \index{HTML version of this document}
4118 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4124 This documentation is in some aspects different from a commercial documentation:
4128 It tries to document SDCC for several processor architectures in one document
4129 (commercially these probably would be separate documents/products).
4131 \begin_inset LatexCommand \index{Status of documentation}
4135 currently matches SDCC for mcs51 and DS390 best and does give too few informati
4137 Z80, PIC14, PIC16 and HC08.
4140 There are many references pointing away from this documentation.
4141 Don't let this distract you.
4143 was a reference like
4144 \begin_inset LatexCommand \url{http://www.opencores.org}
4148 together with a statement
4149 \begin_inset Quotes sld
4152 some processors which are targetted by SDCC can be implemented in a
4169 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4174 \begin_inset Quotes srd
4178 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4183 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4188 \begin_inset Quotes sld
4191 have you ever heard of an open source compiler that compiles a subset of
4193 \begin_inset Quotes srd
4196 we expect you to have a quick look there and come back.
4197 If you read this you are on the right track.
4200 Some sections attribute more space to problems, restrictions and warnings
4201 than to the solution.
4204 The installation section and the section about the debugger is intimidating.
4207 There are still lots of typos and there are more different writing styles
4211 Testing the SDCC Compiler
4212 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4219 The first thing you should do after installing your SDCC compiler is to
4235 \begin_inset LatexCommand \index{version}
4242 at the prompt, and the program should run and output its version like:
4247 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4251 If it doesn't run, or gives a message about not finding sdcc program, then
4252 you need to check over your installation.
4253 Make sure that the sdcc bin directory is in your executable search path
4254 defined by the PATH environment setting (
4259 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4266 Install trouble-shooting for suggestions
4269 Make sure that the sdcc program is in the bin folder, if not perhaps something
4270 did not install correctly.
4278 is commonly installed as described in section
4279 \begin_inset Quotes sld
4282 Install and search paths
4283 \begin_inset Quotes srd
4292 Make sure the compiler works on a very simple example.
4293 Type in the following test.c program using your favorite
4319 Compile this using the following command:
4328 If all goes well, the compiler will generate a test.asm and test.rel file.
4329 Congratulations, you've just compiled your first program with SDCC.
4330 We used the -c option to tell SDCC not to link the generated code, just
4331 to keep things simple for this step.
4339 The next step is to try it with the linker.
4349 If all goes well the compiler will link with the libraries and produce
4350 a test.ihx output file.
4355 (no test.ihx, and the linker generates warnings), then the problem is most
4364 usr/local/share/sdcc/lib directory
4371 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4378 Install trouble-shooting for suggestions).
4386 The final test is to ensure
4394 header files and libraries.
4395 Edit test.c and change it to the following:
4412 strcpy(str1, "testing");
4419 Compile this by typing
4426 This should generate a test.ihx output file, and it should give no warnings
4427 such as not finding the string.h file.
4428 If it cannot find the string.h file, then the problem is that
4432 cannot find the /usr/local/share/sdcc/include directory
4439 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4446 Install trouble-shooting section for suggestions).
4464 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4468 to find exactly where SDCC is looking for the include and lib files.
4471 Install Trouble-shooting
4472 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4477 \begin_inset LatexCommand \index{Install trouble-shooting}
4484 If SDCC does not build correctly
4487 A thing to try is starting from scratch by unpacking the .tgz source package
4488 again in an empty directory.
4496 ./configure 2>&1 | tee configure.log
4510 make 2>&1 | tee make.log
4517 If anything goes wrong, you can review the log files to locate the problem.
4518 Or a relevant part of this can be attached to an email that could be helpful
4519 when requesting help from the mailing list.
4523 \begin_inset Quotes sld
4527 \begin_inset Quotes srd
4534 \begin_inset Quotes sld
4538 \begin_inset Quotes srd
4541 command is a script that analyzes your system and performs some configuration
4542 to ensure the source package compiles on your system.
4543 It will take a few minutes to run, and will compile a few tests to determine
4544 what compiler features are installed.
4548 \begin_inset Quotes sld
4552 \begin_inset Quotes srd
4558 This runs the GNU make tool, which automatically compiles all the source
4559 packages into the final installed binary executables.
4563 \begin_inset Quotes sld
4567 \begin_inset Quotes erd
4573 This will install the compiler, other executables libraries and include
4574 files into the appropriate directories.
4576 \begin_inset LatexCommand \ref{sub:Install-paths}
4582 \begin_inset LatexCommand \ref{sub:Search-Paths}
4587 about install and search paths.
4589 On most systems you will need super-user privileges to do this.
4595 SDCC is not just a compiler, but a collection of tools by various developers.
4596 These include linkers, assemblers, simulators and other components.
4597 Here is a summary of some of the components.
4598 Note that the included simulator and assembler have separate documentation
4599 which you can find in the source package in their respective directories.
4600 As SDCC grows to include support for other processors, other packages from
4601 various developers are included and may have their own sets of documentation.
4605 You might want to look at the files which are installed in <installdir>.
4606 At the time of this writing, we find the following programs for gcc-builds:
4610 In <installdir>/bin:
4613 sdcc - The compiler.
4616 sdcpp - The C preprocessor.
4619 asx8051 - The assembler for 8051 type processors.
4626 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4629 aslink -The linker for 8051 type processors.
4636 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4639 s51 - The ucSim 8051 simulator.
4640 Not available on Win32 platforms.
4643 sdcdb - The source debugger.
4644 Not available on Win32 platforms.
4647 packihx - A tool to pack (compress) Intel hex files.
4650 In <installdir>/share/sdcc/include
4656 In <installdir>/share/sdcc/lib
4659 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4663 In <installdir>/share/sdcc/doc
4669 As development for other processors proceeds, this list will expand to include
4670 executables to support processors like AVR, PIC, etc.
4676 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4677 the assembler and linkage editor.
4680 sdcpp - The C-Preprocessor
4684 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4688 is a modified version of the GNU preprocessor.
4689 The C preprocessor is used to pull in #include sources, process #ifdef
4690 statements, #defines and so on.
4701 - The Assemblers and Linkage Editors
4704 This is retargettable assembler & linkage editor, it was developed by Alan
4706 John Hartman created the version for 8051, and I (Sandeep) have made some
4707 enhancements and bug fixes for it to work properly with SDCC.
4714 \begin_inset LatexCommand \index{s51}
4718 is a freeware, opensource simulator developed by Daniel Drotos.
4719 The simulator is built as part of the build process.
4720 For more information visit Daniel's web site at:
4721 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4726 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4728 S51 is currently not available on Win32 platfors.
4731 sdcdb - Source Level Debugger
4735 \begin_inset LatexCommand \index{sdcdb (debugger)}
4739 is the companion source level debugger.
4740 More about sdcdb in section
4741 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4746 The current version of the debugger uses Daniel's Simulator S51
4747 \begin_inset LatexCommand \index{s51}
4751 , but can be easily changed to use other simulators.
4752 Sdcdb is currently not available on Win32 platfors.
4761 Single Source File Projects
4764 For single source file 8051 projects the process is very simple.
4765 Compile your programs with the following command
4768 "sdcc sourcefile.c".
4772 This will compile, assemble and link your source file.
4773 Output files are as follows:
4777 \begin_inset LatexCommand \index{<file>.asm}
4782 \begin_inset LatexCommand \index{Assembler source}
4786 file created by the compiler
4790 \begin_inset LatexCommand \index{<file>.lst}
4795 \begin_inset LatexCommand \index{Assembler listing}
4799 file created by the Assembler
4803 \begin_inset LatexCommand \index{<file>.rst}
4808 \begin_inset LatexCommand \index{Assembler listing}
4812 file updated with linkedit information, created by linkage editor
4816 \begin_inset LatexCommand \index{<file>.sym}
4821 \begin_inset LatexCommand \index{Symbol listing}
4825 for the sourcefile, created by the assembler
4829 \begin_inset LatexCommand \index{<file>.rel}
4834 \begin_inset LatexCommand \index{<file>.o}
4839 \begin_inset LatexCommand \index{Object file}
4843 created by the assembler, input to Linkage editor
4847 \begin_inset LatexCommand \index{<file>.map}
4852 \begin_inset LatexCommand \index{Memory map}
4856 for the load module, created by the Linker
4860 \begin_inset LatexCommand \index{<file>.mem}
4864 - A file with a summary of the memory usage
4868 \begin_inset LatexCommand \index{<file>.ihx}
4872 - The load module in Intel hex format
4873 \begin_inset LatexCommand \index{Intel hex format}
4877 (you can select the Motorola S19 format
4878 \begin_inset LatexCommand \index{Motorola S19 format}
4893 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4898 If you need another format you might want to use
4905 \begin_inset LatexCommand \index{objdump (tool)}
4916 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4921 Both formats are documented in the documentation of srecord
4922 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4930 \begin_inset LatexCommand \index{<file>.adb}
4934 - An intermediate file containing debug information needed to create the
4946 \begin_inset LatexCommand \index{-\/-debug}
4954 \begin_inset LatexCommand \index{<file>.cdb}
4958 - An optional file (with -
4968 -debug) containing debug information.
4969 The format is documented in cdbfileformat.pdf
4974 \begin_inset LatexCommand \index{<file> (no extension)}
4978 An optional AOMF or AOMF51
4979 \begin_inset LatexCommand \index{AOMF, AOMF51}
4984 \begin_inset LatexCommand \label{OMF file}
4988 file containing debug information (generated with option -
5015 ormat is commonly used by third party tools (debuggers
5016 \begin_inset LatexCommand \index{Debugger}
5020 , simulators, emulators)
5024 \begin_inset LatexCommand \index{<file>.dump*}
5028 - Dump file to debug the compiler it self (generated with option -
5038 -dumpall) (see section
5039 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5045 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5051 \begin_inset Quotes sld
5054 Anatomy of the compiler
5055 \begin_inset Quotes srd
5061 Projects with Multiple Source Files
5064 SDCC can compile only ONE file at a time.
5065 Let us for example assume that you have a project containing the following
5070 foo1.c (contains some functions)
5072 foo2.c (contains some more functions)
5074 foomain.c (contains more functions and the function main)
5082 The first two files will need to be compiled separately with the commands:
5114 Then compile the source file containing the
5119 \begin_inset LatexCommand \index{Linker}
5123 the files together with the following command:
5131 foomain.c\SpecialChar ~
5132 foo1.rel\SpecialChar ~
5137 \begin_inset LatexCommand \index{<file>.rel}
5149 can be separately compiled as well:
5160 sdcc foomain.rel foo1.rel foo2.rel
5167 The file containing the
5182 file specified in the command line, since the linkage editor processes
5183 file in the order they are presented to it.
5184 The linker is invoked from SDCC using a script file with extension .lnk
5185 \begin_inset LatexCommand \index{<file>.lnk}
5190 You can view this file to troubleshoot linking problems such as those arising
5191 from missing libraries.
5194 Projects with Additional Libraries
5195 \begin_inset LatexCommand \index{Libraries}
5202 Some reusable routines may be compiled into a library, see the documentation
5203 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5207 \begin_inset LatexCommand \index{<file>.lib}
5214 Libraries created in this manner can be included in the command line.
5215 Make sure you include the -L <library-path> option to tell the linker where
5216 to look for these files if they are not in the current directory.
5217 Here is an example, assuming you have the source file
5229 (if that is not the same as your current project):
5236 sdcc foomain.c foolib.lib -L mylib
5247 must be an absolute path name.
5251 The most efficient way to use libraries is to keep separate modules in separate
5253 The lib file now should name all the modules.rel
5254 \begin_inset LatexCommand \index{<file>.rel}
5259 For an example see the standard library file
5263 in the directory <installdir>/share/lib/small.
5266 Using sdcclib to Create and Manage Libraries
5267 \begin_inset LatexCommand \index{sdcclib}
5274 Alternatively, instead of having a .rel file for each entry on the library
5275 file as described in the preceding section, sdcclib can be used to embed
5276 all the modules belonging to such library in the library file itself.
5277 This results in a larger library file, but it greatly reduces the number
5278 of disk files accessed by the linker.
5279 Additionally, the packed library file contains an index of all include
5280 modules and symbols that significantly speeds up the linking process.
5281 To display a list of options supported by sdcclib type:
5290 \begin_inset LatexCommand \index{sdcclib}
5301 To create a new library file, start by compiling all the required modules.
5339 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5341 The next step is to add the .rel files to the library file:
5349 sdcclib libint.lib _divsint.rel
5352 \begin_inset LatexCommand \index{sdcclib}
5362 sdcclib libint.lib _divuint.rel
5368 sdcclib libint.lib _modsint.rel
5374 sdcclib libint.lib _moduint.rel
5380 sdcclib libint.lib _mulint.rel
5387 If the file already exists in the library, it will be replaced.
5388 To see what modules and symbols are included in the library, options -s
5389 and -m are available.
5397 sdcclib -s libint.lib
5400 \begin_inset LatexCommand \index{sdcclib}
5510 If the source files are compiled using -
5521 \begin_inset LatexCommand \index{-\/-debug}
5525 , the corresponding debug information file .adb will be include in the library
5527 The library files created with sdcclib are plain text files, so they can
5528 be viewed with a text editor.
5529 It is not recomended to modify a library file created with sdcclib using
5530 a text editor, as there are file indexes numbers located accross the file
5531 used by the linker to quickly locate the required module to link.
5532 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5533 it can be safely deleted, since all the information required for linking
5534 is embedded in the library file itself.
5535 Library files created using sdcclib are used as described in the preceding
5539 Command Line Options
5540 \begin_inset LatexCommand \index{Command Line Options}
5547 Processor Selection Options
5548 \begin_inset LatexCommand \index{Options processor selection}
5553 \begin_inset LatexCommand \index{Processor selection options}
5559 \labelwidthstring 00.00.0000
5564 \begin_inset LatexCommand \index{-mmcs51}
5570 Generate code for the Intel MCS51
5571 \begin_inset LatexCommand \index{MCS51}
5575 family of processors.
5576 This is the default processor target.
5578 \labelwidthstring 00.00.0000
5583 \begin_inset LatexCommand \index{-mds390}
5589 Generate code for the Dallas DS80C390
5590 \begin_inset LatexCommand \index{DS80C390}
5596 \labelwidthstring 00.00.0000
5601 \begin_inset LatexCommand \index{-mds400}
5607 Generate code for the Dallas DS80C400
5608 \begin_inset LatexCommand \index{DS80C400}
5614 \labelwidthstring 00.00.0000
5619 \begin_inset LatexCommand \index{-mhc08}
5625 Generate code for the Freescale/Motorola HC08
5626 \begin_inset LatexCommand \index{HC08}
5630 family of processors.
5632 \labelwidthstring 00.00.0000
5637 \begin_inset LatexCommand \index{-mz80}
5643 Generate code for the Zilog Z80
5644 \begin_inset LatexCommand \index{Z80}
5648 family of processors.
5650 \labelwidthstring 00.00.0000
5655 \begin_inset LatexCommand \index{-mgbz80}
5661 Generate code for the GameBoy Z80
5662 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5666 processor (Not actively maintained).
5668 \labelwidthstring 00.00.0000
5673 \begin_inset LatexCommand \index{-mavr}
5679 Generate code for the Atmel AVR
5680 \begin_inset LatexCommand \index{AVR}
5684 processor (In development, not complete).
5685 AVR users should probably have a look at winavr
5686 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5691 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5698 I think it is fair to direct users there for now.
5699 Open source is also about avoiding unnecessary work .
5700 But I didn't find the 'official' link.
5702 \labelwidthstring 00.00.0000
5707 \begin_inset LatexCommand \index{-mpic14}
5713 Generate code for the Microchip PIC 14
5714 \begin_inset LatexCommand \index{PIC14}
5718 -bit processors (p16f84 and variants.
5719 In development, not complete).
5722 p16f627 p16f628 p16f84 p16f873 p16f877?
5724 \labelwidthstring 00.00.0000
5729 \begin_inset LatexCommand \index{-mpic16}
5735 Generate code for the Microchip PIC 16
5736 \begin_inset LatexCommand \index{PIC16}
5740 -bit processors (p18f452 and variants.
5741 In development, not complete).
5743 \labelwidthstring 00.00.0000
5749 Generate code for the Toshiba TLCS-900H
5750 \begin_inset LatexCommand \index{TLCS-900H}
5754 processor (Not maintained, not complete).
5756 \labelwidthstring 00.00.0000
5761 \begin_inset LatexCommand \index{-mxa51}
5767 Generate code for the Phillips XA51
5768 \begin_inset LatexCommand \index{XA51}
5772 processor (Not maintained, not complete).
5775 Preprocessor Options
5776 \begin_inset LatexCommand \index{Options preprocessor}
5781 \begin_inset LatexCommand \index{Preprocessor options}
5786 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5792 \labelwidthstring 00.00.0000
5797 \begin_inset LatexCommand \index{-I<path>}
5803 The additional location where the pre processor will look for <..h> or
5804 \begin_inset Quotes eld
5808 \begin_inset Quotes erd
5813 \labelwidthstring 00.00.0000
5818 \begin_inset LatexCommand \index{-D<macro[=value]>}
5824 Command line definition of macros.
5825 Passed to the preprocessor.
5827 \labelwidthstring 00.00.0000
5832 \begin_inset LatexCommand \index{-M}
5838 Tell the preprocessor to output a rule suitable for make describing the
5839 dependencies of each object file.
5840 For each source file, the preprocessor outputs one make-rule whose target
5841 is the object file name for that source file and whose dependencies are
5842 all the files `#include'd in it.
5843 This rule may be a single line or may be continued with `
5845 '-newline if it is long.
5846 The list of rules is printed on standard output instead of the preprocessed
5849 \begin_inset LatexCommand \index{-E}
5855 \labelwidthstring 00.00.0000
5860 \begin_inset LatexCommand \index{-C}
5866 Tell the preprocessor not to discard comments.
5867 Used with the `-E' option.
5869 \labelwidthstring 00.00.0000
5874 \begin_inset LatexCommand \index{-MM}
5885 Like `-M' but the output mentions only the user header files included with
5887 \begin_inset Quotes eld
5891 System header files included with `#include <file>' are omitted.
5893 \labelwidthstring 00.00.0000
5898 \begin_inset LatexCommand \index{-Aquestion(answer)}
5904 Assert the answer answer for question, in case it is tested with a preprocessor
5905 conditional such as `#if #question(answer)'.
5906 `-A-' disables the standard assertions that normally describe the target
5909 \labelwidthstring 00.00.0000
5914 \begin_inset LatexCommand \index{-Umacro}
5920 Undefine macro macro.
5921 `-U' options are evaluated after all `-D' options, but before any `-include'
5922 and `-imacros' options.
5924 \labelwidthstring 00.00.0000
5929 \begin_inset LatexCommand \index{-dM}
5935 Tell the preprocessor to output only a list of the macro definitions that
5936 are in effect at the end of preprocessing.
5937 Used with the `-E' option.
5939 \labelwidthstring 00.00.0000
5944 \begin_inset LatexCommand \index{-dD}
5950 Tell the preprocessor to pass all macro definitions into the output, in
5951 their proper sequence in the rest of the output.
5953 \labelwidthstring 00.00.0000
5958 \begin_inset LatexCommand \index{-dN}
5969 Like `-dD' except that the macro arguments and contents are omitted.
5970 Only `#define name' is included in the output.
5972 \labelwidthstring 00.00.0000
5977 preprocessorOption[,preprocessorOption]
5980 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5985 Pass the preprocessorOption to the preprocessor
5990 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5995 SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5996 Collection (gcc), if you need more dedicated options please refer to the
5998 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6006 \begin_inset LatexCommand \index{Options linker}
6011 \begin_inset LatexCommand \index{Linker options}
6017 \labelwidthstring 00.00.0000
6037 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6042 \begin_inset LatexCommand \index{-L -\/-lib-path}
6049 <absolute path to additional libraries> This option is passed to the linkage
6050 editor's additional libraries
6051 \begin_inset LatexCommand \index{Libraries}
6056 The path name must be absolute.
6057 Additional library files may be specified in the command line.
6058 See section Compiling programs for more details.
6060 \labelwidthstring 00.00.0000
6077 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6082 <Value> The start location of the external ram
6083 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6087 , default value is 0.
6088 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6098 -xram-loc 0x8000 or -
6110 \labelwidthstring 00.00.0000
6127 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6132 <Value> The start location of the code
6133 \begin_inset LatexCommand \index{code}
6137 segment, default value 0.
6138 Note when this option is used the interrupt vector table is also relocated
6139 to the given address.
6140 The value entered can be in Hexadecimal or Decimal format, e.g.: -
6150 -code-loc 0x8000 or -
6162 \labelwidthstring 00.00.0000
6179 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6184 <Value> By default the stack
6185 \begin_inset LatexCommand \index{stack}
6189 is placed after the data segment.
6190 Using this option the stack can be placed anywhere in the internal memory
6192 The value entered can be in Hexadecimal or Decimal format, e.g.
6203 -stack-loc 0x20 or -
6214 Since the sp register is incremented before a push or call, the initial
6215 sp will be set to one byte prior the provided value.
6216 The provided value should not overlap any other memory areas such as used
6217 register banks or the data segment and with enough space for the current
6235 \begin_inset LatexCommand \index{-\/-pack-iram}
6239 option (which is now a default setting) will override this setting, so
6240 you should also specify the
6256 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6260 option if you need to manually place the stack.
6262 \labelwidthstring 00.00.0000
6279 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6284 <Value> By default the external stack
6285 \begin_inset LatexCommand \index{xstack}
6289 is placed after the pdata segment.
6290 Using this option the xstack can be placed anywhere in the external memory
6292 The value entered can be in Hexadecimal or Decimal format, e.g.
6303 -xstack-loc 0x8000 or -
6314 The provided value should not overlap any other memory areas such as the
6315 pdata or xdata segment and with enough space for the current application.
6317 \labelwidthstring 00.00.0000
6334 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6339 <Value> The start location of the internal ram data
6340 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6345 The value entered can be in Hexadecimal or Decimal format, eg.
6367 (By default, the start location of the internal ram data segment is set
6368 as low as possible in memory, taking into account the used register banks
6369 and the bit segment at address 0x20.
6370 For example if register banks 0 and 1 are used without bit variables, the
6371 data segment will be set, if -
6381 -data-loc is not used, to location 0x10.)
6383 \labelwidthstring 00.00.0000
6400 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6405 <Value> The start location of the indirectly addressable internal ram
6406 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6410 of the 8051, default value is 0x80.
6411 The value entered can be in Hexadecimal or Decimal format, eg.
6422 -idata-loc 0x88 or -
6434 \labelwidthstring 00.00.0000
6451 <Value> The start location of the bit
6452 \begin_inset LatexCommand \index{bit}
6456 addressable internal ram of the 8051.
6462 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6465 \labelwidthstring 00.00.0000
6480 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6489 The linker output (final object code) is in Intel Hex format.
6490 \begin_inset LatexCommand \index{Intel hex format}
6494 This is the default option.
6495 The format itself is documented in the documentation of srecord
6496 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6502 \labelwidthstring 00.00.0000
6517 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6526 The linker output (final object code) is in Motorola S19 format
6527 \begin_inset LatexCommand \index{Motorola S19 format}
6532 The format itself is documented in the documentation of srecord.
6534 \labelwidthstring 00.00.0000
6549 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6558 The linker output (final object code) is in ELF format
6559 \begin_inset LatexCommand \index{ELF format}
6564 (Currently only supported for the HC08 processors)
6566 \labelwidthstring 00.00.0000
6571 linkOption[,linkOption]
6574 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6579 Pass the linkOption to the linker.
6580 See file sdcc/as/doc/asxhtm.html for more on linker options.
6584 \begin_inset LatexCommand \index{Options MCS51}
6589 \begin_inset LatexCommand \index{MCS51 options}
6595 \labelwidthstring 00.00.0000
6610 \begin_inset LatexCommand \index{-\/-model-small}
6621 Generate code for Small Model programs, see section Memory Models for more
6623 This is the default model.
6625 \labelwidthstring 00.00.0000
6640 \begin_inset LatexCommand \index{-\/-model-medium}
6646 Generate code for Medium model programs, see section Memory Models for
6648 If this option is used all source files in the project have to be compiled
6650 It must also be used when invoking the linker.
6652 \labelwidthstring 00.00.0000
6667 \begin_inset LatexCommand \index{-\/-model-large}
6673 Generate code for Large model programs, see section Memory Models for more
6675 If this option is used all source files in the project have to be compiled
6677 It must also be used when invoking the linker.
6679 \labelwidthstring 00.00.0000
6694 \begin_inset LatexCommand \index{-\/-xstack}
6700 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6701 variables and passing parameters.
6703 \begin_inset LatexCommand \ref{sub:External-Stack}
6708 External Stack for more details.
6710 \labelwidthstring 00.00.0000
6728 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6732 Causes the linker to check if the internal ram usage is within limits of
6735 \labelwidthstring 00.00.0000
6753 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6757 Causes the linker to check if the external ram usage is within limits of
6760 \labelwidthstring 00.00.0000
6778 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6782 Causes the linker to check if the code memory usage is within limits of
6785 \labelwidthstring 00.00.0000
6803 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6807 Causes the linker to check if there is at minimum <Value> bytes for stack.
6809 \labelwidthstring 00.00.0000
6827 \begin_inset LatexCommand \index{-\/-pack-iram}
6831 Causes the linker to use unused register banks for data variables and pack
6832 data, idata and stack together.
6833 This is the default now.
6835 \labelwidthstring 00.00.0000
6853 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6857 Causes the linker to use old style for allocating memory areas.
6860 DS390 / DS400 Options
6861 \begin_inset LatexCommand \index{Options DS390}
6866 \begin_inset LatexCommand \index{DS390 options}
6872 \labelwidthstring 00.00.0000
6889 \begin_inset LatexCommand \index{-\/-model-flat24}
6899 Generate 24-bit flat mode code.
6900 This is the one and only that the ds390 code generator supports right now
6901 and is default when using
6906 See section Memory Models for more details.
6908 \labelwidthstring 00.00.0000
6923 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6929 disable interrupts during ESP:SP updates.
6931 \labelwidthstring 00.00.0000
6948 \begin_inset LatexCommand \index{-\/-stack-10bit}
6952 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6953 This is the one and only that the ds390 code generator supports right now
6954 and is default when using
6959 In this mode, the stack is located in the lower 1K of the internal RAM,
6960 which is mapped to 0x400000.
6961 Note that the support is incomplete, since it still uses a single byte
6962 as the stack pointer.
6963 This means that only the lower 256 bytes of the potential 1K stack space
6964 will actually be used.
6965 However, this does allow you to reclaim the precious 256 bytes of low RAM
6966 for use for the DATA and IDATA segments.
6967 The compiler will not generate any code to put the processor into 10 bit
6969 It is important to ensure that the processor is in this mode before calling
6970 any re-entrant functions compiled with this option.
6971 In principle, this should work with the
6984 \begin_inset LatexCommand \index{-\/-stack-auto}
6990 option, but that has not been tested.
6991 It is incompatible with the
7004 \begin_inset LatexCommand \index{-\/-xstack}
7011 It also only makes sense if the processor is in 24 bit contiguous addressing
7024 -model-flat24 option
7028 \labelwidthstring 00.00.0000
7043 \begin_inset LatexCommand \index{-\/-stack-probe}
7049 insert call to function __stack_probe at each function prologue.
7051 \labelwidthstring 00.00.0000
7066 \begin_inset LatexCommand \index{-\/-tini-libid}
7072 <nnnn> LibraryID used in -mTININative.
7075 \labelwidthstring 00.00.0000
7090 \begin_inset LatexCommand \index{-\/-use-accelerator}
7096 generate code for DS390 Arithmetic Accelerator.
7101 \begin_inset LatexCommand \index{Options Z80}
7106 \begin_inset LatexCommand \index{Z80 options}
7112 \labelwidthstring 00.00.0000
7129 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
7139 Force a called function to always save BC.
7141 \labelwidthstring 00.00.0000
7158 \begin_inset LatexCommand \index{-\/-no-std-crt0}
7162 When linking, skip the standard crt0.o object file.
7163 You must provide your own crt0.o for your system when linking.
7167 Optimization Options
7168 \begin_inset LatexCommand \index{Options optimization}
7173 \begin_inset LatexCommand \index{Optimization options}
7179 \labelwidthstring 00.00.0000
7194 \begin_inset LatexCommand \index{-\/-nogcse}
7200 Will not do global subexpression elimination, this option may be used when
7201 the compiler creates undesirably large stack/data spaces to store compiler
7211 \begin_inset LatexCommand \index{sloc (spill location)}
7216 A warning message will be generated when this happens and the compiler
7217 will indicate the number of extra bytes it allocated.
7218 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7220 \begin_inset LatexCommand \index{\#pragma nogcse}
7224 can be used to turn off global subexpression elimination
7225 \begin_inset LatexCommand \index{Subexpression elimination}
7229 for a given function only.
7231 \labelwidthstring 00.00.0000
7246 \begin_inset LatexCommand \index{-\/-noinvariant}
7252 Will not do loop invariant optimizations, this may be turned off for reasons
7253 explained for the previous option.
7254 For more details of loop optimizations performed see Loop Invariants in
7256 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7261 It is recommended that this option NOT be used, #pragma\SpecialChar ~
7263 \begin_inset LatexCommand \index{\#pragma noinvariant}
7267 can be used to turn off invariant optimizations for a given function only.
7269 \labelwidthstring 00.00.0000
7284 \begin_inset LatexCommand \index{-\/-noinduction}
7290 Will not do loop induction optimizations, see section strength reduction
7292 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7294 \begin_inset LatexCommand \index{\#pragma noinduction}
7298 can be used to turn off induction optimizations for a given function only.
7300 \labelwidthstring 00.00.0000
7315 \begin_inset LatexCommand \index{-\/-nojtbound}
7326 Will not generate boundary condition check when switch statements
7327 \begin_inset LatexCommand \index{switch statement}
7331 are implemented using jump-tables.
7333 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7338 Switch Statements for more details.
7339 It is recommended that this option is NOT used, #pragma\SpecialChar ~
7341 \begin_inset LatexCommand \index{\#pragma nojtbound}
7345 can be used to turn off boundary checking for jump tables for a given function
7348 \labelwidthstring 00.00.0000
7363 \begin_inset LatexCommand \index{-\/-noloopreverse}
7372 Will not do loop reversal
7373 \begin_inset LatexCommand \index{Loop reversing}
7379 \labelwidthstring 00.00.0000
7396 \begin_inset LatexCommand \index{-\/-nolabelopt }
7400 Will not optimize labels (makes the dumpfiles more readable).
7402 \labelwidthstring 00.00.0000
7417 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7423 Will not memcpy initialized data from code space into xdata space.
7424 This saves a few bytes in code space if you don't have initialized data
7425 \begin_inset LatexCommand \index{Variable initialization}
7431 \labelwidthstring 00.00.0000
7446 \begin_inset LatexCommand \index{-\/-nooverlay}
7452 The compiler will not overlay parameters and local variables of any function,
7453 see section Parameters and local variables for more details.
7455 \labelwidthstring 00.00.0000
7470 \begin_inset LatexCommand \index{-\/-no-peep}
7476 Disable peep-hole optimization with built-in rules.
7478 \labelwidthstring 00.00.0000
7495 \begin_inset LatexCommand \index{-\/-peep-file}
7500 <filename> This option can be used to use additional rules to be used by
7501 the peep hole optimizer.
7503 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7508 Peep Hole optimizations for details on how to write these rules.
7510 \labelwidthstring 00.00.0000
7525 \begin_inset LatexCommand \index{-\/-peep-asm}
7531 Pass the inline assembler code through the peep hole optimizer.
7532 This can cause unexpected changes to inline assembler code, please go through
7533 the peephole optimizer
7534 \begin_inset LatexCommand \index{Peephole optimizer}
7538 rules defined in the source file tree '<target>/peeph.def' before using
7541 \labelwidthstring 00.00.0000
7556 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7562 The compiler will optimize code generation towards fast code, possibly
7563 at the expense of code size.
7565 \labelwidthstring 00.00.0000
7580 \begin_inset LatexCommand \index{-\/-opt-code-size}
7586 The compiler will optimize code generation towards compact code, possibly
7587 at the expense of code speed.
7591 \begin_inset LatexCommand \index{Options other}
7597 \labelwidthstring 00.00.0000
7613 \begin_inset LatexCommand \index{-\/-compile-only}
7618 \begin_inset LatexCommand \index{-c -\/-compile-only}
7624 will compile and assemble the source, but will not call the linkage editor.
7626 \labelwidthstring 00.00.0000
7645 \begin_inset LatexCommand \index{-\/-c1mode}
7651 reads the preprocessed source from standard input and compiles it.
7652 The file name for the assembler output must be specified using the -o option.
7654 \labelwidthstring 00.00.0000
7659 \begin_inset LatexCommand \index{-E}
7665 Run only the C preprocessor.
7666 Preprocess all the C source files specified and output the results to standard
7669 \labelwidthstring 00.00.0000
7675 \begin_inset LatexCommand \index{-o <path/file>}
7681 The output path resp.
7682 file where everything will be placed.
7683 If the parameter is a path, it must have a trailing slash (or backslash
7684 for the Windows binaries) to be recognized as a path.
7687 \labelwidthstring 00.00.0000
7702 \begin_inset LatexCommand \index{-\/-stack-auto}
7713 All functions in the source file will be compiled as
7718 \begin_inset LatexCommand \index{reentrant}
7723 the parameters and local variables will be allocated on the stack
7724 \begin_inset LatexCommand \index{stack}
7730 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7734 Parameters and Local Variables for more details.
7735 If this option is used all source files in the project should be compiled
7737 It automatically implies --int-long-reent and --float-reent.
7740 \labelwidthstring 00.00.0000
7755 \begin_inset LatexCommand \index{-\/-callee-saves}
7759 function1[,function2][,function3]....
7762 The compiler by default uses a caller saves convention for register saving
7763 across function calls, however this can cause unnecessary register pushing
7764 & popping when calling small functions from larger functions.
7765 This option can be used to switch the register saving convention for the
7766 function names specified.
7767 The compiler will not save registers when calling these functions, no extra
7768 code will be generated at the entry & exit (function prologue
7771 \begin_inset LatexCommand \index{function prologue}
7780 \begin_inset LatexCommand \index{function epilogue}
7786 ) for these functions to save & restore the registers used by these functions,
7787 this can SUBSTANTIALLY reduce code & improve run time performance of the
7789 In the future the compiler (with inter procedural analysis) will be able
7790 to determine the appropriate scheme to use for each function call.
7791 DO NOT use this option for built-in functions such as _mulint..., if this
7792 option is used for a library function the appropriate library function
7793 needs to be recompiled with the same option.
7794 If the project consists of multiple source files then all the source file
7795 should be compiled with the same -
7805 -callee-saves option string.
7806 Also see #pragma\SpecialChar ~
7808 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7814 \labelwidthstring 00.00.0000
7829 \begin_inset LatexCommand \index{-\/-debug}
7838 When this option is used the compiler will generate debug information.
7839 The debug information collected in a file with .cdb extension can be used
7841 For more information see documentation for SDCDB.
7842 Another file with no extension contains debug information in AOMF or AOMF51
7843 \begin_inset LatexCommand \index{AOMF, AOMF51}
7847 format which is commonly used by third party tools.
7849 \labelwidthstring 00.00.0000
7854 \begin_inset LatexCommand \index{-S}
7865 Stop after the stage of compilation proper; do not assemble.
7866 The output is an assembler code file for the input file specified.
7868 \labelwidthstring 00.00.0000
7883 \begin_inset LatexCommand \index{-\/-int-long-reent}
7889 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7890 Note by default these libraries are compiled as non-reentrant.
7891 See section Installation for more details.
7893 \labelwidthstring 00.00.0000
7908 \begin_inset LatexCommand \index{-\/-cyclomatic}
7917 This option will cause the compiler to generate an information message for
7918 each function in the source file.
7919 The message contains some
7923 information about the function.
7924 The number of edges and nodes the compiler detected in the control flow
7925 graph of the function, and most importantly the
7927 cyclomatic complexity
7928 \begin_inset LatexCommand \index{Cyclomatic complexity}
7934 see section on Cyclomatic Complexity for more details.
7936 \labelwidthstring 00.00.0000
7951 \begin_inset LatexCommand \index{-\/-float-reent}
7957 Floating point library is compiled as reentrant
7958 \begin_inset LatexCommand \index{reentrant}
7963 See section Installation for more details.
7965 \labelwidthstring 00.00.0000
7980 \begin_inset LatexCommand \index{-\/-main-return}
7986 This option can be used if the code generated is called by a monitor program
7987 or if the main routine includes an endless loop.
7988 This option might result in slightly smaller code and save two bytes of
7990 The return from the 'main'
7991 \begin_inset LatexCommand \index{main return}
7995 function will return to the function calling main.
7996 The default setting is to lock up i.e.
8003 \labelwidthstring 00.00.0000
8018 \begin_inset LatexCommand \index{-\/-nostdinc}
8024 This will prevent the compiler from passing on the default include path
8025 to the preprocessor.
8027 \labelwidthstring 00.00.0000
8042 \begin_inset LatexCommand \index{-\/-nostdlib}
8048 This will prevent the compiler from passing on the default library
8049 \begin_inset LatexCommand \index{Libraries}
8055 \labelwidthstring 00.00.0000
8070 \begin_inset LatexCommand \index{-\/-verbose}
8076 Shows the various actions the compiler is performing.
8078 \labelwidthstring 00.00.0000
8083 \begin_inset LatexCommand \index{-V}
8089 Shows the actual commands the compiler is executing.
8091 \labelwidthstring 00.00.0000
8106 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8112 Hides your ugly and inefficient c-code from the asm file, so you can always
8113 blame the compiler :)
8115 \labelwidthstring 00.00.0000
8130 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8136 Will not include peep-hole comments in the generated files.
8138 \labelwidthstring 00.00.0000
8153 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8159 Include i-codes in the asm file.
8160 Sounds like noise but is most helpful for debugging the compiler itself.
8162 \labelwidthstring 00.00.0000
8177 \begin_inset LatexCommand \index{-\/-less-pedantic}
8183 Disable some of the more pedantic warnings
8184 \begin_inset LatexCommand \index{Warnings}
8188 (jwk burps: please be more specific here, please!).
8190 \labelwidthstring 00.00.0000
8204 -disable-warning\SpecialChar ~
8206 \begin_inset LatexCommand \index{-\/-disable-warning}
8212 Disable specific warning with number <nnnn>.
8214 \labelwidthstring 00.00.0000
8229 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8235 Display the directories in the compiler's search path
8237 \labelwidthstring 00.00.0000
8252 \begin_inset LatexCommand \index{-\/-vc}
8258 Display errors and warnings using MSVC style, so you can use SDCC with
8261 \labelwidthstring 00.00.0000
8276 \begin_inset LatexCommand \index{-\/-use-stdout}
8282 Send errors and warnings to stdout instead of stderr.
8284 \labelwidthstring 00.00.0000
8289 asmOption[,asmOption]
8292 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8297 Pass the asmOption to the assembler
8298 \begin_inset LatexCommand \index{Options assembler}
8303 \begin_inset LatexCommand \index{Assembler options}
8308 See file sdcc/as/doc/asxhtm.html for assembler options.cd
8310 \labelwidthstring 00.00.0000
8325 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8331 Generally follow the C89 standard, but allow SDCC features that conflict
8332 with the standard (default).
8334 \labelwidthstring 00.00.0000
8349 \begin_inset LatexCommand \index{-\/-std-c89}
8355 Follow the C89 standard and disable SDCC features that conflict with the
8358 \labelwidthstring 00.00.0000
8373 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8379 Generally follow the C99 standard, but allow SDCC features that conflict
8380 with the standard (incomplete support).
8382 \labelwidthstring 00.00.0000
8397 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8403 Follow the C99 standard and disable SDCC features that conflict with the
8404 standard (incomplete support).
8406 \labelwidthstring 00.00.0000
8423 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8428 <Name> The name to be used for the code
8429 \begin_inset LatexCommand \index{code}
8433 segment, default CSEG.
8434 This is useful if you need to tell the compiler to put the code in a special
8435 segment so you can later on tell the linker to put this segment in a special
8437 Can be used for instance when using bank switching to put the code in a
8440 \labelwidthstring 00.00.0000
8457 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8462 <Name> The name to be used for the const
8463 \begin_inset LatexCommand \index{code}
8467 segment, default CONST.
8468 This is useful if you need to tell the compiler to put the const data in
8469 a special segment so you can later on tell the linker to put this segment
8470 in a special place in memory.
8471 Can be used for instance when using bank switching to put the const data
8474 \labelwidthstring 00.00.0000
8486 a SDCC compiler option but if you want
8490 warnings you can use a separate tool dedicated to syntax checking like
8492 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8497 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8502 \begin_inset LatexCommand \url{http://www.splint.org}
8507 To make your source files parseable by splint you will have to include
8513 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8517 in your source file and add brackets around extended keywords (like
8520 \begin_inset Quotes sld
8533 \begin_inset Quotes srd
8541 \begin_inset Quotes sld
8544 __interrupt\SpecialChar ~
8546 \begin_inset Quotes srd
8554 Splint has an excellent on line manual at
8555 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8559 and it's capabilities go beyond pure syntax checking.
8560 You'll need to tell splint the location of SDCC's include files so a typical
8561 command line could look like this:
8565 splint\SpecialChar ~
8567 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8572 Intermediate Dump Options
8573 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8578 \begin_inset LatexCommand \index{Options intermediate dump}
8583 \begin_inset LatexCommand \index{Intermediate dump options}
8590 The following options are provided for the purpose of retargetting and debugging
8592 They provide a means to dump the intermediate code (iCode
8593 \begin_inset LatexCommand \index{iCode}
8597 ) generated by the compiler in human readable form at various stages of
8598 the compilation process.
8599 More on iCodes see chapter
8600 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8605 \begin_inset Quotes srd
8608 The anatomy of the compiler
8609 \begin_inset Quotes srd
8614 \labelwidthstring 00.00.0000
8629 \begin_inset LatexCommand \index{-\/-dumpraw}
8635 This option will cause the compiler to dump the intermediate code into
8638 <source filename>.dumpraw
8640 just after the intermediate code has been generated for a function, i.e.
8641 before any optimizations are done.
8643 \begin_inset LatexCommand \index{Basic blocks}
8647 at this stage ordered in the depth first number, so they may not be in
8648 sequence of execution.
8650 \labelwidthstring 00.00.0000
8665 \begin_inset LatexCommand \index{-\/-dumpgcse}
8671 Will create a dump of iCode's, after global subexpression elimination
8672 \begin_inset LatexCommand \index{Global subexpression elimination}
8678 <source filename>.dumpgcse.
8680 \labelwidthstring 00.00.0000
8695 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8701 Will create a dump of iCode's, after deadcode elimination
8702 \begin_inset LatexCommand \index{Dead-code elimination}
8708 <source filename>.dumpdeadcode.
8710 \labelwidthstring 00.00.0000
8725 \begin_inset LatexCommand \index{-\/-dumploop}
8734 Will create a dump of iCode's, after loop optimizations
8735 \begin_inset LatexCommand \index{Loop optimization}
8741 <source filename>.dumploop.
8743 \labelwidthstring 00.00.0000
8758 \begin_inset LatexCommand \index{-\/-dumprange}
8767 Will create a dump of iCode's, after live range analysis
8768 \begin_inset LatexCommand \index{Live range analysis}
8774 <source filename>.dumprange.
8776 \labelwidthstring 00.00.0000
8791 \begin_inset LatexCommand \index{-\/-dumlrange}
8797 Will dump the life ranges
8798 \begin_inset LatexCommand \index{Live range analysis}
8804 \labelwidthstring 00.00.0000
8819 \begin_inset LatexCommand \index{-\/-dumpregassign}
8828 Will create a dump of iCode's, after register assignment
8829 \begin_inset LatexCommand \index{Register assignment}
8835 <source filename>.dumprassgn.
8837 \labelwidthstring 00.00.0000
8852 \begin_inset LatexCommand \index{-\/-dumplrange}
8858 Will create a dump of the live ranges of iTemp's
8860 \labelwidthstring 00.00.0000
8875 \begin_inset LatexCommand \index{-\/-dumpall}
8886 Will cause all the above mentioned dumps to be created.
8889 Redirecting output on Windows Shells
8892 By default SDCC writes it's error messages to
8893 \begin_inset Quotes sld
8897 \begin_inset Quotes srd
8901 To force all messages to
8902 \begin_inset Quotes sld
8906 \begin_inset Quotes srd
8930 \begin_inset LatexCommand \index{-\/-use-stdout}
8935 Additionally, if you happen to have visual studio installed in your windows
8936 machine, you can use it to compile your sources using a custom build and
8952 \begin_inset LatexCommand \index{-\/-vc}
8957 Something like this should work:
9001 -model-large -c $(InputPath)
9004 Environment variables
9005 \begin_inset LatexCommand \index{Environment variables}
9012 SDCC recognizes the following environment variables:
9014 \labelwidthstring 00.00.0000
9019 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9025 SDCC installs a signal handler
9026 \begin_inset LatexCommand \index{signal handler}
9030 to be able to delete temporary files after an user break (^C) or an exception.
9031 If this environment variable is set, SDCC won't install the signal handler
9032 in order to be able to debug SDCC.
9034 \labelwidthstring 00.00.0000
9041 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9047 Path, where temporary files will be created.
9048 The order of the variables is the search order.
9049 In a standard *nix environment these variables are not set, and there's
9050 no need to set them.
9051 On Windows it's recommended to set one of them.
9053 \labelwidthstring 00.00.0000
9058 \begin_inset LatexCommand \index{SDCC\_HOME}
9065 \begin_inset LatexCommand \ref{sub:Install-paths}
9071 \begin_inset Quotes sld
9075 \begin_inset Quotes srd
9080 \labelwidthstring 00.00.0000
9085 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9092 \begin_inset LatexCommand \ref{sub:Search-Paths}
9098 \begin_inset Quotes sld
9102 \begin_inset Quotes srd
9107 \labelwidthstring 00.00.0000
9112 \begin_inset LatexCommand \index{SDCC\_LIB}
9119 \begin_inset LatexCommand \ref{sub:Search-Paths}
9125 \begin_inset Quotes sld
9129 \begin_inset Quotes srd
9135 There are some more environment variables recognized by SDCC, but these
9136 are solely used for debugging purposes.
9137 They can change or disappear very quickly, and will never be documented.
9140 Storage Class Language Extensions
9143 MCS51/DS390 Storage Class
9144 \begin_inset LatexCommand \index{Storage class}
9151 In addition to the ANSI storage classes SDCC allows the following MCS51
9152 specific storage classes:
9153 \layout Subsubsection
9156 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9161 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9166 \begin_inset LatexCommand \index{near (storage class)}
9171 \begin_inset LatexCommand \index{\_\_near (storage class)}
9182 storage class for the Small Memory model (
9190 or the more ANSI-C compliant forms
9198 can be used synonymously).
9199 Variables declared with this storage class will be allocated in the directly
9200 addressable portion of the internal RAM of a 8051, e.g.:
9205 __data unsigned char test_data;
9208 Writing 0x01 to this variable generates the assembly code:
9213 75*00 01\SpecialChar ~
9219 \layout Subsubsection
9222 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9227 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9232 \begin_inset LatexCommand \index{far (storage class)}
9237 \begin_inset LatexCommand \index{\_\_far (storage class)}
9244 Variables declared with this storage class will be placed in the external
9250 storage class for the Large Memory model, e.g.:
9255 __xdata unsigned char test_xdata;
9258 Writing 0x01 to this variable generates the assembly code:
9263 90s00r00\SpecialChar ~
9292 \layout Subsubsection
9295 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9300 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9307 Variables declared with this storage class will be allocated into the indirectly
9308 addressable portion of the internal ram of a 8051, e.g.:
9313 __idata unsigned char test_idata;
9316 Writing 0x01 to this variable generates the assembly code:
9345 Please note, the first 128 byte of idata physically access the same RAM
9347 The original 8051 had 128 byte idata memory, nowadays most devices have
9348 256 byte idata memory.
9350 \begin_inset LatexCommand \index{stack}
9354 is located in idata memory.
9355 \layout Subsubsection
9358 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9363 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9370 Paged xdata access is just as straightforward as using the other addressing
9372 It is typically located at the start of xdata and has a maximum size of
9374 The following example writes 0x01 to the pdata variable.
9375 Please note, pdata access physically accesses xdata memory.
9376 The high byte of the address is determined by port P2
9377 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9381 (or in case of some 8051 variants by a separate Special Function Register,
9383 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9392 storage class for the Medium Memory model, e.g.:
9397 __pdata unsigned char test_pdata;
9400 Writing 0x01 to this variable generates the assembly code:
9444 \begin_inset LatexCommand \index{-\/-xstack}
9448 option is used the pdata memory area is followed by the xstack memory area
9449 and the sum of their sizes is limited to 256 bytes.
9450 \layout Subsubsection
9453 \begin_inset LatexCommand \index{code}
9458 \begin_inset LatexCommand \index{\_\_code}
9465 'Variables' declared with this storage class will be placed in the code
9471 __code unsigned char test_code;
9474 Read access to this variable generates the assembly code:
9479 90s00r6F\SpecialChar ~
9482 mov dptr,#_test_code
9511 indexed arrays of characters in code memory can be accessed efficiently:
9516 __code char test_array[] = {'c','h','e','a','p'};
9519 Read access to this array using an 8-bit unsigned index generates the assembly
9536 90s00r41\SpecialChar ~
9539 mov dptr,#_test_array
9554 \layout Subsubsection
9557 \begin_inset LatexCommand \index{bit}
9562 \begin_inset LatexCommand \index{\_\_bit}
9569 This is a data-type and a storage class specifier.
9570 When a variable is declared as a bit, it is allocated into the bit addressable
9571 memory of 8051, e.g.:
9579 Writing 1 to this variable generates the assembly code:
9595 The bit addressable memory consists of 128 bits which are located from 0x20
9596 to 0x2f in data memory.
9599 Apart from this 8051 specific storage class most architectures support ANSI-C
9601 \begin_inset LatexCommand \index{bitfields}
9611 Not really meant as examples, but nevertheless showing what bitfields are
9612 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9616 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9617 signed modifier are implemented as unsigned.
9618 \layout Subsubsection
9621 \begin_inset LatexCommand \index{sfr}
9626 \begin_inset LatexCommand \index{\_\_sfr}
9631 \begin_inset LatexCommand \index{sfr16}
9636 \begin_inset LatexCommand \index{\_\_sfr16}
9641 \begin_inset LatexCommand \index{sfr32}
9646 \begin_inset LatexCommand \index{\_\_sfr32}
9651 \begin_inset LatexCommand \index{\_\_sbit}
9658 Like the bit keyword,
9660 sfr / sfr16 / sfr32 / sbit
9662 signify both a data-type and storage class, they are used to describe the
9683 variables of a 8051, eg:
9689 \begin_inset LatexCommand \index{at}
9694 \begin_inset LatexCommand \index{\_\_at}
9698 (0x80) P0;\SpecialChar ~
9699 /* special function register P0 at location 0x80 */
9701 /* 16 bit special function register combination for timer 0 */
9703 /* with the high byte at location 0x8C and the low byte at location 0x8A
9707 \begin_inset LatexCommand \index{at}
9712 \begin_inset LatexCommand \index{\_\_at}
9718 __sbit __at (0xd7) CY; /* CY (Carry Flag
9719 \begin_inset LatexCommand \index{Flags}
9724 \begin_inset LatexCommand \index{Carry flag}
9731 Special function registers which are located on an address dividable by
9732 8 are bit-addressable, an
9736 addresses a specific bit within these sfr.
9738 16 Bit and 32 bit special function register combinations which require a
9739 certain access order are better not declared using
9748 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9749 this is not guaranteed.
9750 \layout Subsubsection
9753 \begin_inset LatexCommand \index{Pointer}
9757 to MCS51/DS390 specific memory spaces
9760 SDCC allows (via language extensions) pointers to explicitly point to any
9761 of the memory spaces
9762 \begin_inset LatexCommand \index{Memory model}
9767 In addition to the explicit pointers, the compiler uses (by default) generic
9768 pointers which can be used to point to any of the memory spaces.
9772 Pointer declaration examples:
9777 /* pointer physically in internal ram pointing to object in external ram
9780 __xdata unsigned char * __data p;
9784 /* pointer physically in external ram pointing to object in internal ram
9787 __data unsigned char * __xdata p;
9791 /* pointer physically in code rom pointing to data in xdata space */
9793 __xdata unsigned char * __code p;
9797 /* pointer physically in code space pointing to data in code space */
9799 __code unsigned char * __code p;
9803 /* the following is a generic pointer physically located in xdata space
9810 /* the following is a function pointer physically located in data space
9813 char (* __data fp)(void);
9816 Well you get the idea.
9821 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
9834 The highest order byte of the
9838 pointers contains the data space information.
9839 Assembler support routines are called whenever data is stored or retrieved
9845 These are useful for developing reusable library
9846 \begin_inset LatexCommand \index{Libraries}
9851 Explicitly specifying the pointer type will generate the most efficient
9853 \layout Subsubsection
9855 Notes on MCS51 memory
9856 \begin_inset LatexCommand \index{MCS51 memory}
9863 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9864 RAM memory which is structured as follows:
9868 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9871 - Bytes 20-2F - 16 bytes to hold 128 bit
9872 \begin_inset LatexCommand \index{bit}
9878 - Bytes 30-7F - 80 bytes for general purpose use.
9883 Additionally some members of the MCS51 family may have up to 128 bytes of
9884 additional, indirectly addressable, internal RAM memory (
9889 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9894 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9899 Furthermore, some chips may have some built in external memory (
9904 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9909 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9913 ) which should not be confused with the internal, directly addressable RAM
9919 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9924 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9929 Sometimes this built in
9933 memory has to be activated before using it (you can probably find this
9934 information on the datasheet of the microcontroller your are using, see
9936 \begin_inset LatexCommand \ref{sub:Startup-Code}
9944 Normally SDCC will only use the first bank
9945 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9949 of registers (register bank 0), but it is possible to specify that other
9950 banks of registers (keyword
9957 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9962 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9968 ) should be used in interrupt
9969 \begin_inset LatexCommand \index{interrupt}
9974 \begin_inset LatexCommand \index{\_\_interrupt}
9979 By default, the compiler will place the stack after the last byte of allocated
9980 memory for variables.
9981 For example, if the first 2 banks of registers are used, and only four
9986 variables, it will position the base of the internal stack at address 20
9988 This implies that as the stack
9989 \begin_inset LatexCommand \index{stack}
9993 grows, it will use up the remaining register banks, and the 16 bytes used
9994 by the 128 bit variables, and 80 bytes for general purpose use.
9995 If any bit variables are used, the data variables will be placed in unused
9996 register banks and after the byte holding the last bit variable.
9997 For example, if register banks 0 and 1 are used, and there are 9 bit variables
10002 variables will be placed starting from address 0x10 to 0x20 and continue
10015 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10019 to specify the start address of the
10034 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10038 to specify the size of the total internal RAM (
10052 By default the 8051 linker will place the stack after the last byte of (i)data
10065 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10069 allows you to specify the start of the stack, i.e.
10070 you could start it after any data in the general purpose area.
10071 If your microcontroller has additional indirectly addressable internal
10076 ) you can place the stack on it.
10077 You may also need to use -
10088 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10092 to set the start address of the external RAM (
10107 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10111 to specify its size.
10112 Same goes for the code memory, using -
10123 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10138 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10143 If in doubt, don't specify any options and see if the resulting memory
10144 layout is appropriate, then you can adjust it.
10147 The linker generates two files with memory allocation information.
10148 The first, with extension .map
10149 \begin_inset LatexCommand \index{<file>.map}
10153 shows all the variables and segments.
10154 The second with extension .mem
10155 \begin_inset LatexCommand \index{<file>.mem}
10159 shows the final memory layout.
10160 The linker will complain either if memory segments overlap, there is not
10161 enough memory, or there is not enough space for stack.
10162 If you get any linking warnings and/or errors related to stack or segments
10163 allocation, take a look at either the .map or .mem files to find out what
10165 The .mem file may even suggest a solution to the problem.
10168 Z80/Z180 Storage Class
10169 \begin_inset LatexCommand \index{Storage class}
10173 Language Extensions
10174 \layout Subsubsection
10177 \begin_inset LatexCommand \index{sfr}
10182 \begin_inset LatexCommand \index{\_\_sfr}
10186 (in/out to 8-bit addresses)
10190 \begin_inset LatexCommand \index{Z80}
10194 family has separate address spaces for memory and
10204 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10208 is accessed with special instructions, e.g.:
10213 sfr at 0x78 IoPort;\SpecialChar ~
10215 /* define a var in I/O space at 78h called IoPort */
10219 Writing 0x01 to this variable generates the assembly code:
10224 3E 01\SpecialChar ~
10232 D3 78\SpecialChar ~
10239 \layout Subsubsection
10242 \begin_inset LatexCommand \index{sfr}
10247 \begin_inset LatexCommand \index{\_\_sfr}
10251 (in/out to 16-bit addresses)
10258 is used to support 16 bit addresses in I/O memory e.g.:
10264 \begin_inset LatexCommand \index{at}
10269 \begin_inset LatexCommand \index{\_\_at}
10276 Writing 0x01 to this variable generates the assembly code:
10281 01 23 01\SpecialChar ~
10286 3E 01\SpecialChar ~
10294 ED 79\SpecialChar ~
10301 \layout Subsubsection
10304 \begin_inset LatexCommand \index{sfr}
10309 \begin_inset LatexCommand \index{\_\_sfr}
10313 (in0/out0 to 8 bit addresses on Z180
10314 \begin_inset LatexCommand \index{Z180}
10319 \begin_inset LatexCommand \index{HD64180}
10326 The compiler option -
10336 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
10338 \begin_inset LatexCommand \index{\#pragma portmode}
10342 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10352 If you include the file z180.h this will be set automatically.
10356 \begin_inset LatexCommand \index{Storage class}
10360 Language Extensions
10361 \layout Subsubsection
10364 \begin_inset LatexCommand \index{data (hc08 storage class)}
10369 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10376 The data storage class declares a variable that resides in the first 256
10377 bytes of memory (the direct page).
10378 The HC08 is most efficient at accessing variables (especially pointers)
10380 \layout Subsubsection
10383 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10388 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10395 The xdata storage class declares a variable that can reside anywhere in
10397 This is the default if no storage class is specified.
10401 Absolute Addressing
10402 \begin_inset LatexCommand \index{Absolute addressing}
10409 Data items can be assigned an absolute address with the
10412 \begin_inset LatexCommand \index{at}
10417 \begin_inset LatexCommand \index{\_\_at}
10423 keyword, in addition to a storage class, e.g.:
10429 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10434 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10439 \begin_inset LatexCommand \index{at}
10444 \begin_inset LatexCommand \index{\_\_at}
10448 (0x7ffe) unsigned int chksum;
10456 __xdata __at (0x7ffe) unsigned int chksum;
10459 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10460 of the external ram.
10465 reserve any space for variables declared in this way
10466 \begin_inset Marginal
10476 (they are implemented with an equate in the assembler).
10477 Thus it is left to the programmer to make sure there are no overlaps with
10478 other variables that are declared without the absolute address.
10479 The assembler listing file (.lst
10480 \begin_inset LatexCommand \index{<file>.lst}
10484 ) and the linker output files (.rst
10485 \begin_inset LatexCommand \index{<file>.rst}
10490 \begin_inset LatexCommand \index{<file>.map}
10494 ) are good places to look for such overlaps.
10495 Variables with an absolute address are
10498 \begin_inset Marginal
10511 \begin_inset LatexCommand \index{Variable initialization}
10518 In case of memory mapped I/O devices the keyword
10522 has to be used to tell the compiler that accesses might not be removed:
10528 \begin_inset LatexCommand \index{volatile}
10533 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10538 \begin_inset LatexCommand \index{at}
10542 (0x8000) unsigned char PORTA_8255;
10545 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
10550 \begin_inset LatexCommand \index{Aligned array}
10557 starts at a block (256 byte) boundary
10558 \begin_inset LatexCommand \index{block boundary}
10563 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10569 Absolute addresses can be specified for variables in all storage classes,
10576 \begin_inset LatexCommand \index{bit}
10581 \begin_inset LatexCommand \index{at}
10588 The above example will allocate the variable at offset 0x02 in the bit-addressab
10590 There is no real advantage to assigning absolute addresses to variables
10591 in this manner, unless you want strict control over all the variables allocated.
10592 One possible use would be to write hardware portable code.
10593 For example, if you have a routine that uses one or more of the microcontroller
10594 I/O pins, and such pins are different for two different hardwares, you
10595 can declare the I/O pins in your routine using:
10601 \begin_inset LatexCommand \index{volatile}
10605 bit MOSI;\SpecialChar ~
10609 /* master out, slave in */
10611 extern volatile bit MISO;\SpecialChar ~
10615 /* master in, slave out */
10617 extern volatile bit MCLK;\SpecialChar ~
10625 /* Input and Output of a byte on a 3-wire serial bus.
10630 If needed adapt polarity of clock, polarity of data and bit order
10635 unsigned char spi_io(unsigned char out_byte)
10659 MOSI = out_byte & 0x80;
10689 /* _asm nop _endasm; */\SpecialChar ~
10697 /* for slow peripherals */
10748 Then, someplace in the code for the first hardware you would use
10754 \begin_inset LatexCommand \index{at}
10759 \begin_inset LatexCommand \index{\_\_at}
10763 (0x80) MOSI;\SpecialChar ~
10767 /* I/O port 0, bit 0 */
10769 bit __at (0x81) MISO;\SpecialChar ~
10773 /* I/O port 0, bit 1 */
10775 bit __at (0x82) MCLK;\SpecialChar ~
10779 /* I/O port 0, bit 2 */
10782 Similarly, for the second hardware you would use
10787 bit __at (0x83) MOSI;\SpecialChar ~
10791 /* I/O port 0, bit 3 */
10793 bit __at (0x91) MISO;\SpecialChar ~
10797 /* I/O port 1, bit 1 */
10800 \begin_inset LatexCommand \index{bit}
10804 __at (0x92) MCLK;\SpecialChar ~
10808 /* I/O port 1, bit 2 */
10811 and you can use the same hardware dependent routine without changes, as
10812 for example in a library.
10813 This is somehow similar to sbit, but only one absolute address has to be
10814 specified in the whole project.
10818 \begin_inset LatexCommand \index{Parameters}
10823 \begin_inset LatexCommand \index{function parameter}
10828 \begin_inset LatexCommand \index{local variables}
10833 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
10840 Automatic (local) variables and parameters to functions can either be placed
10841 on the stack or in data-space.
10842 The default action of the compiler is to place these variables in the internal
10843 RAM (for small model) or external RAM (for large model).
10844 This in fact makes them similar to
10847 \begin_inset LatexCommand \index{static}
10853 so by default functions are non-reentrant
10854 \begin_inset LatexCommand \index{reentrant}
10863 They can be placed on the stack
10864 \begin_inset LatexCommand \index{stack}
10881 \begin_inset LatexCommand \index{-\/-stack-auto}
10889 #pragma\SpecialChar ~
10893 \begin_inset LatexCommand \index{\#pragma stackauto}
10900 \begin_inset LatexCommand \index{reentrant}
10906 keyword in the function declaration, e.g.:
10911 unsigned char foo(char i) __reentrant
10925 Since stack space on 8051 is limited, the
10943 option should be used sparingly.
10944 Note that the reentrant keyword just means that the parameters & local
10945 variables will be allocated to the stack, it
10949 mean that the function is register bank
10950 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10959 \begin_inset LatexCommand \index{local variables}
10963 can be assigned storage classes and absolute
10964 \begin_inset LatexCommand \index{Absolute addressing}
10973 unsigned char foo()
10981 xdata unsigned char i;
10994 \begin_inset LatexCommand \index{at}
10998 (0x31) unsigned char j;
11010 In the above example the variable
11014 will be allocated in the external ram,
11018 in bit addressable space and
11037 or when a function is declared as
11041 this should only be done for static variables.
11045 \begin_inset LatexCommand \index{function parameter}
11049 however are not allowed any storage class
11050 \begin_inset LatexCommand \index{Storage class}
11054 , (storage classes for parameters will be ignored), their allocation is
11055 governed by the memory model in use, and the reentrancy options.
11058 It is however allowed to use bit parameters in reentrant functions and also
11059 non-static local bit variables are supported.
11060 Efficient use is limited to 8 semi-bitregisters in bit space.
11061 They are pushed and popped to stack as a single byte just like the normal
11066 \begin_inset LatexCommand \label{sub:Overlaying}
11071 \begin_inset LatexCommand \index{Overlaying}
11079 \begin_inset LatexCommand \index{reentrant}
11083 functions SDCC will try to reduce internal ram space usage by overlaying
11084 parameters and local variables of a function (if possible).
11085 Parameters and local variables
11086 \begin_inset LatexCommand \index{local variables}
11090 of a function will be allocated to an overlayable segment if the function
11093 no other function calls and the function is non-reentrant and the memory
11095 \begin_inset LatexCommand \index{Memory model}
11102 If an explicit storage class
11103 \begin_inset LatexCommand \index{Storage class}
11107 is specified for a local variable, it will NOT be overlayed.
11110 Note that the compiler (not the linkage editor) makes the decision for overlayin
11112 Functions that are called from an interrupt service routine
11113 \begin_inset Marginal
11123 should be preceded by a #pragma\SpecialChar ~
11125 \begin_inset LatexCommand \index{\#pragma nooverlay}
11129 if they are not reentrant.
11132 Also note that the compiler does not do any processing of inline assembler
11133 code, so the compiler might incorrectly assign local variables and parameters
11134 of a function into the overlay segment if the inline assembler code calls
11135 other c-functions that might use the overlay.
11136 In that case the #pragma\SpecialChar ~
11137 nooverlay should be used.
11140 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11142 \begin_inset LatexCommand \index{Multiplication}
11147 \begin_inset LatexCommand \index{Division}
11151 will NOT be overlayed since these are implemented using external functions,
11160 \begin_inset LatexCommand \index{\#pragma nooverlay}
11166 void set_error(unsigned char errcd)
11182 void some_isr () __interrupt
11183 \begin_inset LatexCommand \index{interrupt}
11213 In the above example the parameter
11221 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11223 not present, this could cause unpredictable runtime behavior when called
11224 from an interrupt service routine.
11225 The #pragma\SpecialChar ~
11226 nooverlay ensures that the parameters and local variables for
11227 the function are NOT overlayed.
11230 Interrupt Service Routines
11231 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11238 General Information
11253 outines to be coded in C, with some extended keywords.
11258 void timer_isr (void) __interrupt (1) __using (1)
11272 The optional number following the
11275 \begin_inset LatexCommand \index{interrupt}
11280 \begin_inset LatexCommand \index{\_\_interrupt}
11286 keyword is the interrupt number this routine will service.
11287 When present, the compiler will insert a call to this routine in the interrupt
11288 vector table for the interrupt number specified.
11289 If you have multiple source files in your project, interrupt service routines
11290 can be present in any of them, but a prototype of the isr MUST be present
11291 or included in the file that contains the function
11299 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11304 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11310 keyword can be used to tell the compiler to use the specified register
11311 bank (8051 specific) when generating code for this function.
11317 Interrupt service routines open the door for some very interesting bugs:
11319 If an interrupt service routine changes variables which are accessed by
11320 other functions these variables have to be declared
11325 \begin_inset LatexCommand \index{volatile}
11333 If the access to these variables is not
11336 \begin_inset LatexCommand \index{atomic}
11343 the processor needs more than one instruction for the access and could
11344 be interrupted while accessing the variable) the interrupt must be disabled
11345 during the access to avoid inconsistent data.
11346 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
11347 and should be protected by disabling interrupts.
11348 You're not automatically on the safe side if you use 8 bit variables though.
11349 We need an example here: f.e.
11350 on the 8051 the harmless looking
11351 \begin_inset Quotes srd
11356 flags\SpecialChar ~
11361 \begin_inset Quotes sld
11370 \begin_inset Quotes srd
11375 flags\SpecialChar ~
11380 \begin_inset Quotes sld
11383 from within an interrupt routine might get lost if the interrupt occurs
11386 \begin_inset Quotes sld
11391 counter\SpecialChar ~
11396 \begin_inset Quotes srd
11399 is not atomic on the 8051 even if
11403 is located in data memory.
11404 Bugs like these are hard to reproduce and can cause a lot of trouble.
11408 The return address and the registers used in the interrupt service routine
11409 are saved on the stack
11410 \begin_inset LatexCommand \index{stack}
11414 so there must be sufficient stack space.
11415 If there isn't variables or registers (or even the return address itself)
11422 \begin_inset LatexCommand \index{stack overflow}
11426 is most likely to happen if the interrupt occurs during the
11427 \begin_inset Quotes sld
11431 \begin_inset Quotes srd
11434 subroutine when the stack is already in use for f.e.
11435 many return addresses.
11438 A special note here, int (16 bit) and long (32 bit) integer division
11439 \begin_inset LatexCommand \index{Division}
11444 \begin_inset LatexCommand \index{Multiplication}
11449 \begin_inset LatexCommand \index{Modulus}
11454 \begin_inset LatexCommand \index{Floating point support}
11458 operations are implemented using external support routines developed in
11460 If an interrupt service routine needs to do any of these operations then
11461 the support routines (as mentioned in a following section) will have to
11462 be recompiled using the
11475 \begin_inset LatexCommand \index{-\/-stack-auto}
11481 option and the source file will need to be compiled using the
11496 \begin_inset LatexCommand \index{-\/-int-long-reent}
11501 Note, the type promotion
11502 \begin_inset LatexCommand \index{type promotion}
11506 required by ANSI C can cause 16 bit routines to be used without the programmer
11511 Calling other functions from an interrupt service routine is not recommended,
11512 avoid it if possible.
11513 Note that when some function is called from an interrupt service routine
11514 it should be preceded by a #pragma\SpecialChar ~
11516 \begin_inset LatexCommand \index{\#pragma nooverlay}
11520 if it is not reentrant.
11521 Furthermore nonreentrant functions should not be called from the main program
11522 while the interrupt service routine might be active.
11523 They also must not be called from low priority interrupt service routines
11524 while a high priority interrupt service routine might be active.
11525 You could use semaphores or make the function
11529 if all parameters are passed in registers.
11534 \begin_inset LatexCommand \ref{sub:Overlaying}
11539 about Overlaying and section
11540 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
11545 about Functions using private register banks.
11548 MCS51/DS390 Interrupt Service Routines
11551 Interrupt numbers and the corresponding address & descriptions for the Standard
11552 8051/8052 are listed below.
11553 SDCC will automatically adjust the interrupt vector table to the maximum
11554 interrupt number specified.
11560 \begin_inset Tabular
11561 <lyxtabular version="3" rows="9" columns="3">
11563 <column alignment="center" valignment="top" leftline="true" width="0in">
11564 <column alignment="left" valignment="top" leftline="true" width="0in">
11565 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
11566 <row topline="true" bottomline="true">
11567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11592 <row topline="true">
11593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11618 <row topline="true">
11619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11644 <row topline="true">
11645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11670 <row topline="true">
11671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11696 <row topline="true">
11697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11722 <row topline="true">
11723 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11748 <row topline="true">
11749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11773 <row topline="true" bottomline="true">
11774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11807 If the interrupt service routine is defined without
11810 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11815 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11821 a register bank or with register bank 0 (
11825 0), the compiler will save the registers used by itself on the stack upon
11826 entry and restore them at exit, however if such an interrupt service routine
11827 calls another function then the entire register bank will be saved on the
11829 This scheme may be advantageous for small interrupt service routines which
11830 have low register usage.
11833 If the interrupt service routine is defined to be using a specific register
11838 & psw are saved and restored, if such an interrupt service routine calls
11839 another function (using another register bank) then the entire register
11840 bank of the called function will be saved on the stack.
11841 This scheme is recommended for larger interrupt service routines.
11844 HC08 Interrupt Service Routines
11847 Since the number of interrupts available is chip specific and the interrupt
11848 vector table always ends at the last byte of memory, the interrupt numbers
11849 corresponds to the interrupt vectors in reverse order of address.
11850 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
11851 2 will use the interrupt vector at 0xfffa, and so on.
11852 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
11853 this way; instead see section
11854 \begin_inset LatexCommand \ref{sub:Startup-Code}
11858 for details on customizing startup.
11861 Z80 Interrupt Service Routines
11864 The Z80 uses several different methods for determining the correct interrupt
11865 vector depending on the hardware implementation.
11866 Therefore, SDCC ignores the optional interrupt number and does not attempt
11867 to generate an interrupt vector table.
11870 By default, SDCC generates code for a maskable interrupt, which uses a RETI
11871 instruction to return from the interrupt.
11872 To write an interrupt handler for the non-maskable interrupt, which needs
11873 a RETN instruction instead, add the
11882 void nmi_isr (void) critical interrupt
11896 However if you need to create a non-interruptable interrupt service routine
11897 you would also require the
11902 To distinguish between this and an nmi_isr you must provide an interrupt
11906 Enabling and Disabling Interrupts
11909 Critical Functions and Critical Statements
11912 A special keyword may be associated with a block or a function declaring
11918 SDCC will generate code to disable all interrupts
11919 \begin_inset LatexCommand \index{interrupt}
11923 upon entry to a critical function and restore the interrupt enable to the
11924 previous state before returning.
11925 Nesting critical functions will need one additional byte on the stack
11926 \begin_inset LatexCommand \index{stack}
11935 int foo () __critical
11936 \begin_inset LatexCommand \index{critical}
11941 \begin_inset LatexCommand \index{\_\_critical}
11966 The critical attribute maybe used with other attributes like
11976 may also be used to disable interrupts more locally:
11984 More than one statement could have been included in the block.
11987 Enabling and Disabling Interrupts directly
11991 \begin_inset LatexCommand \index{interrupt}
11995 can also be disabled and enabled directly (8051):
12000 EA = 0;\SpecialChar ~
12063 EA = 1;\SpecialChar ~
12130 On other architectures which have seperate opcodes for enabling and disabling
12131 interrupts you might want to make use of defines with inline assembly
12132 \begin_inset LatexCommand \index{Assembler routines}
12142 \begin_inset LatexCommand \index{\_asm}
12151 \begin_inset LatexCommand \index{\_endasm}
12160 #define SEI _asm\SpecialChar ~
12172 Note: it is sometimes sufficient to disable only a specific interrupt source
12174 a timer or serial interrupt by manipulating an
12177 \begin_inset LatexCommand \index{interrupt mask}
12187 Usually the time during which interrupts are disabled should be kept as
12189 This minimizes both
12194 \begin_inset LatexCommand \index{interrupt latency}
12198 (the time between the occurrence of the interrupt and the execution of
12199 the first code in the interrupt routine) and
12204 \begin_inset LatexCommand \index{interrupt jitter}
12208 (the difference between the shortest and the longest interrupt latency).
12209 These really are something different, f.e.
12210 a serial interrupt has to be served before its buffer overruns so it cares
12211 for the maximum interrupt latency, whereas it does not care about jitter.
12212 On a loudspeaker driven via a digital to analog converter which is fed
12213 by an interrupt a latency of a few milliseconds might be tolerable, whereas
12214 a much smaller jitter will be very audible.
12217 You can reenable interrupts within an interrupt routine and on some architecture
12218 s you can make use of two (or more) levels of
12220 interrupt priorities
12223 \begin_inset LatexCommand \index{interrupt priority}
12228 On some architectures which don't support interrupt priorities these can
12229 be implemented by manipulating the interrupt mask and reenabling interrupts
12230 within the interrupt routine.
12231 Check there is sufficient space on the stack
12232 \begin_inset LatexCommand \index{stack}
12236 and don't add complexity unless you have to.
12241 \begin_inset LatexCommand \index{semaphore}
12245 locking (mcs51/ds390)
12248 Some architectures (mcs51/ds390) have an atomic
12249 \begin_inset LatexCommand \index{atomic}
12262 These type of instructions are typically used in preemptive multitasking
12263 systems, where a routine f.e.
12264 claims the use of a data structure ('acquires a lock
12265 \begin_inset LatexCommand \index{lock}
12269 on it'), makes some modifications and then releases the lock when the data
12270 structure is consistent again.
12271 The instruction may also be used if interrupt and non-interrupt code have
12272 to compete for a resource.
12273 With the atomic bit test and clear instruction interrupts
12274 \begin_inset LatexCommand \index{interrupt}
12278 don't have to be disabled for the locking operation.
12282 SDCC generates this instruction if the source follows this pattern:
12288 \begin_inset LatexCommand \index{volatile}
12292 bit resource_is_free;
12296 if (resource_is_free)
12306 resource_is_free=0;
12319 resource_is_free=1;
12326 Note, mcs51 and ds390 support only an atomic
12327 \begin_inset LatexCommand \index{atomic}
12335 instruction (as opposed to atomic bit test and
12340 Functions using private register banks
12341 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12348 Some architectures have support for quickly changing register sets.
12349 SDCC supports this feature with the
12352 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12357 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12363 attribute (which tells the compiler to use a register bank
12364 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12368 other than the default bank zero).
12369 It should only be applied to
12372 \begin_inset LatexCommand \index{interrupt}
12378 functions (see footnote below).
12379 This will in most circumstances make the generated ISR code more efficient
12380 since it will not have to save registers on the stack.
12387 attribute will have no effect on the generated code for a
12391 function (but may occasionally be useful anyway
12397 possible exception: if a function is called ONLY from 'interrupt' functions
12398 using a particular bank, it can be declared with the same 'using' attribute
12399 as the calling 'interrupt' functions.
12400 For instance, if you have several ISRs using bank one, and all of them
12401 call memcpy(), it might make sense to create a specialized version of memcpy()
12402 'using 1', since this would prevent the ISR from having to save bank zero
12403 to the stack on entry and switch to bank zero before calling the function
12410 (pending: I don't think this has been done yet)
12417 function using a non-zero bank will assume that it can trash that register
12418 bank, and will not save it.
12419 Since high-priority interrupts
12420 \begin_inset LatexCommand \index{interrupts}
12425 \begin_inset LatexCommand \index{interrupt priority}
12429 can interrupt low-priority ones on the 8051 and friends, this means that
12430 if a high-priority ISR
12434 a particular bank occurs while processing a low-priority ISR
12438 the same bank, terrible and bad things can happen.
12439 To prevent this, no single register bank should be
12443 by both a high priority and a low priority ISR.
12444 This is probably most easily done by having all high priority ISRs use
12445 one bank and all low priority ISRs use another.
12446 If you have an ISR which can change priority at runtime, you're on your
12447 own: I suggest using the default bank zero and taking the small performance
12451 It is most efficient if your ISR calls no other functions.
12452 If your ISR must call other functions, it is most efficient if those functions
12453 use the same bank as the ISR (see note 1 below); the next best is if the
12454 called functions use bank zero.
12455 It is very inefficient to call a function using a different, non-zero bank
12461 \begin_inset LatexCommand \label{sub:Startup-Code}
12466 \begin_inset LatexCommand \index{Startup code}
12473 MCS51/DS390 Startup Code
12476 The compiler inserts a call to the C routine
12478 _sdcc_external_startup()
12479 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
12488 at the start of the CODE area.
12489 This routine is in the runtime library
12490 \begin_inset LatexCommand \index{Runtime library}
12495 By default this routine returns 0, if this routine returns a non-zero value,
12496 the static & global variable initialization will be skipped and the function
12497 main will be invoked.
12498 Otherwise static & global variables will be initialized before the function
12502 _sdcc_external_startup()
12504 routine to your program to override the default if you need to setup hardware
12505 or perform some other critical operation prior to static & global variable
12507 \begin_inset LatexCommand \index{Variable initialization}
12512 On some mcs51 variants xdata
12513 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12517 memory has to be explicitly enabled before it can be accessed or if the
12518 watchdog needs to be disabled, this is the place to do it.
12519 The startup code clears all internal data memory, 256 bytes by default,
12520 but from 0 to n-1 if
12533 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12540 (recommended for Chipcon CC1010).
12543 See also the compiler option
12562 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
12567 \begin_inset LatexCommand \ref{sub:MCS51-variants}
12572 about MCS51-variants.
12578 The HC08 startup code follows the same scheme as the MCS51 startup code.
12584 On the Z80 the startup code is inserted by linking with crt0.o which is generated
12585 from sdcc/device/lib/z80/crt0.s.
12586 If you need a different startup code you can use the compiler option
12607 \begin_inset LatexCommand \index{-\/-no-std-crt0}
12611 and provide your own crt0.o.
12615 Inline Assembler Code
12616 \begin_inset LatexCommand \index{Assembler routines}
12623 A Step by Step Introduction
12624 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
12631 Starting from a small snippet of c-code this example shows for the MCS51
12632 how to use inline assembly, access variables, a function parameter and
12633 an array in xdata memory.
12634 The example uses an MCS51 here but is easily adapted for other architectures.
12635 This is a buffer routine which should be optimized:
12642 \begin_inset LatexCommand \index{far (storage class)}
12647 \begin_inset LatexCommand \index{\_\_far (storage class)}
12652 \begin_inset LatexCommand \index{at}
12657 \begin_inset LatexCommand \index{\_\_at}
12661 (0x7f00) buf[0x100];
12662 \begin_inset LatexCommand \index{Aligned array}
12668 unsigned char head, tail;
12672 void to_buffer( unsigned char c )
12680 if( head != (unsigned char)(tail-1) )\SpecialChar ~
12686 \begin_inset LatexCommand \index{promotion to signed int}
12691 \begin_inset LatexCommand \index{type promotion}
12696 \begin_inset Marginal
12716 buf[ head++ ] = c;\SpecialChar ~
12732 /* access to a 256 byte aligned array */
12737 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
12738 then a corresponding buffer.asm file is generated.
12739 We define a new function
12743 in file buffer.c in which we cut and paste the generated code, removing
12744 unwanted comments and some ':'.
12746 \begin_inset Quotes sld
12750 \begin_inset Quotes srd
12754 \begin_inset Quotes sld
12758 \begin_inset Quotes srd
12761 to the beginning and the end of the function body:
12767 /* With a cut and paste from the .asm file, we have something to start with.
12772 The function is not yet OK! (registers aren't saved) */
12774 void to_buffer_asm( unsigned char c )
12783 \begin_inset LatexCommand \index{\_asm}
12788 \begin_inset LatexCommand \index{\_\_asm}
12802 ;buffer.c if( head != (unsigned char)(tail-1) )
12850 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
12851 \begin_inset LatexCommand \index{Aligned array}
12916 \begin_inset LatexCommand \index{\_endasm}
12921 \begin_inset LatexCommand \index{\_\_endasm}
12930 The new file buffer.c should compile with only one warning about the unreferenced
12931 function argument 'c'.
12932 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
12933 (1) and finally have:
12939 unsigned char far __at(0x7f00) buf[0x100];
12941 unsigned char head, tail;
12943 #define USE_ASSEMBLY (1)
12951 void to_buffer( unsigned char c )
12959 if( head != (unsigned char)(tail-1) )
12979 void to_buffer( unsigned char c )
12987 c; // to avoid warning: unreferenced function argument
12994 \begin_inset LatexCommand \index{\_asm}
12999 \begin_inset LatexCommand \index{\_\_asm}
13013 ; save used registers here.
13024 ; If we were still using r2,r3 we would have to push them here.
13027 ; if( head != (unsigned char)(tail-1) )
13070 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
13094 ; buf[ head++ ] = c;
13105 a,dpl \SpecialChar ~
13112 ; dpl holds lower byte of function argument
13123 dpl,_head \SpecialChar ~
13126 ; buf is 0x100 byte aligned so head can be used directly
13168 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
13180 ; restore used registers here
13187 \begin_inset LatexCommand \index{\_endasm}
13192 \begin_inset LatexCommand \index{\_\_endasm}
13203 The inline assembler code can contain any valid code understood by the assembler
13204 , this includes any assembler directives and comment lines
13210 The assembler does not like some characters like ':' or ''' in comments.
13211 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
13212 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
13217 \begin_inset LatexCommand \index{Assembler documentation}
13225 The compiler does not do any validation of the code within the
13228 \begin_inset LatexCommand \index{\_asm}
13233 \begin_inset LatexCommand \index{\_\_asm}
13241 \begin_inset LatexCommand \index{\_endasm}
13246 \begin_inset LatexCommand \index{\_\_endasm}
13255 Specifically it will not know which registers are used and thus register
13257 \begin_inset LatexCommand \index{push/pop}
13261 has to be done manually.
13265 It is recommended that each assembly instruction (including labels) be placed
13266 in a separate line (as the example shows).
13280 \begin_inset LatexCommand \index{-\/-peep-asm}
13286 command line option is used, the inline assembler code will be passed through
13287 the peephole optimizer
13288 \begin_inset LatexCommand \index{Peephole optimizer}
13293 There are only a few (if any) cases where this option makes sense, it might
13294 cause some unexpected changes in the inline assembler code.
13295 Please go through the peephole optimizer rules defined in file
13299 before using this option.
13303 \begin_inset LatexCommand \label{sub:Naked-Functions}
13308 \begin_inset LatexCommand \index{Naked functions}
13315 A special keyword may be associated with a function declaring it as
13318 \begin_inset LatexCommand \index{\_naked}
13323 \begin_inset LatexCommand \index{\_\_naked}
13334 function modifier attribute prevents the compiler from generating prologue
13335 \begin_inset LatexCommand \index{function prologue}
13340 \begin_inset LatexCommand \index{function epilogue}
13344 code for that function.
13345 This means that the user is entirely responsible for such things as saving
13346 any registers that may need to be preserved, selecting the proper register
13347 bank, generating the
13351 instruction at the end, etc.
13352 Practically, this means that the contents of the function must be written
13353 in inline assembler.
13354 This is particularly useful for interrupt functions, which can have a large
13355 (and often unnecessary) prologue/epilogue.
13356 For example, compare the code generated by these two functions:
13362 \begin_inset LatexCommand \index{volatile}
13366 data unsigned char counter;
13370 void simpleInterrupt(void) __interrupt
13371 \begin_inset LatexCommand \index{interrupt}
13376 \begin_inset LatexCommand \index{\_\_interrupt}
13394 void nakedInterrupt(void) __interrupt (2) __naked
13403 \begin_inset LatexCommand \index{\_asm}
13408 \begin_inset LatexCommand \index{\_\_asm}
13425 _counter ; does not change flags, no need to save psw
13437 ; MUST explicitly include ret or reti in _naked function.
13444 \begin_inset LatexCommand \index{\_endasm}
13449 \begin_inset LatexCommand \index{\_\_endasm}
13458 For an 8051 target, the generated simpleInterrupt looks like:
13467 example, recent versions of SDCC generate
13469 the same code for simpleInterrupt() and nakedInterrupt()!
13609 whereas nakedInterrupt looks like:
13624 _counter ; does not change flags, no need to save psw
13642 ; MUST explicitly include ret or reti in _naked function
13645 The related directive #pragma exclude
13646 \begin_inset LatexCommand \index{\#pragma exclude}
13650 allows a more fine grained control over pushing & popping
13651 \begin_inset LatexCommand \index{push/pop}
13658 While there is nothing preventing you from writing C code inside a
13662 function, there are many ways to shoot yourself in the foot doing this,
13663 and it is recommended that you stick to inline assembler.
13666 Use of Labels within Inline Assembler
13669 SDCC allows the use of in-line assembler with a few restrictions regarding
13671 In older versions of the compiler all labels defined within inline assembler
13680 where nnnn is a number less than 100 (which implies a limit of utmost 100
13681 inline assembler labels
13695 \begin_inset LatexCommand \index{\_asm}
13700 \begin_inset LatexCommand \index{\_\_asm}
13730 \begin_inset LatexCommand \index{\_endasm}
13735 \begin_inset LatexCommand \index{\_\_endasm}
13742 Inline assembler code cannot reference any C-Labels, however it can reference
13744 \begin_inset LatexCommand \index{Labels}
13748 defined by the inline assembler, e.g.:
13773 ; some assembler code
13793 /* some more c code */
13795 clabel:\SpecialChar ~
13797 /* inline assembler cannot reference this label */
13809 $0003: ;label (can be referenced by inline assembler only)
13816 \begin_inset LatexCommand \index{\_endasm}
13821 \begin_inset LatexCommand \index{\_\_endasm}
13831 /* some more c code */
13836 In other words inline assembly code can access labels defined in inline
13837 assembly within the scope of the function.
13838 The same goes the other way, i.e.
13839 labels defines in inline assembly can not be accessed by C statements.
13842 Interfacing with Assembler Code
13843 \begin_inset LatexCommand \index{Assembler routines}
13850 Global Registers used for Parameter Passing
13851 \begin_inset LatexCommand \index{Parameter passing}
13858 The compiler always uses the global registers
13861 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13866 \begin_inset LatexCommand \index{DPTR}
13871 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
13880 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
13886 to pass the first parameter to a routine.
13887 The second parameter onwards is either allocated on the stack (for reentrant
13898 -stack-auto is used) or in data / xdata memory (depending on the memory
13903 Assembler Routine (non-reentrant)
13906 In the following example
13907 \begin_inset LatexCommand \index{reentrant}
13912 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
13916 the function c_func calls an assembler routine asm_func, which takes two
13918 \begin_inset LatexCommand \index{function parameter}
13927 extern int asm_func(unsigned char, unsigned char);
13931 int c_func (unsigned char i, unsigned char j)
13939 return asm_func(i,j);
13953 return c_func(10,9);
13958 The corresponding assembler function is:
13963 .globl _asm_func_PARM_2
14064 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
14081 Note here that the return values
14082 \begin_inset LatexCommand \index{return value}
14086 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
14088 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
14089 b' & 'acc' for four byte values.
14092 The parameter naming convention is _<function_name>_PARM_<n>, where n is
14093 the parameter number starting from 1, and counting from the left.
14094 The first parameter is passed in
14095 \begin_inset Quotes eld
14099 \begin_inset Quotes erd
14102 for a one byte parameter,
14103 \begin_inset Quotes eld
14107 \begin_inset Quotes erd
14111 \begin_inset Quotes eld
14115 \begin_inset Quotes erd
14118 for three bytes and
14119 \begin_inset Quotes eld
14123 \begin_inset Quotes erd
14126 for a four bytes parameter.
14127 The variable name for the second parameter will be _<function_name>_PARM_2.
14131 Assemble the assembler routine with the following command:
14138 asx8051 -losg asmfunc.asm
14145 Then compile and link the assembler routine to the C source file with the
14153 sdcc cfunc.c asmfunc.rel
14156 Assembler Routine (reentrant)
14160 \begin_inset LatexCommand \index{reentrant}
14165 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
14169 the second parameter
14170 \begin_inset LatexCommand \index{function parameter}
14174 onwards will be passed on the stack, the parameters are pushed from right
14176 after the call the leftmost parameter will be on the top of the stack.
14177 Here is an example:
14182 extern int asm_func(unsigned char, unsigned char);
14186 int c_func (unsigned char i, unsigned char j) reentrant
14194 return asm_func(i,j);
14208 return c_func(10,9);
14213 The corresponding assembler routine is:
14313 The compiling and linking procedure remains the same, however note the extra
14314 entry & exit linkage required for the assembler code, _bp is the stack
14315 frame pointer and is used to compute the offset into the stack for parameters
14316 and local variables.
14320 \begin_inset LatexCommand \index{int (16 bit)}
14325 \begin_inset LatexCommand \index{long (32 bit)}
14332 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
14333 multiplication and modulus operations are implemented by support routines.
14334 These support routines are all developed in ANSI-C to facilitate porting
14335 to other MCUs, although some model specific assembler optimizations are
14337 The following files contain the described routines, all of them can be
14338 found in <installdir>/share/sdcc/lib.
14344 \begin_inset Tabular
14345 <lyxtabular version="3" rows="11" columns="2">
14347 <column alignment="left" valignment="top" leftline="true" width="0">
14348 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14349 <row topline="true" bottomline="true">
14350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14371 <row topline="true">
14372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14385 16 bit multiplication
14389 <row topline="true">
14390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14403 signed 16 bit division (calls _divuint)
14407 <row topline="true">
14408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14421 unsigned 16 bit division
14425 <row topline="true">
14426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14439 signed 16 bit modulus (calls _moduint)
14443 <row topline="true">
14444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14457 unsigned 16 bit modulus
14461 <row topline="true">
14462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14475 32 bit multiplication
14479 <row topline="true">
14480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14493 signed 32 division (calls _divulong)
14497 <row topline="true">
14498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14511 unsigned 32 division
14515 <row topline="true">
14516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14529 signed 32 bit modulus (calls _modulong)
14533 <row topline="true" bottomline="true">
14534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14547 unsigned 32 bit modulus
14560 Since they are compiled as
14565 \begin_inset LatexCommand \index{reentrant}
14570 \begin_inset LatexCommand \index{interrupt}
14574 service routines should not do any of the above operations.
14575 If this is unavoidable then the above routines will need to be compiled
14589 \begin_inset LatexCommand \index{-\/-stack-auto}
14595 option, after which the source program will have to be compiled with
14608 \begin_inset LatexCommand \index{-\/-int-long-reent}
14615 Notice that you don't have to call these routines directly.
14616 The compiler will use them automatically every time an integer operation
14620 Floating Point Support
14621 \begin_inset LatexCommand \index{Floating point support}
14628 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
14629 floating point support routines are derived from gcc's floatlib.c and consist
14630 of the following routines:
14638 \begin_inset Tabular
14639 <lyxtabular version="3" rows="17" columns="2">
14641 <column alignment="left" valignment="top" leftline="true" width="0">
14642 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
14643 <row topline="true" bottomline="true">
14644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14670 <row topline="true">
14671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14702 add floating point numbers
14706 <row topline="true">
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14738 subtract floating point numbers
14742 <row topline="true">
14743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14774 divide floating point numbers
14778 <row topline="true">
14779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14810 multiply floating point numbers
14814 <row topline="true">
14815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14846 convert floating point to unsigned char
14850 <row topline="true">
14851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14882 convert floating point to signed char
14886 <row topline="true">
14887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14904 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14918 convert floating point to unsigned int
14922 <row topline="true">
14923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14954 convert floating point to signed int
14958 <row topline="true">
14959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14999 convert floating point to unsigned long
15003 <row topline="true">
15004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15035 convert floating point to signed long
15039 <row topline="true">
15040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15071 convert unsigned char to floating point
15075 <row topline="true">
15076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15107 convert char to floating point number
15111 <row topline="true">
15112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15143 convert unsigned int to floating point
15147 <row topline="true">
15148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15179 convert int to floating point numbers
15183 <row topline="true">
15184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15215 convert unsigned long to floating point number
15219 <row topline="true" bottomline="true">
15220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15251 convert long to floating point number
15264 These support routines are developed in ANSI-C so there is room for space
15265 and speed improvement
15271 These floating point routines (
15275 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
15280 Note if all these routines are used simultaneously the data space might
15282 For serious floating point usage the large model might be needed.
15283 Also notice that you don't have to call this routines directly.
15284 The compiler will use them automatically every time a floating point operation
15289 \begin_inset LatexCommand \index{Libraries}
15298 <pending: this is messy and incomplete - a little more information is in
15299 sdcc/doc/libdoc.txt
15304 Compiler support routines (_gptrget, _mulint etc.)
15307 Stdclib functions (puts, printf, strcat etc.)
15308 \layout Subsubsection
15314 \begin_inset LatexCommand \index{<stdio.h>}
15318 As usual on embedded systems you have to provide your own
15321 \begin_inset LatexCommand \index{getchar()}
15330 \begin_inset LatexCommand \index{putchar()}
15337 SDCC does not know whether the system connects to a serial line with or
15338 without handshake, LCD, keyboard or other device.
15352 You'll find examples for serial routines f.e.
15353 in sdcc/device/lib.
15359 \begin_inset LatexCommand \index{printf()}
15369 does not support float (except on ds390).
15370 To enable this recompile it with the option
15383 \begin_inset LatexCommand \index{USE\_FLOATS}
15389 on the command line.
15403 \begin_inset LatexCommand \index{-\/-model-large}
15409 for the mcs51 port, since this uses a lot of memory.
15412 If you're short on memory you might want to use
15415 \begin_inset LatexCommand \index{printf\_small()}
15430 For the mcs51 there additionally are assembly versions
15433 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
15439 (subset of printf using less than 270 bytes) and
15442 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
15451 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
15457 (floating-point aware version of printf_fast) which should fit the requirements
15458 of many embedded systems (printf_fast() can be customized by unsetting
15463 support long variables and field widths).
15466 Math functions (sinf, powf, sqrtf etc.)
15467 \layout Subsubsection
15472 See definitions in file <math.h>.
15479 \begin_inset LatexCommand \index{Libraries}
15483 included in SDCC should have a license at least as liberal as the GNU Lesser
15484 General Public License
15485 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15496 license statements for the libraries are missing.
15497 sdcc/device/lib/ser_ir.c
15501 come with a GPL (as opposed to LGPL) License - this will not be liberal
15502 enough for many embedded programmers.
15505 If you have ported some library or want to share experience about some code
15507 falls into any of these categories Busses (I
15508 \begin_inset Formula $^{\textrm{2}}$
15511 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
15512 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
15513 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
15514 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
15519 would certainly like to hear about it.
15520 Programmers coding for embedded systems are not especially famous for being
15521 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
15522 e these references are very valuable.
15523 Let's help to create a climate where information is shared.
15529 MCS51 Memory Models
15530 \begin_inset LatexCommand \index{Memory model}
15535 \begin_inset LatexCommand \index{MCS51 memory model}
15540 \layout Subsubsection
15542 Small, Medium and Large
15545 SDCC allows three memory models for MCS51 code,
15554 Modules compiled with different memory models should
15558 be combined together or the results would be unpredictable.
15559 The library routines supplied with the compiler are compiled as small,
15561 The compiled library modules are contained in separate directories as small,
15562 medium and large so that you can link to the appropriate set.
15565 When the medium or large model is used all variables declared without a
15566 storage class will be allocated into the external ram, this includes all
15567 parameters and local variables (for non-reentrant
15568 \begin_inset LatexCommand \index{reentrant}
15573 When the small model is used variables without storage class are allocated
15574 in the internal ram.
15577 Judicious usage of the processor specific storage classes
15578 \begin_inset LatexCommand \index{Storage class}
15582 and the 'reentrant' function type will yield much more efficient code,
15583 than using the large model.
15584 Several optimizations are disabled when the program is compiled using the
15585 large model, it is therefore recommended that the small model be used unless
15586 absolutely required.
15587 \layout Subsubsection
15590 \begin_inset LatexCommand \label{sub:External-Stack}
15595 \begin_inset LatexCommand \index{stack}
15600 \begin_inset LatexCommand \index{External stack (mcs51)}
15607 The external stack (-
15618 \begin_inset LatexCommand \index{-\/-xstack}
15622 ) is located in pdata
15623 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15627 memory (usually at the start of the external ram segment) and uses all
15628 unused space in pdata (max.
15640 -xstack option is used to compile the program, the parameters and local
15642 \begin_inset LatexCommand \index{local variables}
15646 of all reentrant functions are allocated in this area.
15647 This option is provided for programs with large stack space requirements.
15648 When used with the -
15659 \begin_inset LatexCommand \index{-\/-stack-auto}
15663 option, all parameters and local variables are allocated on the external
15664 stack (note: support libraries will need to be recompiled with the same
15666 There is a predefined target in the library makefile).
15669 The compiler outputs the higher order address byte of the external ram segment
15671 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15676 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15680 ), therefore when using the External Stack option, this port
15684 be used by the application program.
15688 \begin_inset LatexCommand \index{Memory model}
15693 \begin_inset LatexCommand \index{DS390 memory model}
15700 The only model supported is Flat 24
15701 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
15706 This generates code for the 24 bit contiguous addressing mode of the Dallas
15708 In this mode, up to four meg of external RAM or code space can be directly
15710 See the data sheets at www.dalsemi.com for further information on this part.
15714 Note that the compiler does not generate any code to place the processor
15715 into 24 bitmode (although
15719 in the ds390 libraries will do that for you).
15725 \begin_inset LatexCommand \index{Tinibios (DS390)}
15729 , the boot loader or similar code must ensure that the processor is in 24
15730 bit contiguous addressing mode before calling the SDCC startup code.
15748 option, variables will by default be placed into the XDATA segment.
15753 Segments may be placed anywhere in the 4 meg address space using the usual
15765 Note that if any segments are located above 64K, the -r flag must be passed
15766 to the linker to generate the proper segment relocations, and the Intel
15767 HEX output format must be used.
15768 The -r flag can be passed to the linker by using the option
15772 on the SDCC command line.
15773 However, currently the linker can not handle code segments > 64k.
15777 \begin_inset LatexCommand \index{Pragmas}
15784 SDCC supports the following #pragma directives:
15788 \begin_inset LatexCommand \index{\#pragma save}
15792 - this will save all current options to the save/restore stack.
15793 See #pragma\SpecialChar ~
15798 \begin_inset LatexCommand \index{\#pragma restore}
15802 - will restore saved options from the last save.
15803 saves & restores can be nested.
15804 SDCC uses a save/restore stack: save pushes current options to the stack,
15805 restore pulls current options from the stack.
15806 See #pragma\SpecialChar ~
15813 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15818 \begin_inset LatexCommand \index{function prologue}
15822 function1[,function2[,function3...]] - The compiler by default uses a caller
15823 saves convention for register saving across function calls, however this
15824 can cause unnecessary register pushing & popping
15825 \begin_inset LatexCommand \index{push/pop}
15829 when calling small functions from larger functions.
15830 This option can be used to switch off the register saving convention for
15831 the function names specified.
15832 The compiler will not save registers when calling these functions, extra
15833 code need to be manually inserted at the entry & exit for these functions
15834 to save & restore the registers used by these functions, this can SUBSTANTIALLY
15835 reduce code & improve run time performance of the generated code.
15836 In the future the compiler (with inter procedural analysis) may be able
15837 to determine the appropriate scheme to use for each function call.
15848 -callee-saves command line option is used, the function names specified
15849 in #pragma\SpecialChar ~
15851 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15855 is appended to the list of functions specified in the command line.
15859 \begin_inset LatexCommand \index{\#pragma exclude}
15863 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
15864 of pairs of push/pop
15865 \begin_inset LatexCommand \index{push/pop}
15874 \begin_inset LatexCommand \index{interrupt}
15887 The directive should be placed immediately before the ISR function definition
15888 and it affects ALL ISR functions following it.
15889 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
15890 exclude\SpecialChar ~
15892 \begin_inset LatexCommand \index{\#pragma exclude}
15897 See also the related keyword _naked
15898 \begin_inset LatexCommand \index{\_naked}
15903 \begin_inset LatexCommand \index{\_\_naked}
15911 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
15915 - the compiler will not warn you anymore for obvious mistakes, you'r on
15919 disable_warning <nnnn>
15920 \begin_inset LatexCommand \index{\#pragma disable\_warning}
15924 - the compiler will not warn you anymore about warning number <nnnn>.
15928 \begin_inset LatexCommand \index{\#pragma nogcse}
15932 - will stop global common subexpression elimination.
15936 \begin_inset LatexCommand \index{\#pragma noinduction}
15940 - will stop loop induction optimizations.
15944 \begin_inset LatexCommand \index{\#pragma noinvariant}
15948 - will not do loop invariant optimizations.
15949 For more details see Loop Invariants in section
15950 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
15958 \begin_inset LatexCommand \index{\#pragma noiv}
15962 - Do not generate interrupt
15963 \begin_inset LatexCommand \index{interrupt}
15967 vector table entries for all ISR functions defined after the pragma.
15968 This is useful in cases where the interrupt vector table must be defined
15969 manually, or when there is a secondary, manually defined interrupt vector
15971 for the autovector feature of the Cypress EZ-USB FX2).
15972 More elegantly this can be achieved by obmitting the optional interrupt
15973 number after the interrupt keyword, see section
15974 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
15983 \begin_inset LatexCommand \index{\#pragma nojtbound}
15987 - will not generate code for boundary value checking, when switch statements
15988 are turned into jump-tables (dangerous).
15989 For more details see section
15990 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
15998 \begin_inset LatexCommand \index{\#pragma noloopreverse}
16002 - Will not do loop reversal optimization
16006 \begin_inset LatexCommand \index{\#pragma nooverlay}
16010 - the compiler will not overlay the parameters and local variables of a
16015 \begin_inset LatexCommand \index{\#pragma stackauto}
16030 \begin_inset LatexCommand \index{-\/-stack-auto}
16035 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
16039 Parameters and Local Variables.
16043 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
16047 - The compiler will optimize code generation towards fast code, possibly
16048 at the expense of code size.
16052 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
16056 - The compiler will optimize code generation towards compact code, possibly
16057 at the expense of code speed.
16061 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
16065 - The compiler will attempt to generate code that is both compact and fast,
16066 as long as meeting one goal is not a detriment to the other (this is the
16072 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
16076 - Generally follow the C89 standard, but allow SDCC features that conflict
16077 with the standard (default).
16081 \begin_inset LatexCommand \index{\#pragma std\_c89}
16085 - Follow the C89 standard and disable SDCC features that conflict with the
16090 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
16094 - Generally follow the C99 standard, but allow SDCC features that conflict
16095 with the standard (incomplete support).
16099 \begin_inset LatexCommand \index{\#pragma std\_c99}
16103 - Follow the C99 standard and disable SDCC features that conflict with the
16104 standard (incomplete support).
16108 \begin_inset LatexCommand \index{\#pragma codeseg}
16112 - Use this name (max.
16113 8 characters) for the code segment.
16128 \begin_inset LatexCommand \index{\#pragma constseg}
16132 - Use this name (max.
16133 8 characters) for the const segment.
16147 SDCPP supports the following #pragma directives:
16151 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
16155 (+ | -) - switch _asm _endasm block preprocessing on / off.
16159 The pragma's are intended to be used to turn-on or off certain optimizations
16160 which might cause the compiler to generate extra stack / data space to
16161 store compiler generated temporary variables.
16162 This usually happens in large functions.
16163 Pragma directives should be used as shown in the following example, they
16164 are used to control options & optimizations for a given function; pragmas
16165 should be placed before and/or after a function, placing pragma's inside
16166 a function body could have unpredictable results.
16172 \begin_inset LatexCommand \index{\#pragma save}
16183 /* save the current settings */
16186 \begin_inset LatexCommand \index{\#pragma nogcse}
16195 /* turnoff global subexpression elimination */
16197 #pragma noinduction
16198 \begin_inset LatexCommand \index{\#pragma noinduction}
16202 /* turn off induction optimizations */
16225 \begin_inset LatexCommand \index{\#pragma restore}
16229 /* turn the optimizations back on */
16232 The compiler will generate a warning message when extra space is allocated.
16233 It is strongly recommended that the save and restore pragma's be used when
16234 changing options for a function.
16237 Defines Created by the Compiler
16240 The compiler creates the following #defines
16241 \begin_inset LatexCommand \index{\#defines}
16246 \begin_inset LatexCommand \index{Defines created by the compiler}
16256 \begin_inset Tabular
16257 <lyxtabular version="3" rows="11" columns="2">
16259 <column alignment="left" valignment="top" leftline="true" width="0">
16260 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16261 <row topline="true" bottomline="true">
16262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16283 <row topline="true">
16284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16290 \begin_inset LatexCommand \index{SDCC}
16297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16303 Since version 2.5.6 the version number as an int (ex.
16308 <row topline="true">
16309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16315 \begin_inset LatexCommand \index{SDCC\_mcs51}
16320 \begin_inset LatexCommand \index{SDCC\_ds390}
16325 \begin_inset LatexCommand \index{SDCC\_z80}
16332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16337 depending on the model used (e.g.: -mds390
16341 <row topline="true">
16342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16348 \begin_inset LatexCommand \index{\_\_mcs51}
16353 \begin_inset LatexCommand \index{\_\_ds390}
16358 \begin_inset LatexCommand \index{\_\_hc08}
16363 \begin_inset LatexCommand \index{\_\_z80}
16370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16375 depending on the model used (e.g.
16380 <row topline="true">
16381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16387 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
16394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16417 <row topline="true">
16418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16424 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
16431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16454 <row topline="true">
16455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16461 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
16468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16491 <row topline="true">
16492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16498 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
16505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16528 <row topline="true">
16529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16535 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
16542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16565 <row topline="true">
16566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16572 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
16579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16592 <row topline="true" bottomline="true">
16593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16599 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
16606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16626 Notes on supported Processors
16630 \begin_inset LatexCommand \label{sub:MCS51-variants}
16635 \begin_inset LatexCommand \index{MCS51 variants}
16642 MCS51 processors are available from many vendors and come in many different
16644 While they might differ considerably in respect to Special Function Registers
16645 the core MCS51 is usually not modified or is kept compatible.
16649 pdata access by SFR
16652 With the upcome of devices with internal xdata and flash memory devices
16654 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
16658 as dedicated I/O port is becoming more popular.
16659 Switching the high byte for pdata
16660 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
16664 access which was formerly done by port P2 is then achieved by a Special
16666 \begin_inset LatexCommand \index{sfr}
16671 In well-established MCS51 tradition the address of this
16675 is where the chip designers decided to put it.
16676 Needless to say that they didn't agree on a common name either.
16677 So that the startup code can correctly initialize xdata variables, you
16678 should define an sfr with the name _XPAGE
16681 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
16687 at the appropriate location if the default, port P2, is not used for this.
16693 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
16698 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
16703 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
16706 For more exotic implementations further customizations may be needed.
16708 \begin_inset LatexCommand \ref{sub:Startup-Code}
16712 for other possibilities.
16715 Other Features available by SFR
16718 Some MCS51 variants offer features like Double DPTR
16719 \begin_inset LatexCommand \index{DPTR}
16723 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
16724 These are currently not used for the MCS51 port.
16725 If you absolutely need them you can fall back to inline assembly or submit
16732 The DS80C400 microcontroller has a rich set of peripherals.
16733 In its built-in ROM library it includes functions to access some of the
16734 features, among them is a TCP stack with IP4 and IP6 support.
16735 Library headers (currently in beta status) and other files are provided
16739 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
16747 The Z80 and gbz80 port
16750 SDCC can target both the Zilog
16751 \begin_inset LatexCommand \index{Z80}
16755 and the Nintendo Gameboy's Z80-like gbz80
16756 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
16761 The Z80 port is passed through the same
16764 \begin_inset LatexCommand \index{Regression test}
16770 as the MCS51 and DS390 ports, so floating point support, support for long
16771 variables and bitfield support is fine.
16772 See mailing lists and forums about interrupt routines.
16775 As always, the code is the authoritative reference - see z80/ralloc.c and
16778 \begin_inset LatexCommand \index{stack}
16782 frame is similar to that generated by the IAR Z80 compiler.
16783 IX is used as the base pointer, HL and IY are used as a temporary registers,
16784 and BC and DE are available for holding variables.
16786 \begin_inset LatexCommand \index{return value}
16790 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
16792 The gbz80 port use the same set of registers for the return values, but
16793 in a different order of significance: E (one byte), DE (two bytes), or
16800 The port to the Motorola HC08
16801 \begin_inset LatexCommand \index{HC08}
16805 family has been added in October 2003, and is still undergoing some basic
16807 The code generator is complete, but the register allocation is still quite
16809 Some of the SDCC's standard C library functions have embedded non-HC08
16810 inline assembly and so are not yet usable.
16821 \begin_inset LatexCommand \index{PIC14}
16825 port still requires a major effort from the development community.
16826 However it can work for very simple code.
16829 C code and 14bit PIC code page
16830 \begin_inset LatexCommand \index{code page (pic14)}
16835 \begin_inset LatexCommand \index{RAM bank (pic14)}
16842 The linker organizes allocation for the code page and RAM banks.
16843 It does not have intimate knowledge of the code flow.
16844 It will put all the code section of a single asm file into a single code
16846 In order to make use of multiple code pages, separate asm files must be
16848 The compiler treats all functions of a single C file as being in the same
16849 code page unless it is non static.
16850 The compiler treats all local variables of a single C file as being in
16851 the same RAM bank unless it is an extern.
16855 To get the best follow these guide lines:
16858 make local functions static, as non static functions require code page selection
16862 Make local variables static as extern variables require RAM bank selection
16866 For devices that have multiple code pages it is more efficient to use the
16867 same number of files as pages, i.e.
16868 for the 16F877 use 4 separate files and i.e.
16869 for the 16F874 use 2 separate files.
16870 This way the linker can put the code for each file into different code
16871 pages and the compiler can allocate reusable variables more efficiently
16872 and there's less page selection overhead.
16873 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
16874 instruction set) use 'unsigned char' whereever possible instead of 'int'.
16877 Creating a device include file
16880 For generating a device include file use the support perl script inc2h.pl
16881 kept in directory support/script.
16887 For the interrupt function, use the keyword 'interrupt'
16888 \begin_inset LatexCommand \index{interrupt}
16892 with level number of 0 (PIC14 only has 1 interrupt so this number is only
16893 there to avoid a syntax error - it ought to be fixed).
16899 void Intr(void) interrupt 0
16905 T0IF = 0; /* Clear timer interrupt */
16910 Linking and assembling
16913 For assembling you can use either GPUTILS'
16914 \begin_inset LatexCommand \index{gputils (pic tools)}
16918 gpasm.exe or MPLAB's mpasmwin.exe.
16919 GPUTILS is available from
16920 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
16925 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
16926 If you use MPLAB and an interrupt function then the linker script file
16927 vectors section will need to be enlarged to link with mplink.
16950 sdcc -S -V -mpic14 -p16F877 $<
16964 $(PRJ).hex: $(OBJS)
16974 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
16996 sdcc -S -V -mpic14 -p16F877 $<
17006 mpasmwin /q /o $*.asm
17010 $(PRJ).hex: $(OBJS)
17020 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
17023 Please note that indentations within a
17027 have to be done with a tabulator character.
17030 Command-line options
17033 Besides the switches common to all SDCC backends, the PIC14 port accepts
17034 the following options (for an updated list see sdcc -
17046 \labelwidthstring 00.00.0000
17058 -debug-extra emit debug info in assembly output
17060 \labelwidthstring 00.00.0000
17072 -no-pcode-opt disable (slightly faulty) optimization on pCode
17076 \layout Subsubsection
17078 error: missing definition for symbol
17079 \begin_inset Quotes sld
17083 \begin_inset Quotes srd
17089 The PIC14 port uses library routines to provide more complex operations
17090 like multiplication, division/modulus and (generic) pointer dereferencing.
17091 In order to add these routines to your project, you must link with PIC14's
17097 For single source file projects this is done automatically, more complex
17102 to the linker's arguments.
17103 Make sure you also add an include path for the library (using the -I switch
17105 \layout Subsubsection
17107 Processor mismatch in file
17108 \begin_inset Quotes sld
17112 \begin_inset Quotes srd
17118 This warning can usually be ignored due to the very good compatibility amongst
17119 14 bit PIC devices.
17122 You might also consider recompiling the library for your specific device
17123 by changing the ARCH=p16f877 (default target) entry in
17125 device/lib/pic/Makefile.in
17129 device/lib/pic/Makefile
17131 to reflect your device.
17132 This might even improve performance for smaller devices as unneccesary
17133 BANKSELs migth be removed.
17137 \layout Subsubsection
17142 Currently, data can only be initialized if it resides in the source file
17148 Data in other source files will silently
17156 \begin_inset LatexCommand \index{PIC16}
17164 \begin_inset LatexCommand \index{PIC16}
17168 port is the portion of SDCC that is responsible to produce code for the
17170 \begin_inset LatexCommand \index{Microchip}
17174 (TM) microcontrollers with 16 bit core.
17175 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
17176 Currently supported devices are:
17180 \begin_inset Tabular
17181 <lyxtabular version="3" rows="4" columns="6">
17183 <column alignment="center" valignment="top" leftline="true" width="0">
17184 <column alignment="center" valignment="top" leftline="true" width="0">
17185 <column alignment="center" valignment="top" leftline="true" width="0">
17186 <column alignment="center" valignment="top" leftline="true" width="0">
17187 <column alignment="center" valignment="top" leftline="true" width="0">
17188 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17189 <row topline="true">
17190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17239 <row topline="true">
17240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17289 <row topline="true">
17290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17339 <row topline="true" bottomline="true">
17340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17396 PIC16 port supports the standard command line arguments as supposed, with
17397 the exception of certain cases that will be mentioned in the following
17400 \labelwidthstring 00.00.0000
17412 -callee-saves See -
17424 \labelwidthstring 00.00.0000
17436 -all-callee-saves All function arguments are passed on stack by default.
17439 There is no need to specify this in the command line.
17441 \labelwidthstring 00.00.0000
17453 -fommit-frame-pointer Frame pointer will be omitted when the function uses
17454 no local variables.
17457 Port Specific Options
17458 \begin_inset LatexCommand \index{Options PIC16}
17465 The port specific options appear after the global options in the sdcc --help
17467 \layout Subsubsection
17472 General options enable certain port features and optimizations.
17474 \labelwidthstring 00.00.0000
17486 -stack-model=[model] Used in conjuction with the command above.
17487 Defines the stack model to be used, valid stack models are :
17490 \labelwidthstring 00.00.0000
17496 Selects small stack model.
17497 8 bit stack and frame pointers.
17498 Supports 256 bytes stack size.
17500 \labelwidthstring 00.00.0000
17506 Selects large stack model.
17507 16 bit stack and frame pointers.
17508 Supports 65536 bytes stack size.
17511 \labelwidthstring 00.00.0000
17523 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
17524 unitialized data variables with [kword].
17525 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
17527 \labelwidthstring 00.00.0000
17539 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
17540 Useful for bootloaders.
17542 \labelwidthstring 00.00.0000
17554 -asm= sets the full path and name of an external assembler to call.
17556 \labelwidthstring 00.00.0000
17568 -link= sets the full path and name of an external linker to call.
17570 \labelwidthstring 00.00.0000
17582 -mplab-comp MPLAB compatibility option.
17583 Currently only suppresses special gpasm directives.
17584 \layout Subsubsection
17586 Optimization Options
17588 \labelwidthstring 00.00.0000
17600 -optimize-goto Try to use (conditional) BRA instead of GOTO
17602 \labelwidthstring 00.00.0000
17614 -optimize-cmp Try to optimize some compares.
17616 \labelwidthstring 00.00.0000
17628 -optimize-df Analyze the dataflow of the generated code and improve it.
17630 \labelwidthstring 00.00.0000
17642 -obanksel=nn Set optimization level for inserting BANKSELs.
17647 \labelwidthstring 00.00.0000
17651 \labelwidthstring 00.00.0000
17653 1 checks previous used register and if it is the same then does not emit
17654 BANKSEL, accounts only for labels.
17656 \labelwidthstring 00.00.0000
17658 2 tries to check the location of (even different) symbols and removes BANKSELs
17659 if they are in the same bank.
17664 Important: There might be problems if the linker script has data sections
17665 across bank borders!
17667 \layout Subsubsection
17671 \labelwidthstring 00.00.0000
17683 -nodefaultlibs do not link default libraries when linking
17685 \labelwidthstring 00.00.0000
17697 -no-crt Don't link the default run-time modules
17699 \labelwidthstring 00.00.0000
17711 -use-crt= Use a custom run-time module instead of the defaults.
17712 \layout Subsubsection
17717 Debugging options enable extra debugging information in the output files.
17719 \labelwidthstring 00.00.0000
17731 -debug-xtra Similar to -
17742 \begin_inset LatexCommand \index{-\/-debug}
17746 , but dumps more information.
17748 \labelwidthstring 00.00.0000
17760 -debug-ralloc Force register allocator to dump <source>.d file with debugging
17762 <source> is the name of the file compiled.
17764 \labelwidthstring 00.00.0000
17776 -pcode-verbose Enable pcode debugging information in translation.
17778 \labelwidthstring 00.00.0000
17790 -denable-peeps Force the usage of peepholes.
17793 \labelwidthstring 00.00.0000
17805 -gstack Trace push/pops for stack pointer overflow
17807 \labelwidthstring 00.00.0000
17819 -call-tree dump call tree in .calltree file
17822 Enviromental Variables
17825 There is a number of enviromental variables that can be used when running
17826 SDCC to enable certain optimizations or force a specific program behaviour.
17827 these variables are primarily for debugging purposes so they can be enabled/dis
17831 Currently there is only two such variables available:
17833 \labelwidthstring 00.00.0000
17835 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
17836 bitfields is optimized by directly loading FSR0 with the address of the
17837 bitfield structure.
17838 Normally SDCC will cast the bitfield structure to a bitfield pointer and
17840 This step saves data ram and code space for functions that perform heavy
17843 80 bytes of code space are saved when compiling malloc.c with this option).
17846 \labelwidthstring 00.00.0000
17848 NO_REG_OPT do not perform pCode registers optimization.
17849 This should be used for debugging purposes.
17850 In some where bugs in the pcode optimizer are found, users can benefit
17851 from temporarily disabling the optimizer until the bug is fixed.
17854 Preprocessor Macros
17857 PIC16 port defines the following preprocessor macros while translating a
17862 \begin_inset Tabular
17863 <lyxtabular version="3" rows="6" columns="2">
17865 <column alignment="center" valignment="top" leftline="true" width="0">
17866 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17867 <row topline="true" bottomline="true">
17868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17885 <row topline="true">
17886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17899 Port identification
17903 <row topline="true">
17904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17927 Port identification (same as above)
17931 <row topline="true">
17932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17945 MCU Identification.
17950 is the microcontrol identification number, i.e.
17955 <row topline="true">
17956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17979 MCU Identification (same as above)
17983 <row topline="true" bottomline="true">
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17997 nnn = SMALL or LARGE respectively according to the stack model used
18008 In addition the following macros are defined when calling assembler:
18012 \begin_inset Tabular
18013 <lyxtabular version="3" rows="4" columns="2">
18015 <column alignment="center" valignment="top" leftline="true" width="0">
18016 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18017 <row topline="true" bottomline="true">
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">
18035 <row topline="true">
18036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18049 MCU Identification.
18054 is the microcontrol identification number, i.e.
18059 <row topline="true">
18060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 nnn = SMALL or LARGE respectively according to the memory model used for
18078 <row topline="true" bottomline="true">
18079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18092 nnn = SMALL or LARGE respectively according to the stack model used
18107 \begin_inset LatexCommand \index{PIC16}
18111 port uses the following directories for searching header files and libraries.
18115 \begin_inset Tabular
18116 <lyxtabular version="3" rows="3" columns="4">
18118 <column alignment="center" valignment="top" leftline="true" width="0">
18119 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18120 <column alignment="center" valignment="top" width="0">
18121 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18122 <row topline="true" bottomline="true">
18123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18156 <row topline="true">
18157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18162 PREFIX/sdcc/include/pic16
18165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18170 PIC16 specific headers
18173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18190 <row topline="true" bottomline="true">
18191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18196 PREFIX/sdcc/lib/pic16
18199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18204 PIC16 specific libraries
18207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18232 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
18239 PIC16 port currently supports the following pragmas:
18241 \labelwidthstring 00.00.0000
18243 stack pragma stack forces the code generator to initialize the stack & frame
18244 pointers at a specific address.
18245 This is an adhoc solution for cases where no STACK directive is available
18246 in the linker script or gplink is not instructed to create a stack section.
18248 The stack pragma should be used only once in a project.
18249 Multiple pragmas may result in indeterminate behaviour of the program.
18255 The old format (ie.
18256 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
18257 cross page boundaries (or even exceed the available data RAM) and crash
18259 Make sure that stack does not cross page boundaries when using the SMALL
18265 The format is as follows:
18268 #pragma stack bottom_address [stack_size]
18275 is the lower bound of the stack section.
18276 The stack pointer initially will point at address (bottom_address+stack_size-1).
18284 /* initializes stack of 100 bytes at RAM address 0x200 */
18287 #pragma stack 0x200 100
18290 If the stack_size field is omitted then a stack is created with the default
18292 This size might be enough for most programs, but its not enough for operations
18293 with deep function nesting or excessive stack usage.
18295 \labelwidthstring 00.00.0000
18299 This pragma is deprecated.
18300 Its use will cause a warning message to be issued.
18306 \labelwidthstring 00.00.0000
18308 code place a function symbol at static FLASH address
18316 /* place function test_func at 0x4000 */
18319 #pragma code test_func 0x4000
18323 \labelwidthstring 00.00.0000
18325 library instructs the linker to use a library module.
18330 #pragma library module_name
18337 can be any library or object file (including its path).
18338 Note that there are four reserved keywords which have special meaning.
18343 \begin_inset Tabular
18344 <lyxtabular version="3" rows="6" columns="3">
18346 <column alignment="center" valignment="top" leftline="true" width="0">
18347 <column alignment="block" valignment="top" leftline="true" width="20page%">
18348 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18349 <row topline="true" bottomline="true">
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18375 <row topline="true">
18376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18391 ignore all library pragmas
18394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18405 <row topline="true">
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18437 <row topline="true">
18438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18453 link the Math libarary
18456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18469 <row topline="true">
18470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 link the I/O library
18488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18501 <row topline="true" bottomline="true">
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18517 link the debug library
18520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18539 * is the device number, i.e.
18540 452 for PIC18F452 MCU.
18543 This feature allows for linking with specific libraries withoug having to
18544 explicit name them in the command line.
18549 keyword will reject all modules specified by the library pragma.
18551 \labelwidthstring 00.00.0000
18553 udata pragma udata instructs the compiler to emit code so that linker will
18554 place a variable at a specific memory bank
18562 /* places variable foo at bank2 */
18565 #pragma udata bank2 foo
18571 In order for this pragma to work extra SECTION directives should be added
18572 in the .lkr script.
18573 In the following example a sample .lkr file is shown:
18578 // Sample linker script for the PIC18F452 processor
18584 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
18587 CODEPAGE NAME=page START=0x2A END=0x7FFF
18590 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
18593 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
18596 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
18599 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
18602 ACCESSBANK NAME=accessram START=0x0 END=0x7F
18607 DATABANK NAME=gpr0 START=0x80 END=0xFF
18610 DATABANK NAME=gpr1 START=0x100 END=0x1FF
18613 DATABANK NAME=gpr2 START=0x200 END=0x2FF
18616 DATABANK NAME=gpr3 START=0x300 END=0x3FF
18619 DATABANK NAME=gpr4 START=0x400 END=0x4FF
18622 DATABANK NAME=gpr5 START=0x500 END=0x5FF
18625 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
18630 SECTION NAME=CONFIG ROM=config
18635 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
18638 SECTION NAME=bank1 RAM=gpr1 # should be added to link
18641 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
18644 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
18647 SECTION NAME=bank4 RAM=gpr4
18650 SECTION NAME=bank5 RAM=gpr5
18653 The linker will recognise the section name set in the pragma statement and
18654 will position the variable at the memory bank set with the RAM field at
18655 the SECTION line in the linker script file.
18659 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
18666 There is one main header file that can be included to the source files using
18673 This header file contains the definitions for the processor special registers,
18674 so it is necessary if the source accesses them.
18675 It can be included by adding the following line in the beginning of the
18679 #include <pic18fregs.h>
18682 The specific microcontroller is selected within the pic18fregs.h automatically,
18683 so the same source can be used with a variety of devices.
18689 The libraries that PIC16
18690 \begin_inset LatexCommand \index{PIC16}
18694 port depends on are the microcontroller device libraries which contain
18695 the symbol definitions for the microcontroller special function registers.
18696 These libraries have the format pic18fxxxx.lib, where
18700 is the microcontroller identification number.
18701 The specific library is selected automatically by the compiler at link
18702 stage according to the selected device.
18705 Libraries are created with gplib which is part of the gputils package
18706 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
18711 \layout Subsubsection*
18713 Building the libraries
18716 Before using SDCC/pic16 there are some libraries that need to be compiled.
18717 This process is not done automatically by SDCC since not all users use
18718 SDCC for pic16 projects.
18719 So each user should compile the libraries separately.
18722 The steps to compile the pic16 libraries under Linux are:
18725 cd device/lib/pic16
18740 su -c 'make install' # install the libraries, you need the root password
18743 If you need to install the headers too, do:
18749 su -c 'make install' # install the headers, you need the root password
18752 There exist a special target to build the I/O libraries.
18753 This target is not automatically build because it will build the I/O library
18759 This way building will take quite a lot of time.
18760 Users are advised to edit the
18762 device/lib/pic16/pics.build
18764 file and then execute:
18773 The following memory models are supported by the PIC16 port:
18782 Memory model affects the default size of pointers within the source.
18783 The sizes are shown in the next table:
18787 \begin_inset Tabular
18788 <lyxtabular version="3" rows="3" columns="3">
18790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18791 <column alignment="center" valignment="top" leftline="true" width="0">
18792 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18793 <row topline="true" bottomline="true">
18794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18799 Pointer sizes according to memory model
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18819 <row topline="true" bottomline="true">
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18828 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18845 <row topline="true" bottomline="true">
18846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18854 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
18862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18878 It is advisable that all sources within a project are compiled with the
18880 If one wants to override the default memory model, this can be done by
18881 declaring a pointer as
18890 Far selects large memory model's pointers, while near selects small memory
18894 The standard device libraries (see
18895 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
18899 ) contain no reference to pointers, so they can be used with both memory
18906 The stack implementation for the PIC16 port uses two indirect registers,
18909 \labelwidthstring 00.00.0000
18911 FSR1 is assigned as stack pointer
18913 \labelwidthstring 00.00.0000
18915 FSR2 is assigned as frame pointer
18918 The following stack models are supported by the PIC16 port
18939 model means that only the FSRxL byte is used to access stack and frame,
18946 uses both FSRxL and FSRxH registers.
18947 The following table shows the stack/frame pointers sizes according to stack
18948 model and the maximum space they can address:
18952 \begin_inset Tabular
18953 <lyxtabular version="3" rows="3" columns="3">
18955 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18956 <column alignment="center" valignment="top" leftline="true" width="0">
18957 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18958 <row topline="true" bottomline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18964 Stack & Frame pointer sizes according to stack model
18967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18984 <row topline="true">
18985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19010 <row topline="true" bottomline="true">
19011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19047 stack model is currently not working properly throughout the code generator.
19048 So its use is not advised.
19049 Also there are some other points that need special care:
19054 Do not create stack sections with size more than one physical bank (that
19058 Stack sections should no cross physical bank limits (i.e.
19059 #pragma stack 0x50 0x100)
19062 These limitations are caused by the fact that only FSRxL is modified when
19063 using SMALL stack model, so no more than 256 bytes of stack can be used.
19064 This problem will disappear after LARGE model is fully implemented.
19070 In addition to the standard SDCC function keywords, PIC16 port makes available
19073 \labelwidthstring 00.00.0000
19075 wparam Use the WREG to pass one byte of the first function argument.
19076 This improves speed but you may not use this for functions with arguments
19077 that are called via function pointers, otherwise the first byte of the
19078 first parameter will get lost.
19082 void func_wparam(int a) wparam
19088 /* WREG hold the lower part of a */
19091 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
19101 This keyword replaces the deprecated wparam pragma.
19103 \labelwidthstring 00.00.0000
19105 shadowregs When entering/exiting an ISR, it is possible to take advantage
19106 of the PIC18F hardware shadow registers which hold the values of WREG,
19107 STATUS and BSR registers.
19108 This can be done by adding the keyword
19116 keyword in the function's header.
19119 void isr_shadow(void) shadowregs interrupt 1
19135 instructs the code generator not to store/restore WREG, STATUS, BSR when
19136 entering/exiting the ISR.
19139 Function return values
19142 Return values from functions are placed to the appropriate registers following
19143 a modified Microchip policy optimized for SDCC.
19144 The following table shows these registers:
19148 \begin_inset Tabular
19149 <lyxtabular version="3" rows="6" columns="2">
19151 <column alignment="center" valignment="top" leftline="true" width="0">
19152 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19153 <row topline="true" bottomline="true">
19154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19167 destination register
19171 <row topline="true">
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19189 <row topline="true">
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19207 <row topline="true">
19208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19225 <row topline="true">
19226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19239 FSR0L:PRODH:PRODL:WREG
19243 <row topline="true" bottomline="true">
19244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19257 on stack, FSR0 points to the beginning
19271 An interrupt servive routine (ISR) is declared using the
19278 void isr(void) interrupt
19296 is the interrupt number, which for PIC18F devices can be:
19300 \begin_inset Tabular
19301 <lyxtabular version="3" rows="4" columns="3">
19303 <column alignment="center" valignment="top" leftline="true" width="0">
19304 <column alignment="center" valignment="top" leftline="true" width="0">
19305 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19306 <row topline="true" bottomline="true">
19307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19330 Interrupt Vector Address
19334 <row topline="true">
19335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19360 <row topline="true">
19361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19392 HIGH priority interrupts
19395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19404 <row topline="true" bottomline="true">
19405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19418 LOW priority interrupts
19421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19437 When generating assembly code for ISR the code generator places a
19443 Interrupt Vector Address
19445 which points at the genetated ISR.
19446 This single GOTO instruction is part of an automatically generated
19448 interrupt entry point
19451 The actuall ISR code is placed as normally would in the code space.
19452 Upon interrupt request, the GOTO instruction is executed which jumps to
19454 When declaring interrupt functions as _naked this GOTO instruction is
19459 The whole interrupt functions is therefore placed at the Interrupt Vector
19460 Address of the specific interrupt.
19461 This is not a problem for the LOW priority interrupts, but it is a problem
19462 for the RESET and the HIGH priority interrupts because code may be written
19463 at the next interrupt´s vector address and cause undeterminate program
19464 behaviour if that interrupt is raised.
19470 This is not a problem when
19473 this is a HIGH interrupt ISR and LOW interrupts are
19480 when the ISR is small enough not to reach the next interrupt´s vector address.
19490 is possible to be omitted.
19491 This way a function is generated similar to an ISR, but it is not assigned
19495 When entering an interrupt, currently the PIC16
19496 \begin_inset LatexCommand \index{PIC16}
19500 port automatically saves the following registers:
19512 PROD (PRODL and PRODH)
19515 FSR0 (FSR0L and FSR0H)
19518 These registers are restored upon return from the interrupt routine.
19524 NOTE that when the _naked attribute is specified for an interrupt routine,
19525 then NO registers are stored or restored.
19534 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
19535 There are 3 types of generic pointers currently implemented data, code
19536 and eeprom pointers.
19537 They are differentiated by the value of the 7th and 6th bits of the upper
19542 \begin_inset Tabular
19543 <lyxtabular version="3" rows="5" columns="5">
19545 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19546 <column alignment="center" valignment="top" width="0">
19547 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19548 <column alignment="center" valignment="top" width="0">
19549 <column alignment="left" valignment="top" rightline="true" width="0">
19550 <row topline="true" bottomline="true">
19551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19580 rest of the pointer
19583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19592 <row topline="true" bottomline="true">
19593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19626 uuuuuu uuuuxxxx xxxxxxxx
19629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19634 a 12-bit data pointer in data RAM memory
19638 <row bottomline="true">
19639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19672 uxxxxx xxxxxxxx xxxxxxxx
19675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19680 a 21-bit code pointer in FLASH memory
19684 <row bottomline="true">
19685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19718 uuuuuu uuuuuuxx xxxxxxxx
19721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19726 a 10-bit eeprom pointer in EEPROM memory
19730 <row bottomline="true">
19731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19764 xxxxxx xxxxxxxx xxxxxxxx
19767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19772 unimplemented pointer type
19783 Generic pointer are read and written with a set of library functions which
19784 read/write 1, 2, 3, 4 bytes.
19788 \layout Subsubsection
19790 Standard I/O Streams
19797 the type FILE is defined as:
19800 typedef char * FILE;
19803 This type is the stream type implemented I/O in the PIC18F devices.
19804 Also the standard input and output streams are declared in stdio.h:
19807 extern FILE * stdin;
19810 extern FILE * stdout;
19813 The FILE type is actually a generic pointer which defines one more type
19814 of generic pointers, the
19819 This new type has the format:
19823 \begin_inset Tabular
19824 <lyxtabular version="3" rows="2" columns="7">
19826 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19827 <column alignment="center" valignment="top" width="0">
19828 <column alignment="center" valignment="top" leftline="true" width="0">
19829 <column alignment="center" valignment="top" leftline="true" width="0">
19830 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19831 <column alignment="center" valignment="top" width="0">
19832 <column alignment="left" valignment="top" rightline="true" width="0">
19833 <row topline="true" bottomline="true">
19834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19879 rest of the pointer
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19891 <row topline="true" bottomline="true">
19892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19949 upper byte high nubble is 0x2n, the rest are zeroes
19960 Currently implemented there are 3 types of streams defined:
19964 \begin_inset Tabular
19965 <lyxtabular version="3" rows="4" columns="4">
19967 <column alignment="center" valignment="top" leftline="true" width="0">
19968 <column alignment="center" valignment="top" leftline="true" width="0">
19969 <column alignment="center" valignment="top" leftline="true" width="0">
19970 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19971 <row topline="true" bottomline="true">
19972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20005 <row topline="true">
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20037 Writes/Reads characters via the USART peripheral
20041 <row topline="true">
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20073 Writes/Reads characters via the MSSP peripheral
20077 <row topline="true" bottomline="true">
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20109 Writes/Reads characters via used defined functions
20120 The stream identifiers are declared as macros in the stdio.h header.
20123 In the libc library there exist the functions that are used to write to
20124 each of the above streams.
20127 \labelwidthstring 00.00.0000
20139 _stream_usart_putchar writes a character at the USART stream
20141 \labelwidthstring 00.00.0000
20153 _stream_mssp_putchar writes a character at the MSSP stream
20155 \labelwidthstring 00.00.0000
20157 putchar dummy function.
20158 This writes a character to a user specified manner.
20161 In order to increase performance
20165 is declared in stdio.h as having its parameter in WREG (it has the wparam
20167 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
20168 in a user-friendly way.
20173 is the name of the variable that holds the character to print.
20174 An example follows:
20177 #include <pic18fregs.h>
20189 PORTA = c; /* dump character c to PORTA */
20202 stdout = STREAM_USER; /* this is not necessery, since stdout points
20205 * by default to STREAM_USER */
20208 printf (¨This is a printf test
20216 \layout Subsubsection
20221 PIC16 contains an implementation of the printf-family of functions.
20222 There exist the following functions:
20225 extern unsigned int sprintf(char *buf, char *fmt, ...);
20228 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
20233 extern unsigned int printf(char *fmt, ...);
20236 extern unsigned int vprintf(char *fmt, va_lista ap);
20241 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
20244 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
20247 For sprintf and vsprintf
20251 should normally be a data pointer where the resulting string will be placed.
20252 No range checking is done so the user should allocate the necessery buffer.
20253 For fprintf and vfprintf
20257 should be a stream pointer (i.e.
20258 stdout, STREAM_MSSP, etc...).
20259 \layout Subsubsection
20264 The PIC18F family of microcontrollers supports a number of interrupt sources.
20265 A list of these interrupts is shown in the following table:
20269 \begin_inset Tabular
20270 <lyxtabular version="3" rows="11" columns="4">
20272 <column alignment="left" valignment="top" leftline="true" width="0">
20273 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20274 <column alignment="left" valignment="top" leftline="true" width="0">
20275 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20276 <row topline="true" bottomline="true">
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20310 <row topline="true">
20311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20324 PORTB change interrupt
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20340 EEPROM/FLASH write complete interrupt
20344 <row topline="true">
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20358 INT0 external interrupt
20361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20374 Bus collision interrupt
20378 <row topline="true">
20379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20392 INT1 external interrupt
20395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20408 Low voltage detect interrupt
20412 <row topline="true">
20413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20426 INT2 external interrupt
20429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20442 Parallel slave port interrupt
20446 <row topline="true">
20447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20460 CCP1 module interrupt
20463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20476 AD convertion complete interrupt
20480 <row topline="true">
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20494 CCP2 module interrupt
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20510 USART receive interrupt
20514 <row topline="true">
20515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20528 TMR0 overflow interrupt
20531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20544 USART transmit interrupt
20548 <row topline="true">
20549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20562 TMR1 overflow interrupt
20565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20578 SSP receive/transmit interrupt
20582 <row topline="true">
20583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20596 TMR2 matches PR2 interrupt
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20614 <row topline="true" bottomline="true">
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20628 TMR3 overflow interrupt
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20653 The prototypes for these names are defined in the header file
20660 In order to simplify signal handling, a number of macros is provided:
20662 \labelwidthstring 00.00.0000
20664 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
20665 high priority interrupts.
20670 is the function name to use.
20672 \labelwidthstring 00.00.0000
20674 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
20675 low priority interrupt.
20680 is the function name to use.
20682 \labelwidthstring 00.00.0000
20684 DEF_HANDLER(sig,handler) define a handler for signal
20688 \labelwidthstring 00.00.0000
20690 END_DEF end the declaration of the dispatch table.
20693 Additionally there are two more macros to simplify the declaration of the
20696 \labelwidthstring 00.00.0000
20700 SIGHANDLER(handler)
20702 this declares the function prototype for the
20708 \labelwidthstring 00.00.0000
20710 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
20713 An example of using the macros above is shown below:
20716 #include <pic18fregs.h>
20719 #include <signal.h>
20723 DEF_INTHIGH(high_int)
20726 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
20729 DEF_HANDLER(SIG_BCOL, _bcol_handler)
20736 SIGHANDLER(_tmr0_handler)
20742 /* action to be taken when timer 0 overflows */
20749 SIGHANDLERNAKED(_bcol_handler)
20758 /* action to be taken when bus collision occurs */
20774 Special care should be taken when using the above scheme:
20777 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
20780 when declaring SIGHANDLERNAKED handler never forget to use
20784 for proper returning.
20790 Here you can find some general tips for compiling programs with SDCC/pic16.
20791 \layout Subsubsection
20796 The default stack size (that is 64 bytes) probably is enough for many programs.
20797 One must take care that when there are many levels of function nesting,
20798 or there is excessive usage of stack, its size should be extended.
20799 An example of such a case is the printf/sprintf family of functions.
20800 If you encounter problems like not being able to print integers, then you
20801 need to set the stack size around the maximum (256 for small stack model).
20802 The following diagram shows what happens when calling printf to print an
20806 printf () --> ltoa () --> ultoa () --> divschar ()
20809 It is should be understood that stack is easily consumed when calling complicate
20811 Using command line arguments like -
20821 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
20823 Other ways to reduce stack usage may exist.
20829 There are several approaches to debugging your code.
20830 This chapter is meant to show your options and to give detail on some of
20835 When writing your code:
20838 write your code with debugging in mind (avoid duplicating code, put conceptually
20839 similar variables into structs, use structured code, have strategic points
20840 within your code where all variables are consistent, ...)
20843 run a syntax-checking tool like splint
20844 \begin_inset LatexCommand \index{splint (syntax checking tool)}
20849 \begin_inset LatexCommand \index{lint (syntax checking tool)}
20864 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
20871 for the high level code use a C-compiler (like f.e.
20872 GCC) to compile run and debug the code on your host.
20884 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
20888 ) on howto handle syntax extensions like __xdata, __at(), ...
20892 use another C-compiler to compile code for your target.
20893 Always an option but not recommended:) And not very likely to help you.
20894 If you seriously consider walking this path you should at least occasionally
20895 check portability of your code.
20896 Most commercial compiler vendors will offer an evaluation version so you
20897 can test compile your code or snippets of your code.
20900 Debugging on a simulator:
20903 there is a separate section about SDCDB (section
20904 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
20911 or (8051 specific) use a freeware/commercial simulator which interfaces
20913 \begin_inset LatexCommand \index{AOMF, AOMF51}
20918 \begin_inset LatexCommand \ref{OMF file}
20922 ) optionally generated by SDCC.
20925 Debugging On-target:
20928 use a MCU port pin to serially output debug data to the RS232 port of your
20930 You'll probably want some level shifting device typically involving a MAX232
20932 If the hardware serial port of the MCU is not available search for 'Software
20933 UART' in your favourite search machine.
20936 use an on-target monitor.
20937 In this context a monitor is a small program which usually accepts commands
20938 via a serial line and allows to set program counter, to single step through
20939 a program and read/write memory locations.
20940 For the 8051 a good example of a monitor with a very liberal licence is
20942 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
20949 toggle MCU port pins at strategic points within your code and use an oscilloscop
20953 digital oscilloscope
20956 \begin_inset LatexCommand \index{oscilloscope}
20960 with deep trace memory is really helpful especially if you have to debug
20961 a realtime application.
20962 If you need to monitor more pins than your oscilloscope provides you can
20963 sometimes get away with a small R-2R network.
20964 On a single channel oscilloscope you could f.e.
20965 monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
20967 \begin_inset Formula $\Omega$
20970 resistor and the other one by a 5\SpecialChar ~
20972 \begin_inset Formula $\Omega$
20975 resistor to the oscilloscope probe (check output drive capability of the
20976 pins you want to monitor).
20977 If you need to monitor many more pins a
20997 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
21002 Usually very expensive.
21003 And very nice to have too.
21004 And usually locks you (for years...) to the devices the ICE can emulate.
21008 use a remote debugger.
21009 In most 8-bit systems the symbol information is not available on the target,
21010 and a complete debugger is too bulky for the target system.
21011 Therefore usually a debugger on the host system connects to an on-target
21012 debugging stub which accepts only primitive commands.
21015 Terms to enter into your favourite search engine could be 'remote debugging',
21016 'gdb stub' or 'inferior debugger'.
21020 use an on target hardware debugger.
21021 Some of the more modern MCUs include hardware support for setting break
21022 points and monitoring/changing variables by using dedicated hardware pins.
21023 This facility doesn't require additional code to run on the target and
21028 doesn't affect runtime behaviour until a breakpoint is hit.
21029 For the mcs51 most hardware debuggers use the AOMF
21030 \begin_inset LatexCommand \index{AOMF, AOMF51}
21035 \begin_inset LatexCommand \ref{OMF file}
21046 if you are not familiar with any of the following terms you're likely to
21047 run into problems rather sooner than later:
21064 As an embedded programmer you
21068 to know them so why not look them up
21072 you have problems?)
21075 tell someone else about your problem (actually this is a surprisingly effective
21076 means to hunt down the bug even if the listener is not familiar with your
21078 As 'failure to communicate' is probably one of the job-induced deformations
21079 of an embedded programmer this is highly encouraged.
21082 Debugging with SDCDB
21083 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
21088 \begin_inset LatexCommand \index{sdcdb (debugger)}
21095 SDCC is distributed with a source level debugger
21096 \begin_inset LatexCommand \index{Debugger}
21101 The debugger uses a command line interface, the command repertoire of the
21102 debugger has been kept as close to gdb
21103 \begin_inset LatexCommand \index{gdb}
21107 (the GNU debugger) as possible.
21108 The configuration and build process is part of the standard compiler installati
21109 on, which also builds and installs the debugger in the target directory
21110 specified during configuration.
21111 The debugger allows you debug BOTH at the C source and at the ASM source
21113 Sdcdb is currently not available on Win32 platforms.
21116 Compiling for Debugging
21130 \begin_inset LatexCommand \index{-\/-debug}
21134 option must be specified for all files for which debug information is to
21136 The compiler generates a .adb file for each of these files.
21137 The linker creates the .cdb
21138 \begin_inset LatexCommand \index{<file>.cdb}
21143 \begin_inset LatexCommand \index{<file>.adb}
21147 files and the address information.
21148 This .cdb is used by the debugger.
21151 How the Debugger Works
21164 -debug option is specified the compiler generates extra symbol information
21165 some of which are put into the assembler source and some are put into the
21167 Then the linker creates the .cdb file from the individual .adb files with
21168 the address information for the symbols.
21169 The debugger reads the symbolic information generated by the compiler &
21170 the address information generated by the linker.
21171 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
21172 execution is controlled by the debugger.
21173 When a command is issued for the debugger, it translates it into appropriate
21174 commands for the simulator.
21175 (Currently sdcdb only connects to the simulator but
21180 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
21184 is an effort to connect directly to the hardware.)
21187 Starting the Debugger SDCDB
21190 The debugger can be started using the following command line.
21191 (Assume the file you are debugging has the file name foo).
21205 The debugger will look for the following files.
21208 foo.c - the source file.
21211 foo.cdb - the debugger symbol information file.
21214 foo.ihx - the Intel hex format
21215 \begin_inset LatexCommand \index{Intel hex format}
21222 SDCDB Command Line Options
21235 -directory=<source file directory> this option can used to specify the directory
21237 The debugger will look into the directory list specified for source, cdb
21239 The items in the directory list must be separated by ':', e.g.
21240 if the source files can be in the directories /home/src1 and /home/src2,
21251 -directory option should be -
21261 -directory=/home/src1:/home/src2.
21262 Note there can be no spaces in the option.
21266 -cd <directory> - change to the <directory>.
21269 -fullname - used by GUI front ends.
21272 -cpu <cpu-type> - this argument is passed to the simulator please see the
21273 simulator docs for details.
21276 -X <Clock frequency > this options is passed to the simulator please see
21277 the simulator docs for details.
21280 -s <serial port file> passed to simulator see the simulator docs for details.
21283 -S <serial in,out> passed to simulator see the simulator docs for details.
21286 -k <port number> passed to simulator see the simulator docs for details.
21289 SDCDB Debugger Commands
21292 As mentioned earlier the command interface for the debugger has been deliberatel
21293 y kept as close the GNU debugger gdb, as possible.
21294 This will help the integration with existing graphical user interfaces
21295 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
21296 If you use a graphical user interface for the debugger you can skip this
21298 \layout Subsubsection*
21300 break [line | file:line | function | file:function]
21303 Set breakpoint at specified line or function:
21312 sdcdb>break foo.c:100
21314 sdcdb>break funcfoo
21316 sdcdb>break foo.c:funcfoo
21317 \layout Subsubsection*
21319 clear [line | file:line | function | file:function ]
21322 Clear breakpoint at specified line or function:
21331 sdcdb>clear foo.c:100
21333 sdcdb>clear funcfoo
21335 sdcdb>clear foo.c:funcfoo
21336 \layout Subsubsection*
21341 Continue program being debugged, after breakpoint.
21342 \layout Subsubsection*
21347 Execute till the end of the current function.
21348 \layout Subsubsection*
21353 Delete breakpoint number 'n'.
21354 If used without any option clear ALL user defined break points.
21355 \layout Subsubsection*
21357 info [break | stack | frame | registers ]
21360 info break - list all breakpoints
21363 info stack - show the function call stack.
21366 info frame - show information about the current execution frame.
21369 info registers - show content of all registers.
21370 \layout Subsubsection*
21375 Step program until it reaches a different source line.
21376 Note: pressing <return> repeats the last command.
21377 \layout Subsubsection*
21382 Step program, proceeding through subroutine calls.
21383 \layout Subsubsection*
21388 Start debugged program.
21389 \layout Subsubsection*
21394 Print type information of the variable.
21395 \layout Subsubsection*
21400 print value of variable.
21401 \layout Subsubsection*
21406 load the given file name.
21407 Note this is an alternate method of loading file for debugging.
21408 \layout Subsubsection*
21413 print information about current frame.
21414 \layout Subsubsection*
21419 Toggle between C source & assembly source.
21420 \layout Subsubsection*
21422 ! simulator command
21425 Send the string following '!' to the simulator, the simulator response is
21427 Note the debugger does not interpret the command being sent to the simulator,
21428 so if a command like 'go' is sent the debugger can loose its execution
21429 context and may display incorrect values.
21430 \layout Subsubsection*
21437 My name is Bobby Brown"
21440 Interfacing SDCDB with DDD
21443 The screenshot was converted from png to eps with:
21444 \begin_inset Quotes sld
21447 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
21448 \begin_inset Quotes srd
21451 which produces a pretty compact eps file which is free from compression
21455 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
21456 as this broke the build system on Sourceforge (pdf-file was broken).
21462 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.eps}
21468 shows a screenshot of a debugging session with DDD
21469 \begin_inset LatexCommand \index{DDD (debugger)}
21473 (Unix only) on a simulated 8032.
21474 The debugging session might not run as smoothly as the screenshot suggests.
21475 The debugger allows setting of breakpoints, displaying and changing variables,
21476 single stepping through C and assembler code.
21479 The source was compiled with
21502 -debug ddd_example.c
21515 and DDD was invoked with
21522 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
21525 Interfacing SDCDB with XEmacs
21526 \begin_inset LatexCommand \index{XEmacs}
21531 \begin_inset LatexCommand \index{Emacs}
21538 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
21539 sdcdb.el and sdcdbsrc.el.
21540 These two files can be found in the $(prefix)/bin directory after the installat
21542 These files need to be loaded into XEmacs for the interface to work.
21543 This can be done at XEmacs startup time by inserting the following into
21544 your '.xemacs' file (which can be found in your HOME directory):
21550 (load-file sdcdbsrc.el)
21556 .xemacs is a lisp file so the () around the command is REQUIRED.
21557 The files can also be loaded dynamically while XEmacs is running, set the
21558 environment variable 'EMACSLOADPATH' to the installation bin directory
21559 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
21560 To start the interface enter the following command:
21574 You will prompted to enter the file name to be debugged.
21579 The command line options that are passed to the simulator directly are bound
21580 to default values in the file sdcdbsrc.el.
21581 The variables are listed below, these values maybe changed as required.
21584 sdcdbsrc-cpu-type '51
21587 sdcdbsrc-frequency '11059200
21590 sdcdbsrc-serial nil
21593 The following is a list of key mapping for the debugger interface.
21604 ;;key\SpecialChar ~
21618 binding\SpecialChar ~
21642 ;;---\SpecialChar ~
21656 -------\SpecialChar ~
21698 sdcdb-next-from-src\SpecialChar ~
21726 sdcdb-back-from-src\SpecialChar ~
21754 sdcdb-cont-from-src\SpecialChar ~
21764 SDCDB continue command
21782 sdcdb-step-from-src\SpecialChar ~
21810 sdcdb-whatis-c-sexp\SpecialChar ~
21820 SDCDB ptypecommand for data at
21887 sdcdbsrc-delete\SpecialChar ~
21901 SDCDB Delete all breakpoints if no arg
21950 given or delete arg (C-u arg x)
21968 sdcdbsrc-frame\SpecialChar ~
21983 SDCDB Display current frame if no arg,
22032 given or display frame arg
22099 sdcdbsrc-goto-sdcdb\SpecialChar ~
22109 Goto the SDCDB output buffer
22127 sdcdb-print-c-sexp\SpecialChar ~
22138 SDCDB print command for data at
22205 sdcdbsrc-goto-sdcdb\SpecialChar ~
22215 Goto the SDCDB output buffer
22233 sdcdbsrc-mode\SpecialChar ~
22249 Toggles Sdcdbsrc mode (turns it off)
22264 sdcdb-finish-from-src\SpecialChar ~
22272 SDCDB finish command
22287 sdcdb-break\SpecialChar ~
22305 Set break for line with point
22320 sdcdbsrc-mode\SpecialChar ~
22336 Toggle Sdcdbsrc mode
22351 sdcdbsrc-srcmode\SpecialChar ~
22374 Here are a few guidelines that will help the compiler generate more efficient
22375 code, some of the tips are specific to this compiler others are generally
22376 good programming practice.
22379 Use the smallest data type to represent your data-value.
22380 If it is known in advance that the value is going to be less than 256 then
22381 use an 'unsigned char' instead of a 'short' or 'int'.
22382 Please note, that ANSI C requires both signed and unsigned chars to be
22383 promoted to 'signed int'
22384 \begin_inset LatexCommand \index{promotion to signed int}
22388 before doing any operation.
22390 \begin_inset LatexCommand \index{type promotion}
22395 \begin_inset LatexCommand \label{type promotion}
22399 can be omitted, if the result is the same.
22400 The effect of the promotion rules together with the sign-extension is often
22407 unsigned char uc = 0xfe;
22409 if (uc * uc < 0) /* this is true! */
22428 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
22438 (unsigned char) -12 / (signed char) -3 = ...
22441 No, the result is not 4:
22446 (int) (unsigned char) -12 / (int) (signed char) -3 =
22448 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
22450 (int) 0x00f4 / (int) 0xfffd =
22452 (int) 0x00f4 / (int) 0xfffd =
22454 (int) 244 / (int) -3 =
22456 (int) -81 = (int) 0xffaf;
22459 Don't complain, that gcc gives you a different result.
22460 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
22461 Therefore the results are different.
22464 \begin_inset Quotes sld
22468 \begin_inset Quotes srd
22474 If well-defined overflow characteristics are important and negative values
22475 are not, or if you want to steer clear of sign-extension problems when
22476 manipulating bits or bytes, use one of the corresponding unsigned types.
22477 (Beware when mixing signed and unsigned values in expressions, though.)
22479 Although character types (especially unsigned char) can be used as "tiny"
22480 integers, doing so is sometimes more trouble than it's worth, due to unpredicta
22481 ble sign extension and increased code size.
22485 Use unsigned when it is known in advance that the value is not going to
22487 This helps especially if you are doing division or multiplication, bit-shifting
22488 or are using an array index.
22491 NEVER jump into a LOOP.
22494 Declare the variables to be local
22495 \begin_inset LatexCommand \index{local variables}
22499 whenever possible, especially loop control variables (induction).
22502 Since the compiler does not always do implicit integral promotion, the programme
22503 r should do an explicit cast when integral promotion is required.
22506 Reducing the size of division, multiplication & modulus operations can reduce
22507 code size substantially.
22508 Take the following code for example.
22514 foobar(unsigned int p1, unsigned char ch)
22522 unsigned char ch1 = p1 % ch ;
22533 For the modulus operation the variable ch will be promoted to unsigned int
22534 first then the modulus operation will be performed (this will lead to a
22535 call to support routine _moduint()), and the result will be casted to a
22537 If the code is changed to
22542 foobar(unsigned int p1, unsigned char ch)
22550 unsigned char ch1 = (unsigned char)p1 % ch ;
22561 It would substantially reduce the code generated (future versions of the
22562 compiler will be smart enough to detect such optimization opportunities).
22566 Have a look at the assembly listing to get a
22567 \begin_inset Quotes sld
22571 \begin_inset Quotes srd
22574 for the code generation.
22577 Porting code from or to other compilers
22580 check whether endianness of the compilers differs and adapt where needed.
22583 check the device specific header files for compiler specific syntax.
22584 Eventually include the file <compiler.h
22585 \begin_inset LatexCommand \index{compiler.h (include file)}
22589 > to allow using common header files.
22592 check whether the startup code contains the correct initialization (watchdog,
22596 check whether the sizes of short, int, long match.
22599 check if some 16 or 32 bit hardware registers require a specific addressing
22600 order (least significant or most significant byte first) and adapt if needed
22609 relate to time and not to lower/upper memory location here, so this is
22614 the same as endianness).check whether the keyword
22618 is used where needed.
22619 The compilers might differ in their optimization characteristics (as different
22620 versions of the same compiler might also use more clever optimizations
22621 this is good idea anyway).
22624 check that the compilers are not told to supress warnings.
22627 check and convert compiler specific extensions (interrupts, memory areas,
22631 check for differences in type promotion (especially check for math operations
22632 on char variables and for the use of the ~\SpecialChar ~
22633 operator on bit variables.
22635 \begin_inset LatexCommand \ref{type promotion}
22640 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
22647 check the assembly code generated for interrupt routines (f.e.
22648 for calls to possibly non-reentrant library functions).
22651 check whether timing loops result in proper timing (or preferably consider
22652 a rewrite of the code with timer based delays instead).
22655 check for differences in printf parameters (some compilers push (va_arg)
22656 char variables as integers others as char).
22659 check the resulting memory layout.
22663 \begin_inset LatexCommand \index{Tools}
22667 included in the distribution
22671 \begin_inset Tabular
22672 <lyxtabular version="3" rows="12" columns="3">
22674 <column alignment="left" valignment="top" leftline="true" width="0pt">
22675 <column alignment="left" valignment="top" leftline="true" width="0pt">
22676 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22677 <row topline="true" bottomline="true">
22678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22703 <row topline="true">
22704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22717 Simulator for various architectures
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22729 <row topline="true">
22730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22743 header file conversion
22746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22751 sdcc/support/scripts
22755 <row topline="true">
22756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22769 header file conversion
22772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 sdcc/support/scripts
22781 <row topline="true">
22782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22816 <row topline="true">
22817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22851 <row topline="true">
22852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22886 <row topline="true">
22887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22921 <row topline="true">
22922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22956 <row topline="true">
22957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22991 <row topline="true">
22992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23026 <row topline="true" bottomline="true">
23027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23071 \begin_inset LatexCommand \index{Documentation}
23075 included in the distribution
23079 \begin_inset Tabular
23080 <lyxtabular version="3" rows="10" columns="2">
23082 <column alignment="left" valignment="top" leftline="true" width="0">
23083 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23084 <row topline="true" bottomline="true">
23085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23098 Where to get / filename
23102 <row topline="true">
23103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23108 SDCC Compiler User Guide
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23116 You're reading it right now
23120 <row topline="true">
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23138 <row topline="true">
23139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23145 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
23150 \begin_inset LatexCommand \index{Assembler documentation}
23154 Assemblers and ASLINK
23155 \begin_inset LatexCommand \index{aslink}
23160 \begin_inset LatexCommand \index{Linker documentation}
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23172 sdcc/as/doc/asxhtm.html
23176 <row topline="true">
23177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23182 SDCC regression test
23183 \begin_inset LatexCommand \index{Regression test}
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23195 sdcc/doc/test_suite_spec.pdf
23199 <row topline="true">
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">
23223 Notes on debugging with sdcdb
23224 \begin_inset LatexCommand \index{sdcdb (debugger)}
23231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23236 sdcc/debugger/README
23240 <row topline="true">
23241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23246 Software simulator for microcontrollers
23249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23276 <row topline="true">
23277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23282 Temporary notes on the pic16
23283 \begin_inset LatexCommand \index{PIC16}
23290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23295 sdcc/src/pic16/NOTES
23299 <row topline="true" bottomline="true">
23300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23305 SDCC internal documentation (debugging file format)
23308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23344 Related open source tools
23345 \begin_inset LatexCommand \index{Related tools}
23353 \begin_inset Tabular
23354 <lyxtabular version="3" rows="13" columns="3">
23356 <column alignment="left" valignment="top" leftline="true" width="0pt">
23357 <column alignment="block" valignment="top" leftline="true" width="30line%">
23358 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
23359 <row topline="true" bottomline="true">
23360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23385 <row topline="true">
23386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23392 \begin_inset LatexCommand \index{gpsim (pic simulator)}
23399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23413 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
23421 <row topline="true">
23422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23428 \begin_inset LatexCommand \index{gputils (pic tools)}
23435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23449 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23457 <row topline="true">
23458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23480 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
23488 <row topline="true">
23489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23502 Tools for Silicon Laboratories JTAG debug adapter, partly based on sdcdb
23506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23512 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
23520 <row topline="true">
23521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23527 \begin_inset LatexCommand \index{indent (source formatting tool)}
23534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23539 Formats C source - Master of the white spaces
23542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23548 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
23556 <row topline="true">
23557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23563 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
23570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23575 Object file conversion, checksumming, ...
23578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23584 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
23592 <row topline="true">
23593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23599 \begin_inset LatexCommand \index{objdump (tool)}
23606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23611 Object file conversion, ...
23614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23619 Part of binutils (should be there anyway)
23623 <row topline="true">
23624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23630 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
23637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23642 Source code documentation system
23645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23651 \begin_inset LatexCommand \url{http://www.doxygen.org}
23659 <row topline="true">
23660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23673 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
23676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23682 \begin_inset LatexCommand \url{http://www.kdevelop.org}
23690 <row topline="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">
23704 8051 monitor (hex up-/download, single step, disassemble)
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23713 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
23721 <row topline="true">
23722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23728 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23740 Statically checks c sources (see
23741 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23754 \begin_inset LatexCommand \url{http://www.splint.org}
23762 <row topline="true" bottomline="true">
23763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23769 \begin_inset LatexCommand \index{ddd (debugger)}
23776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23781 Debugger, serves nicely as GUI to sdcdb
23782 \begin_inset LatexCommand \index{sdcdb (debugger)}
23789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23795 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
23812 Related documentation / recommended reading
23816 \begin_inset Tabular
23817 <lyxtabular version="3" rows="6" columns="3">
23819 <column alignment="center" valignment="top" leftline="true" width="0pt">
23820 <column alignment="block" valignment="top" leftline="true" width="30line%">
23821 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
23822 <row topline="true" bottomline="true">
23823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23848 <row topline="true">
23849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23872 \begin_inset LatexCommand \index{C Reference card}
23879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23885 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
23893 <row topline="true">
23894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23916 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
23924 <row topline="true">
23925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23937 Latest datasheet of the target CPU
23940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23949 <row topline="true">
23950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23962 Revision history of datasheet
23965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23974 <row topline="true" bottomline="true">
23975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23990 Advanced Compiler Design and Implementation
23993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23998 bookstore (very dedicated, probably read other books first)
24014 Some questions answered, some pointers given - it might be time to in turn
24022 can you solve your project with the selected microcontroller? Would you
24023 find out early or rather late that your target is too small/slow/whatever?
24024 Can you switch to a slightly better device if it doesn't fit?
24027 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
24028 and/or another programming language be more adequate? Would an operating
24029 system on the target device help?
24032 if you solved the problem, will the marketing department be happy?
24035 if the marketing department is happy, will customers be happy?
24038 if you're the project manager, marketing department and maybe even the customer
24039 in one person, have you tried to see the project from the outside?
24042 is the project done if you think it is done? Or is just that other interface/pro
24043 tocol/feature/configuration/option missing? How about website, manual(s),
24044 internationali(z|s)ation, packaging, labels, 2nd source for components,
24045 electromagnetic compatability/interference, documentation for production,
24046 production test software, update mechanism, patent issues?
24049 is your project adequately positioned in that magic triangle: fame, fortune,
24053 Maybe not all answers to these questions are known and some answers may
24058 , nevertheless knowing these questions may help you to avoid burnout
24064 burnout is bad for electronic devices, programmers and motorcycle tyres
24068 Chances are you didn't want to hear some of them...
24072 \begin_inset LatexCommand \index{Support}
24079 SDCC has grown to be a large project.
24080 The compiler alone (without the preprocessor, assembler and linker) is
24081 well over 100,000 lines of code (blank stripped).
24082 The open source nature of this project is a key to its continued growth
24084 You gain the benefit and support of many active software developers and
24086 Is SDCC perfect? No, that's why we need your help.
24087 The developers take pride in fixing reported bugs.
24088 You can help by reporting the bugs and helping other SDCC users.
24089 There are lots of ways to contribute, and we encourage you to take part
24090 in making SDCC a great software package.
24094 The SDCC project is hosted on the SDCC sourceforge site at
24095 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
24100 You'll find the complete set of mailing lists
24101 \begin_inset LatexCommand \index{Mailing list(s)}
24105 , forums, bug reporting system, patch submission
24106 \begin_inset LatexCommand \index{Patch submission}
24111 \begin_inset LatexCommand \index{download}
24115 area and Subversion code repository
24116 \begin_inset LatexCommand \index{Subversion code repository}
24124 \begin_inset LatexCommand \index{Bug reporting}
24129 \begin_inset LatexCommand \index{Reporting bugs}
24136 The recommended way of reporting bugs is using the infrastructure of the
24138 You can follow the status of bug reports there and have an overview about
24142 Bug reports are automatically forwarded to the developer mailing list and
24143 will be fixed ASAP.
24144 When reporting a bug, it is very useful to include a small test program
24145 (the smaller the better) which reproduces the problem.
24146 If you can isolate the problem by looking at the generated assembly code,
24147 this can be very helpful.
24148 Compiling your program with the -
24159 \begin_inset LatexCommand \index{-\/-dumpall}
24163 option can sometimes be useful in locating optimization problems.
24164 When reporting a bug please maker sure you:
24167 Attach the code you are compiling with SDCC.
24171 Specify the exact command you use to run SDCC, or attach your Makefile.
24175 Specify the SDCC version (type "
24181 "), your platform, and operating system.
24185 Provide an exact copy of any error message or incorrect output.
24189 Put something meaningful in the subject of your message.
24192 Please attempt to include these 5 important parts, as applicable, in all
24193 requests for support or when reporting any problems or bugs with SDCC.
24194 Though this will make your message lengthy, it will greatly improve your
24195 chance that SDCC users and developers will be able to help you.
24196 Some SDCC developers are frustrated by bug reports without code provided
24197 that they can use to reproduce and ultimately fix the problem, so please
24198 be sure to provide sample code if you are reporting a bug!
24201 Please have a short check that you are using a recent version of SDCC and
24202 the bug is not yet known.
24203 This is the link for reporting bugs:
24204 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
24211 Requesting Features
24212 \begin_inset LatexCommand \label{sub:Requesting-Features}
24217 \begin_inset LatexCommand \index{Feature request}
24222 \begin_inset LatexCommand \index{Requesting features}
24229 Like bug reports feature requests are forwarded to the developer mailing
24231 This is the link for requesting features:
24232 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24242 Like bug reports contributed patches are forwarded to the developer mailing
24244 This is the link for submitting patches
24245 \begin_inset LatexCommand \index{Patch submission}
24250 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
24257 You need to specify some parameters to the
24261 command for the patches to be useful.
24262 If you modified more than one file a patch created f.e.
24267 \begin_inset Quotes sld
24270 diff -Naur unmodified_directory modified_directory >my_changes.patch
24271 \begin_inset Quotes srd
24277 will be fine, otherwise
24281 \begin_inset Quotes sld
24284 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
24285 \begin_inset Quotes srd
24298 These links should take you directly to the
24299 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
24309 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
24310 automated messages (mid 2003)
24314 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
24319 \begin_inset LatexCommand \index{Mailing list(s)}
24323 and forums are archived and searchable so if you are lucky someone already
24324 had a similar problem.
24325 While mails to the lists themselves are delivered promptly their web front
24326 end on sourceforge sometimes shows a severe time lag (up to several weeks),
24327 if you're seriously using SDCC please consider subscribing to the lists.
24333 You can follow the status of the Subversion version
24334 \begin_inset LatexCommand \index{version}
24338 of SDCC by watching the Changelog
24339 \begin_inset LatexCommand \index{Changelog}
24343 in the Subversion repository
24346 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
24353 Subversion Source Code Repository
24362 or the filenames of the snapshot versions of SDCC include date and its
24364 \begin_inset LatexCommand \index{Subversion}
24369 Subversion allows to download the source of recent or previous versions
24371 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
24375 (by number or by date).
24376 An on-line source code browser and detailled instructions are also available
24378 SDCC versions starting from 1999 up to now are available (currently the
24379 versions prior to the conversion from cvs to Subversion (April 2006) are
24380 either by accessible by Subversion or by cvs).
24384 \begin_inset LatexCommand \index{Release policy}
24391 Historically there often were long delays between official releases and
24392 the sourceforge download area tends to get not updated at all.
24393 Excuses in the past might have referred to problems with live range analysis,
24394 but as this was fixed a while ago, the current problem is that another
24395 excuse has to be found.
24396 Kidding aside, we have to get better there! On the other hand there are
24397 daily snapshots available at
24398 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
24402 , and you can always build the very last version (hopefully with many bugs
24403 fixed, and features added) from the source code available at
24404 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
24412 \begin_inset LatexCommand \index{Examples}
24419 You'll find some small examples in the directory
24421 sdcc/device/examples/.
24424 More examples and libraries are available at
24426 The SDCC Open Knowledge Resource
24427 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
24434 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
24441 I did insert a reference to Paul's web site here although it seems rather
24442 dedicated to a specific 8032 board (I think it's okay because it f.e.
24443 shows LCD/Harddisc interface and has a free 8051 monitor.
24444 Independent 8032 board vendors face hard competition of heavily subsidized
24445 development boards anyway).
24448 Maybe we should include some links to real world applications.
24449 Preferably pointer to pointers (one for each architecture) so this stays
24454 \begin_inset LatexCommand \index{Quality control}
24461 The compiler is passed through nightly compile and build checks.
24467 \begin_inset LatexCommand \index{Regression test}
24471 check that SDCC itself compiles flawlessly on several platforms and checks
24472 the quality of the code generated by SDCC by running the code through simulator
24474 There is a separate document
24477 \begin_inset LatexCommand \index{Test suite}
24486 You'll find the test code in the directory
24488 sdcc/support/regression
24491 You can run these tests manually by running
24495 in this directory (or f.e.
24500 \begin_inset Quotes sld
24504 \begin_inset Quotes srd
24510 if you don't want to run the complete tests).
24511 The test code might also be interesting if you want to look for examples
24512 \begin_inset LatexCommand \index{Examples}
24516 checking corner cases of SDCC or if you plan to submit patches
24517 \begin_inset LatexCommand \index{Patch submission}
24524 The pic port uses a different set of regression tests, you'll find them
24527 sdcc/src/regression
24532 Use of SDCC in Education
24545 the phrase "use in education" might evoke the association "
24549 fit for use in education".
24550 This connotation is not intended but nevertheless risked as the licensing
24551 of SDCC makes it difficult to offer educational discounts
24555 If your rationales are to:
24558 give students a chance to understand the
24562 steps of code generation
24565 have a curriculum that can be extended for years.
24566 Then you could use an fpga board as target and your curriculum will seamlessly
24567 extend from logic synthesis (
24568 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
24573 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
24577 ), over assembly programming, to C to FPGA compilers (
24578 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
24585 be able to insert excursions about skills like using a revision control
24586 system, submitting/applying patches, using a type-setting (as opposed to
24587 word-processing) engine LyX/LaTeX, using
24588 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
24593 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
24597 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
24598 Source Software, CPU simulation, compiler regression tests
24599 \begin_inset LatexCommand \index{Regression test}
24606 And if there should be a shortage of ideas then you can always point students
24607 to the ever-growing feature request list
24608 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
24615 not tie students to a specific host platform and instead allow them to use
24620 choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
24622 \begin_inset LatexCommand \url[OLPC]{http://wiki.laptop.org/wiki/One_Laptop_per_Child}
24629 not encourage students to use illegal copies of educational software
24632 be immune to licensing/availability/price changes of the chosen tool chain
24635 be able to change to a new target platform without having to adopt a new
24639 have complete control over and insight into the tool chain
24642 make your students aware about the pros and cons of open source software
24646 give back to the public as you are probably at least partially publically
24650 give students a chance to publically prove their skills and to possibly
24651 see a world wide impact
24654 then SDCC is probably among the first choices.
24655 Well, probably SDCC might be the only choice.
24658 SDCC Technical Data
24662 \begin_inset LatexCommand \index{Optimizations}
24669 SDCC performs a host of standard optimizations in addition to some MCU specific
24674 Sub-expression Elimination
24675 \begin_inset LatexCommand \index{Subexpression elimination}
24682 The compiler does local and
24708 will be translated to
24720 Some subexpressions are not as obvious as the above example, e.g.:
24730 In this case the address arithmetic a->b[i] will be computed only once;
24731 the equivalent code in C would be.
24743 The compiler will try to keep these temporary variables in registers.
24746 Dead-Code Elimination
24747 \begin_inset LatexCommand \index{Dead-code elimination}
24768 i = 1; \SpecialChar ~
24777 global = 1;\SpecialChar ~
24790 global = 3;\SpecialChar ~
24815 \begin_inset LatexCommand \index{Copy propagation}
24871 Note: the dead stores created by this copy propagation will be eliminated
24872 by dead-code elimination.
24876 \begin_inset LatexCommand \index{Loop optimization}
24881 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
24888 Two types of loop optimizations are done by SDCC
24896 of loop induction variables.
24897 In addition to the strength reduction the optimizer marks the induction
24898 variables and the register allocator tries to keep the induction variables
24899 in registers for the duration of the loop.
24900 Because of this preference of the register allocator
24901 \begin_inset LatexCommand \index{Register allocation}
24905 , loop induction optimization causes an increase in register pressure, which
24906 may cause unwanted spilling of other temporary variables into the stack
24907 \begin_inset LatexCommand \index{stack}
24912 The compiler will generate a warning message when it is forced to allocate
24913 extra space either on the stack or data space.
24914 If this extra space allocation is undesirable then induction optimization
24915 can be eliminated either for the entire source file (with -
24925 -noinduction option) or for a given function only using #pragma\SpecialChar ~
24927 \begin_inset LatexCommand \index{\#pragma noinduction}
24940 for (i = 0 ; i < 100 ; i ++)
24956 for (i = 0; i < 100; i++)
24965 As mentioned previously some loop invariants are not as apparent, all static
24966 address computations are also moved out of the loop.
24971 \begin_inset LatexCommand \index{Strength reduction}
24975 , this optimization substitutes an expression by a cheaper expression:
24980 for (i=0;i < 100; i++)
24998 for (i=0;i< 100;i++) {
25004 ar[itemp1] = itemp2;
25021 The more expensive multiplication
25022 \begin_inset LatexCommand \index{Multiplication}
25026 is changed to a less expensive addition.
25030 \begin_inset LatexCommand \index{Loop reversing}
25037 This optimization is done to reduce the overhead of checking loop boundaries
25038 for every iteration.
25039 Some simple loops can be reversed and implemented using a
25040 \begin_inset Quotes eld
25043 decrement and jump if not zero
25044 \begin_inset Quotes erd
25048 SDCC checks for the following criterion to determine if a loop is reversible
25049 (note: more sophisticated compilers use data-dependency analysis to make
25050 this determination, SDCC uses a more simple minded analysis).
25053 The 'for' loop is of the form
25059 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
25069 The <for body> does not contain
25070 \begin_inset Quotes eld
25074 \begin_inset Quotes erd
25078 \begin_inset Quotes erd
25084 All goto's are contained within the loop.
25087 No function calls within the loop.
25090 The loop control variable <sym> is not assigned any value within the loop
25093 The loop control variable does NOT participate in any arithmetic operation
25097 There are NO switch statements in the loop.
25100 Algebraic Simplifications
25103 SDCC does numerous algebraic simplifications, the following is a small sub-set
25104 of these optimizations.
25109 i = j + 0;\SpecialChar ~
25113 /* changed to: */\SpecialChar ~
25119 i /= 2;\SpecialChar ~
25126 /* changed to: */\SpecialChar ~
25132 i = j - j;\SpecialChar ~
25136 /* changed to: */\SpecialChar ~
25142 i = j / 1;\SpecialChar ~
25146 /* changed to: */\SpecialChar ~
25153 Note the subexpressions
25154 \begin_inset LatexCommand \index{Subexpression}
25158 given above are generally introduced by macro expansions or as a result
25159 of copy/constant propagation.
25162 'switch' Statements
25163 \begin_inset LatexCommand \label{sub:'switch'-Statements}
25168 \begin_inset LatexCommand \index{switch statement}
25175 SDCC can optimize switch statements to jump tables
25176 \begin_inset LatexCommand \index{jump tables}
25181 It makes the decision based on an estimate of the generated code size.
25182 SDCC is quite liberal in the requirements for jump table generation:
25185 The labels need not be in order, and the starting number need not be one
25186 or zero, the case labels are in numerical sequence or not too many case
25187 labels are missing.
25193 switch(i) {\SpecialChar ~
25224 case 4: ...\SpecialChar ~
25256 case 5: ...\SpecialChar ~
25288 case 3: ...\SpecialChar ~
25319 case 6: ...\SpecialChar ~
25351 case 7: ...\SpecialChar ~
25383 case 8: ...\SpecialChar ~
25415 case 9: ...\SpecialChar ~
25447 case 10: ...\SpecialChar ~
25478 case 11: ...\SpecialChar ~
25545 Both the above switch statements will be implemented using a jump-table.
25546 The example to the right side is slightly more efficient as the check for
25547 the lower boundary of the jump-table is not needed.
25551 The number of case labels is not larger than supported by the target architectur
25555 If the case labels are not in numerical sequence ('gaps' between cases)
25556 SDCC checks whether a jump table with additionally inserted dummy cases
25557 is still attractive.
25561 If the starting number is not zero and a check for the lower boundary of
25562 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
25567 Switch statements which have large gaps in the numeric sequence or those
25568 that have too many case labels can be split into more than one switch statement
25569 for efficient code generation, e.g.:
25649 If the above switch statement is broken down into two switch statements
25739 then both the switch statements will be implemented using jump-tables whereas
25740 the unmodified switch statement will not be.
25743 There might be reasons which SDCC cannot know about to either favour or
25744 not favour jump tables.
25745 If the target system has to be as quick for the last switch case as for
25746 the first (pro jump table), or if the switch argument is known to be zero
25747 in the majority of the cases (contra jump table).
25750 The pragma nojtbound
25751 \begin_inset LatexCommand \index{\#pragma nojtbound}
25755 can be used to turn off checking the
25768 It has no effect if a default label is supplied.
25769 Use of this pragma is dangerous: if the switch
25770 \begin_inset LatexCommand \index{switch statement}
25774 argument is not matched by a case statement the processor will happily
25778 Bit-shifting Operations
25779 \begin_inset LatexCommand \index{Bit shifting}
25786 Bit shifting is one of the most frequently used operation in embedded programmin
25788 SDCC tries to implement bit-shift operations in the most efficient way
25804 generates the following code:
25821 In general SDCC will never setup a loop if the shift count is known.
25864 \begin_inset LatexCommand \index{Bit rotation}
25871 A special case of the bit-shift operation is bit rotation
25872 \begin_inset LatexCommand \index{rotating bits}
25876 , SDCC recognizes the following expression to be a left bit-rotation:
25886 char i;\SpecialChar ~
25897 /* unsigned is needed for rotation */
25902 i = ((i << 1) | (i >> 7));
25911 will generate the following code:
25930 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
25931 ns of this case will also be recognized as bit-rotation, i.e.:
25936 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
25939 Nibble and Byte Swapping
25942 Other special cases of the bit-shift operations are nibble or byte swapping
25943 \begin_inset LatexCommand \index{swapping nibbles/bytes}
25947 , SDCC recognizes the following expressions:
25970 i = ((i << 4) | (i >> 4));
25976 j = ((j << 8) | (j >> 8));
25979 and generates a swap instruction for the nibble swapping
25980 \begin_inset LatexCommand \index{Nibble swapping}
25984 or move instructions for the byte swapping
25985 \begin_inset LatexCommand \index{Byte swapping}
25991 \begin_inset Quotes sld
25995 \begin_inset Quotes srd
25998 example can be used to convert from little to big-endian or vice versa.
25999 If you want to change the endianness of a
26003 integer you have to cast to
26010 Note that SDCC stores numbers in little-endian
26016 Usually 8-bit processors don't care much about endianness.
26017 This is not the case for the standard 8051 which only has an instruction
26023 \begin_inset LatexCommand \index{DPTR}
26031 so little-endian is the more efficient byte order.
26035 \begin_inset LatexCommand \index{little-endian}
26040 \begin_inset LatexCommand \index{Endianness}
26045 lowest order first).
26049 \begin_inset LatexCommand \index{Highest Order Bit}
26054 \begin_inset LatexCommand \index{Any Order Bit}
26061 It is frequently required to obtain the highest order bit of an integral
26062 type (long, int, short or char types).
26063 Also obtaining any other order bit is not uncommon.
26064 SDCC recognizes the following expressions to yield the highest order bit
26065 and generates optimized code for it, e.g.:
26078 unsigned char hob1, aob1;
26082 bit hob2, hob3, aob2, aob3;
26091 hob1 = (gint >> 15) & 1;
26095 hob2 = (gint >> 15) & 1;
26099 hob3 = gint & 0x8000;
26103 aob1 = (gint >> 9) & 1;
26107 aob2 = (gint >> 8) & 1;
26111 aob3 = gint & 0x0800;
26121 will generate the following code:
26154 000A E5*01\SpecialChar ~
26181 000C 23\SpecialChar ~
26212 000D 54 01\SpecialChar ~
26239 000F F5*02\SpecialChar ~
26294 0011 E5*01\SpecialChar ~
26321 0013 33\SpecialChar ~
26351 0014 92*00\SpecialChar ~
26406 0016 E5*01\SpecialChar ~
26433 0018 33\SpecialChar ~
26463 0019 92*01\SpecialChar ~
26518 001B E5*01\SpecialChar ~
26545 001D 03\SpecialChar ~
26576 001E 54 01\SpecialChar ~
26603 0020 F5*03\SpecialChar ~
26658 0022 E5*01\SpecialChar ~
26685 0024 13\SpecialChar ~
26715 0025 92*02\SpecialChar ~
26770 0027 E5*01\SpecialChar ~
26797 0029 A2 E3\SpecialChar ~
26824 002B 92*03\SpecialChar ~
26852 Other variations of these cases however will
26857 They are standard C expressions, so I heartily recommend these be the only
26858 way to get the highest order bit, (it is portable).
26859 Of course it will be recognized even if it is embedded in other expressions,
26865 xyz = gint + ((gint >> 15) & 1);
26868 will still be recognized.
26872 \begin_inset LatexCommand \index{Higher Order Byte}
26876 / Higher Order Word
26877 \begin_inset LatexCommand \index{Higher Order Word}
26884 It is also frequently required to obtain a higher order byte or word of
26885 a larger integral type (long, int or short types).
26886 SDCC recognizes the following expressions to yield the higher order byte
26887 or word and generates optimized code for it, e.g.:
26894 unsigned long int glong;
26902 unsigned char hob1, hob2;
26906 unsigned int how1, how2;
26915 hob1 = (gint >> 8) & 0xFF;
26919 hob2 = glong >> 24;
26923 how1 = (glong >> 16) & 0xFFFF;
26937 will generate the following code:
26970 0037 85*01*06\SpecialChar ~
26992 _foo_hob1_1_1,(_gint + 1)
27022 003A 85*05*07\SpecialChar ~
27044 _foo_hob2_1_1,(_glong + 3)
27074 003D 85*04*08\SpecialChar ~
27096 _foo_how1_1_1,(_glong + 2)
27098 0040 85*05*09\SpecialChar ~
27120 (_foo_how1_1_1 + 1),(_glong + 3)
27122 0043 85*03*0A\SpecialChar ~
27144 _foo_how2_1_1,(_glong + 1)
27146 0046 85*04*0B\SpecialChar ~
27168 (_foo_how2_1_1 + 1),(_glong + 2)
27171 Again, variations of these cases may
27176 They are standard C expressions, so I heartily recommend these be the only
27177 way to get the higher order byte/word, (it is portable).
27178 Of course it will be recognized even if it is embedded in other expressions,
27184 xyz = gint + ((gint >> 8) & 0xFF);
27187 will still be recognized.
27191 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
27196 \begin_inset LatexCommand \index{Peephole optimizer}
27203 The compiler uses a rule based, pattern matching and re-writing mechanism
27204 for peep-hole optimization.
27209 a peep-hole optimizer by Christopher W.
27210 Fraser (cwfraser\SpecialChar ~
27213 A default set of rules are compiled into the compiler, additional rules
27214 may be added with the
27227 \begin_inset LatexCommand \index{-\/-peep-file}
27234 The rule language is best illustrated with examples.
27258 The above rule will change the following assembly
27259 \begin_inset LatexCommand \index{Assembler routines}
27281 Note: All occurrences of a
27285 (pattern variable) must denote the same string.
27286 With the above rule, the assembly sequence:
27296 will remain unmodified.
27300 Other special case optimizations may be added by the user (via
27316 some variants of the 8051 MCU
27317 \begin_inset LatexCommand \index{MCS51 variants}
27330 The following two rules will change all
27349 replace { lcall %1 } by { acall %1 }
27351 replace { ljmp %1 } by { ajmp %1 }
27356 inline-assembler code
27358 is also passed through the peep hole optimizer, thus the peephole optimizer
27359 can also be used as an assembly level macro expander.
27360 The rules themselves are MCU dependent whereas the rule language infra-structur
27361 e is MCU independent.
27362 Peephole optimization rules for other MCU can be easily programmed using
27367 The syntax for a rule is as follows:
27372 rule := replace [ restart ] '{' <assembly sequence> '
27410 <assembly sequence> '
27428 '}' [if <functionName> ] '
27433 <assembly sequence> := assembly instruction (each instruction including
27434 labels must be on a separate line).
27438 The optimizer will apply to the rules one by one from the top in the sequence
27439 of their appearance, it will terminate when all rules are exhausted.
27440 If the 'restart' option is specified, then the optimizer will start matching
27441 the rules again from the top, this option for a rule is expensive (performance)
27442 , it is intended to be used in situations where a transformation will trigger
27443 the same rule again.
27444 An example of this (not a good one, it has side effects) is the following
27467 Note that the replace pattern cannot be a blank, but can be a comment line.
27468 Without the 'restart' option only the innermost 'pop' 'push' pair would
27469 be eliminated, i.e.:
27499 the restart option the rule will be applied again to the resulting code
27500 and then all the pop-push pairs will be eliminated to yield:
27510 A conditional function can be attached to a rule.
27511 Attaching rules are somewhat more involved, let me illustrate this with
27538 The optimizer does a look-up of a function name table defined in function
27543 in the source file SDCCpeeph.c, with the name
27548 If it finds a corresponding entry the function is called.
27549 Note there can be no parameters specified for these functions, in this
27554 is crucial, since the function
27558 expects to find the label in that particular variable (the hash table containin
27559 g the variable bindings is passed as a parameter).
27560 If you want to code more such functions, take a close look at the function
27561 labelInRange and the calling mechanism in source file SDCCpeeph.c.
27562 Currently implemented are
27564 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
27565 24bitMode, portIsDS390, 24bitModeAndPortDS390
27574 I know this whole thing is a little kludgey, but maybe some day we will
27575 have some better means.
27576 If you are looking at this file, you will see the default rules that are
27577 compiled into the compiler, you can add your own rules in the default set
27578 there if you get tired of specifying the -
27592 \begin_inset LatexCommand \index{ANSI-compliance}
27597 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
27604 Deviations from the compliance:
27607 functions are not reentrant
27608 \begin_inset LatexCommand \index{reentrant}
27612 unless explicitly declared as such or the
27625 \begin_inset LatexCommand \index{-\/-stack-auto}
27631 command line option is specified.
27634 structures and unions cannot be assigned values directly, cannot be passed
27635 as function parameters or assigned to each other and cannot be a return
27636 value from a function, e.g.:
27662 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
27673 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
27695 return rets;/* is invalid in SDCC although allowed in ANSI */
27701 initialization of structure arrays must be fully braced.
27707 struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
27709 struct s { char x } a[] = {{1}, {2}}; /* OK */
27714 \begin_inset LatexCommand \index{long long (not supported)}
27719 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
27727 \begin_inset LatexCommand \index{double (not supported)}
27731 ' precision floating point
27732 \begin_inset LatexCommand \index{Floating point support}
27740 \begin_inset LatexCommand \index{K\&R style}
27744 function declarations are NOT allowed.
27750 foo(i,j) /* this old style of function declarations */
27752 int i,j; /* are valid in ANSI but not valid in SDCC */
27767 Most enhancements in C99 are not supported, f.e.:
27776 int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
27783 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
27787 Certain words that are valid identifiers in the standard may be reserved
27788 words in SDCC unless the
27801 \begin_inset LatexCommand \index{-\/-std-c89}
27816 \begin_inset LatexCommand \index{-\/-std-c99}
27822 command line options are used.
27823 These may include (depending on the selected processor): 'at', 'banked',
27824 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
27825 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
27826 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
27828 Compliant equivalents of these keywords are always available in a form
27829 that begin with two underscores
27830 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
27835 '__data' instead of 'data'.
27838 Cyclomatic Complexity
27839 \begin_inset LatexCommand \index{Cyclomatic complexity}
27846 Cyclomatic complexity of a function is defined as the number of independent
27847 paths the program can take during execution of the function.
27848 This is an important number since it defines the number test cases you
27849 have to generate to validate the function.
27850 The accepted industry standard for complexity number is 10, if the cyclomatic
27851 complexity reported by SDCC exceeds 10 you should think about simplification
27852 of the function logic.
27853 Note that the complexity level is not related to the number of lines of
27854 code in a function.
27855 Large functions can have low complexity, and small functions can have large
27861 SDCC uses the following formula to compute the complexity:
27866 complexity = (number of edges in control flow graph) - (number of nodes
27867 in control flow graph) + 2;
27871 Having said that the industry standard is 10, you should be aware that in
27872 some cases it be may unavoidable to have a complexity level of less than
27874 For example if you have switch statement with more than 10 case labels,
27875 each case label adds one to the complexity level.
27876 The complexity level is by no means an absolute measure of the algorithmic
27877 complexity of the function, it does however provide a good starting point
27878 for which functions you might look at for further optimization.
27881 Retargetting for other Processors
27884 The issues for retargetting the compiler are far too numerous to be covered
27886 What follows is a brief description of each of the seven phases of the
27887 compiler and its MCU dependency.
27890 Parsing the source and building the annotated parse tree.
27891 This phase is largely MCU independent (except for the language extensions).
27892 Syntax & semantic checks are also done in this phase, along with some initial
27893 optimizations like back patching labels and the pattern matching optimizations
27894 like bit-rotation etc.
27897 The second phase involves generating an intermediate code which can be easy
27898 manipulated during the later phases.
27899 This phase is entirely MCU independent.
27900 The intermediate code generation assumes the target machine has unlimited
27901 number of registers, and designates them with the name iTemp.
27902 The compiler can be made to dump a human readable form of the code generated
27916 This phase does the bulk of the standard optimizations and is also MCU independe
27918 This phase can be broken down into several sub-phases:
27922 Break down intermediate code (iCode) into basic blocks.
27924 Do control flow & data flow analysis on the basic blocks.
27926 Do local common subexpression elimination, then global subexpression elimination
27928 Dead code elimination
27932 If loop optimizations caused any changes then do 'global subexpression eliminati
27933 on' and 'dead code elimination' again.
27936 This phase determines the live-ranges; by live range I mean those iTemp
27937 variables defined by the compiler that still survive after all the optimization
27939 Live range analysis
27940 \begin_inset LatexCommand \index{Live range analysis}
27944 is essential for register allocation, since these computation determines
27945 which of these iTemps will be assigned to registers, and for how long.
27948 Phase five is register allocation.
27949 There are two parts to this process.
27953 The first part I call 'register packing' (for lack of a better term).
27954 In this case several MCU specific expression folding is done to reduce
27959 The second part is more MCU independent and deals with allocating registers
27960 to the remaining live ranges.
27961 A lot of MCU specific code does creep into this phase because of the limited
27962 number of index registers available in the 8051.
27965 The Code generation phase is (unhappily), entirely MCU dependent and very
27966 little (if any at all) of this code can be reused for other MCU.
27967 However the scheme for allocating a homogenized assembler operand for each
27968 iCode operand may be reused.
27971 As mentioned in the optimization section the peep-hole optimizer is rule
27972 based system, which can reprogrammed for other MCUs.
27976 \begin_inset LatexCommand \index{Compiler internals}
27983 The anatomy of the compiler
27984 \begin_inset LatexCommand \label{sub:The-anatomy-of}
27993 This is an excerpt from an article published in Circuit Cellar Magazine
27999 It's a little outdated (the compiler is much more efficient now and user/develo
28000 per friendly), but pretty well exposes the guts of it all.
28006 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
28007 It is fairly easy to retarget for other 8-bit MCU.
28008 Here we take a look at some of the internals of the compiler.
28013 \begin_inset LatexCommand \index{Parsing}
28020 Parsing the input source file and creating an AST (Annotated Syntax Tree
28021 \begin_inset LatexCommand \index{Annotated syntax tree}
28026 This phase also involves propagating types (annotating each node of the
28027 parse tree with type information) and semantic analysis.
28028 There are some MCU specific parsing rules.
28029 For example the storage classes, the extended storage classes are MCU specific
28030 while there may be a xdata storage class for 8051 there is no such storage
28031 class for z80 or Atmel AVR.
28032 SDCC allows MCU specific storage class extensions, i.e.
28033 xdata will be treated as a storage class specifier when parsing 8051 C
28034 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
28039 \begin_inset LatexCommand \index{iCode}
28046 Intermediate code generation.
28047 In this phase the AST is broken down into three-operand form (iCode).
28048 These three operand forms are represented as doubly linked lists.
28049 ICode is the term given to the intermediate form generated by the compiler.
28050 ICode example section shows some examples of iCode generated for some simple
28051 C source functions.
28055 \begin_inset LatexCommand \index{Optimizations}
28062 Bulk of the target independent optimizations is performed in this phase.
28063 The optimizations include constant propagation, common sub-expression eliminati
28064 on, loop invariant code movement, strength reduction of loop induction variables
28065 and dead-code elimination.
28068 Live range analysis
28069 \begin_inset LatexCommand \index{Live range analysis}
28076 During intermediate code generation phase, the compiler assumes the target
28077 machine has infinite number of registers and generates a lot of temporary
28079 The live range computation determines the lifetime of each of these compiler-ge
28080 nerated temporaries.
28081 A picture speaks a thousand words.
28082 ICode example sections show the live range annotations for each of the
28084 It is important to note here, each iCode is assigned a number in the order
28085 of its execution in the function.
28086 The live ranges are computed in terms of these numbers.
28087 The from number is the number of the iCode which first defines the operand
28088 and the to number signifies the iCode which uses this operand last.
28091 Register Allocation
28092 \begin_inset LatexCommand \index{Register allocation}
28099 The register allocation determines the type and number of registers needed
28101 In most MCUs only a few registers can be used for indirect addressing.
28102 In case of 8051 for example the registers R0 & R1 can be used to indirectly
28103 address the internal ram and DPTR to indirectly address the external ram.
28104 The compiler will try to allocate the appropriate register to pointer variables
28106 ICode example section shows the operands annotated with the registers assigned
28108 The compiler will try to keep operands in registers as much as possible;
28109 there are several schemes the compiler uses to do achieve this.
28110 When the compiler runs out of registers the compiler will check to see
28111 if there are any live operands which is not used or defined in the current
28112 basic block being processed, if there are any found then it will push that
28113 operand and use the registers in this block, the operand will then be popped
28114 at the end of the basic block.
28118 There are other MCU specific considerations in this phase.
28119 Some MCUs have an accumulator; very short-lived operands could be assigned
28120 to the accumulator instead of a general-purpose register.
28126 Figure II gives a table of iCode operations supported by the compiler.
28127 The code generation involves translating these operations into corresponding
28128 assembly code for the processor.
28129 This sounds overly simple but that is the essence of code generation.
28130 Some of the iCode operations are generated on a MCU specific manner for
28131 example, the z80 port does not use registers to pass parameters so the
28132 SEND and RECV iCode operations will not be generated, and it also does
28133 not support JUMPTABLES.
28140 <Where is Figure II?>
28143 In the original article Figure II was announced to be downloadable on
28148 Unfortunately it never seemed to have shown up there, so: where is Figure
28153 \begin_inset LatexCommand \index{iCode}
28160 This section shows some details of iCode.
28161 The example C code does not do anything useful; it is used as an example
28162 to illustrate the intermediate code generated by the compiler.
28174 /* This function does nothing useful.
28181 for the purpose of explaining iCode */
28184 short function (data int *x)
28192 short i=10; \SpecialChar ~
28194 /* dead initialization eliminated */
28199 short sum=10; /* dead initialization eliminated */
28212 while (*x) *x++ = *p++;
28226 /* compiler detects i,j to be induction variables */
28230 for (i = 0, j = 10 ; i < 10 ; i++, j
28256 mul += i * 3; \SpecialChar ~
28258 /* this multiplication remains */
28264 gint += j * 3;\SpecialChar ~
28266 /* this multiplication changed to addition */
28280 In addition to the operands each iCode contains information about the filename
28281 and line it corresponds to in the source file.
28282 The first field in the listing should be interpreted as follows:
28287 Filename(linenumber: iCode Execution sequence number : ICode hash table
28288 key : loop depth of the iCode).
28293 Then follows the human readable form of the ICode operation.
28294 Each operand of this triplet form can be of three basic types a) compiler
28295 generated temporary b) user defined variable c) a constant value.
28296 Note that local variables and parameters are replaced by compiler generated
28299 \begin_inset LatexCommand \index{Live range analysis}
28303 are computed only for temporaries (i.e.
28304 live ranges are not computed for global variables).
28306 \begin_inset LatexCommand \index{Register allocation}
28310 are allocated for temporaries only.
28311 Operands are formatted in the following manner:
28316 Operand Name [lr live-from : live-to ] { type information } [ registers
28322 As mentioned earlier the live ranges are computed in terms of the execution
28323 sequence number of the iCodes, for example
28325 the iTemp0 is live from (i.e.
28326 first defined in iCode with execution sequence number 3, and is last used
28327 in the iCode with sequence number 5).
28328 For induction variables such as iTemp21 the live range computation extends
28329 the lifetime from the start to the end of the loop.
28331 The register allocator used the live range information to allocate registers,
28332 the same registers may be used for different temporaries if their live
28333 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
28334 iTemp17 since their live ranges do not overlap.
28335 In addition the allocator also takes into consideration the type and usage
28336 of a temporary, for example itemp6 is a pointer to near space and is used
28337 as to fetch data from (i.e.
28338 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
28339 Some short lived temporaries are allocated to special registers which have
28340 meaning to the code generator e.g.
28341 iTemp13 is allocated to a pseudo register CC which tells the back end that
28342 the temporary is used only for a conditional jump the code generation makes
28343 use of this information to optimize a compare and jump ICode.
28345 There are several loop optimizations
28346 \begin_inset LatexCommand \index{Loop optimization}
28350 performed by the compiler.
28351 It can detect induction variables iTemp21(i) and iTemp23(j).
28352 Also note the compiler does selective strength reduction
28353 \begin_inset LatexCommand \index{Strength reduction}
28358 the multiplication of an induction variable in line 18 (gint = j * 3) is
28359 changed to addition, a new temporary iTemp17 is allocated and assigned
28360 a initial value, a constant 3 is then added for each iteration of the loop.
28361 The compiler does not change the multiplication
28362 \begin_inset LatexCommand \index{Multiplication}
28366 in line 17 however since the processor does support an 8 * 8 bit multiplication.
28368 Note the dead code elimination
28369 \begin_inset LatexCommand \index{Dead-code elimination}
28373 optimization eliminated the dead assignments in line 7 & 8 to I and sum
28381 Sample.c (5:1:0:0) _entry($9) :
28386 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
28391 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
28396 Sample.c(11:4:53:0) preHeaderLbl0($11) :
28401 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
28407 Sample.c(11:6:5:1) _whilecontinue_0($1) :
28412 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
28418 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28423 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
28429 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
28435 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
28441 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
28447 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
28448 * int}[r0] + 0x2 {short}
28453 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
28458 Sample.c(11:17:21:0)_whilebreak_0($3) :
28463 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
28468 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
28473 Sample.c(15:20:54:0)preHeaderLbl1($13) :
28478 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
28483 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
28488 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
28493 Sample.c(15:24:26:1)_forcond_0($4) :
28498 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
28504 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
28509 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
28510 + ITemp21 [lr21:38]{short}[r4]
28515 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
28521 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
28522 + iTemp15 [lr29:30]{short}[r1]
28527 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
28533 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
28539 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
28545 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
28551 Sample.c(19:38:47:1) goto _forcond_0($4)
28556 Sample.c(19:39:48:0)_forbreak_0($7) :
28561 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
28562 + ITemp11 [lr19:40]{short}[r3]
28567 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
28572 Sample.c(20:42:51:0)_return($8) :
28577 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
28583 Finally the code generated for this function:
28624 ; ----------------------------------------------
28629 ; function function
28634 ; ----------------------------------------------
28644 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
28656 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
28668 ;_whilecontinue_0($1) :
28678 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
28683 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
28742 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
28761 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
28808 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
28848 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
28874 ; iTemp6 [lr5:16]{_near * int}[r0] =
28879 ; iTemp6 [lr5:16]{_near * int}[r0] +
28896 ; goto _whilecontinue_0($1)
28908 ; _whilebreak_0($3) :
28918 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
28930 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
28942 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
28954 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
28973 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
29002 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
29007 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
29052 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
29057 ; iTemp21 [lr21:38]{short}[r4]
29083 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
29116 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
29121 ; iTemp15 [lr29:30]{short}[r1]
29140 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
29187 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
29234 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
29246 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
29260 cjne r5,#0xff,00104$
29272 ; goto _forcond_0($4)
29284 ; _forbreak_0($7) :
29294 ; ret iTemp24 [lr40:41]{short}
29337 A few words about basic block successors, predecessors and dominators
29340 Successors are basic blocks
29341 \begin_inset LatexCommand \index{Basic blocks}
29345 that might execute after this basic block.
29347 Predecessors are basic blocks that might execute before reaching this basic
29350 Dominators are basic blocks that WILL execute before reaching this basic
29384 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
29387 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
29390 c) domVect of [BB4] = BB1 ...
29391 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
29399 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
29409 Thanks to all the other volunteer developers who have helped with coding,
29410 testing, web-page creation, distribution sets, etc.
29411 You know who you are :-)
29418 This document was initially written by Sandeep Dutta
29421 All product names mentioned herein may be trademarks
29422 \begin_inset LatexCommand \index{Trademarks}
29426 of their respective companies.
29433 To avoid confusion, the installation and building options for SDCC itself
29434 (chapter 2) are not part of the index.
29438 \begin_inset LatexCommand \printindex{}