1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
7 pdftitle={SDCC Compiler User Guide},
8 pdfauthor={SDCC development team},
9 pdfsubject={installation, user manual},
10 pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
11 embedded, GPL, HC08, manual, mcs51, PIC, Z80},
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 cvs
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, Motorola HC08 and Zilog Z80 based MCUs.
144 It can be retargetted for other microprocessors, support for Microchip
145 PIC, Atmel AVR is under development.
146 The entire source code for the compiler is distributed under GPL.
148 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
153 \begin_inset LatexCommand \index{aslink}
157 , an open source retargettable assembler & linker.
158 SDCC has extensive language extensions suitable for utilizing various microcont
159 rollers and underlying hardware effectively.
164 In addition to the MCU specific optimizations SDCC also does a host of standard
168 global sub expression elimination,
171 loop optimizations (loop invariant, strength reduction of induction variables
175 constant folding & propagation,
181 dead code elimination
191 For the back-end SDCC uses a global register allocation scheme which should
192 be well suited for other 8 bit MCUs.
197 The peep hole optimizer uses a rule based substitution mechanism which is
203 Supported data-types are:
206 char (8 bits, 1 byte),
209 short and int (16 bits, 2 bytes),
212 long (32 bit, 4 bytes)
219 The compiler also allows
221 inline assembler code
223 to be embedded anywhere in a function.
224 In addition, routines developed in assembly can also be called.
228 SDCC also provides an option (-
238 -cyclomatic) to report the relative complexity of a function.
239 These functions can then be further optimized, or hand coded in assembly
245 SDCC also comes with a companion source level debugger SDCDB, the debugger
246 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
251 The latest version can be downloaded from
252 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
262 Please note: the compiler will probably always be some steps ahead of this
267 \begin_inset LatexCommand \index{Status of documentation}
277 Obviously this has pros and cons
286 All packages used in this compiler system are
294 ; source code for all the sub-packages (pre-processor, assemblers, linkers
295 etc) is distributed with the package.
296 This documentation is maintained using a freeware word processor (LyX).
298 This program is free software; you can redistribute it and/or modify it
299 under the terms of the GNU General Public License
300 \begin_inset LatexCommand \index{GNU General Public License, GPL}
304 as published by the Free Software Foundation; either version 2, or (at
305 your option) any later version.
306 This program is distributed in the hope that it will be useful, but WITHOUT
307 ANY WARRANTY; without even the implied warranty
308 \begin_inset LatexCommand \index{warranty}
312 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
313 See the GNU General Public License for more details.
314 You should have received a copy of the GNU General Public License along
315 with this program; if not, write to the Free Software Foundation, 59 Temple
316 Place - Suite 330, Boston, MA 02111-1307, USA.
317 In other words, you are welcome to use, share and improve this program.
318 You are forbidden to forbid anyone else to use, share and improve what
320 Help stamp out software-hoarding!
323 Typographic conventions
324 \begin_inset LatexCommand \index{Typographic conventions}
331 Throughout this manual, we will use the following convention.
332 Commands you have to type in are printed in
340 Code samples are printed in
345 Interesting items and new terms are printed in
350 Compatibility with previous versions
353 This version has numerous bug fixes compared with the previous version.
354 But we also introduced some incompatibilities with older versions.
355 Not just for the fun of it, but to make the compiler more stable, efficient
357 \begin_inset LatexCommand \index{ANSI-compliance}
362 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
366 for ANSI-Compliance).
372 short is now equivalent to int (16 bits), it used to be equivalent to char
373 (8 bits) which is not ANSI compliant
376 the default directory for gcc-builds where include, library and documentation
377 files are stored is now in /usr/local/share
380 char type parameters to vararg functions are casted to int unless explicitly
397 will push a as an int and as a char resp.
410 -regextend has been removed
423 -noregparms has been removed
436 -stack-after-data has been removed
441 <pending: more incompatibilities?>
447 What do you need before you start installation of SDCC? A computer, and
449 The preferred method of installation is to compile SDCC from source using
451 For Windows some pre-compiled binary distributions are available for your
453 You should have some experience with command line tools and compiler use.
459 The SDCC home page at
460 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
464 is a great place to find distribution sets.
465 You can also find links to the user mailing lists that offer help or discuss
466 SDCC with other SDCC users.
467 Web links to other SDCC related sites can also be found here.
468 This document can be found in the DOC directory of the source package as
470 A pdf version of this document is available at
471 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
476 Some of the other tools (simulator and assembler) included with SDCC contain
477 their own documentation and can be found in the source distribution.
478 If you want the latest unreleased software, the complete source package
479 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
482 Wishes for the future
485 There are (and always will be) some things that could be done.
486 Here are some I can think of:
493 char KernelFunction3(char p) at 0x340;
501 \begin_inset LatexCommand \index{code banking (not supported)}
511 If you can think of some more, please see the section
512 \begin_inset LatexCommand \ref{sub:Requesting-Features}
516 about filing feature requests
517 \begin_inset LatexCommand \index{Requesting features}
522 \begin_inset LatexCommand \index{Feature request}
532 \begin_inset LatexCommand \index{Installation}
539 For most users it is sufficient to skip to either section
540 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
545 \begin_inset LatexCommand \ref{sub:Windows-Install}
550 More detailled instructions follow below.
554 \begin_inset LatexCommand \index{Options SDCC configuration}
561 The install paths, search paths and other options are defined when running
563 The defaults can be overridden by:
565 \labelwidthstring 00.00.0000
577 -prefix see table below
579 \labelwidthstring 00.00.0000
591 -exec_prefix see table below
593 \labelwidthstring 00.00.0000
605 -bindir see table below
607 \labelwidthstring 00.00.0000
619 -datadir see table below
621 \labelwidthstring 00.00.0000
623 docdir environment variable, see table below
625 \labelwidthstring 00.00.0000
627 include_dir_suffix environment variable, see table below
629 \labelwidthstring 00.00.0000
631 lib_dir_suffix environment variable, see table below
633 \labelwidthstring 00.00.0000
635 sdccconf_h_dir_separator environment variable, either / or
640 This character will only be used in sdccconf.h; don't forget it's a C-header,
641 therefore a double-backslash is needed there.
643 \labelwidthstring 00.00.0000
655 -disable-mcs51-port Excludes the Intel mcs51 port
657 \labelwidthstring 00.00.0000
669 -disable-gbz80-port Excludes the Gameboy gbz80 port
671 \labelwidthstring 00.00.0000
683 -disable-z80-port Excludes the z80 port
685 \labelwidthstring 00.00.0000
697 -disable-avr-port Excludes the AVR port
699 \labelwidthstring 00.00.0000
711 -disable-ds390-port Excludes the DS390 port
713 \labelwidthstring 00.00.0000
725 -disable-hc08-port Excludes the HC08 port
727 \labelwidthstring 00.00.0000
739 -disable-pic-port Excludes the PIC port
741 \labelwidthstring 00.00.0000
753 -disable-xa51-port Excludes the XA51 port
755 \labelwidthstring 00.00.0000
767 -disable-ucsim Disables configuring and building of ucsim
769 \labelwidthstring 00.00.0000
781 -disable-device-lib-build Disables automatically building device libraries
783 \labelwidthstring 00.00.0000
795 -disable-packihx Disables building packihx
797 \labelwidthstring 00.00.0000
809 -enable-libgc Use the Bohem memory allocator.
810 Lower runtime footprint.
813 Furthermore the environment variables CC, CFLAGS, ...
814 the tools and their arguments can be influenced.
815 Please see `configure -
825 -help` and the man/info pages of `configure` for details.
829 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
830 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
831 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
832 At the moment it's not possible to change the default settings (it was
833 simply never required).
837 These configure options are compiled into the binaries, and can only be
838 changed by rerunning 'configure' and recompiling SDCC.
839 The configure options are written in
843 to distinguish them from run time environment variables (see section search
849 \begin_inset Quotes sld
853 \begin_inset Quotes srd
856 are used by the SDCC team to build the official Win32 binaries.
857 The SDCC team uses Mingw32 to build the official Windows binaries, because
864 a gcc compiler and last but not least
867 the binaries can be built by cross compiling on Sourceforge's compile farm.
870 See the examples, how to pass the Win32 settings to 'configure'.
871 The other Win32 builds using Borland, VC or whatever don't use 'configure',
872 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
884 <lyxtabular version="3" rows="8" columns="3">
886 <column alignment="block" valignment="top" leftline="true" width="0in">
887 <column alignment="block" valignment="top" leftline="true" width="0in">
888 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
889 <row topline="true" bottomline="true">
890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1015 <row topline="true">
1016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1049 <row topline="true">
1050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1087 <row topline="true">
1088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1115 <row topline="true" bottomline="true">
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1152 'configure' also computes relative paths.
1153 This is needed for full relocatability of a binary package and to complete
1154 search paths (see section search paths below):
1160 \begin_inset Tabular
1161 <lyxtabular version="3" rows="4" columns="3">
1163 <column alignment="block" valignment="top" leftline="true" width="0in">
1164 <column alignment="block" valignment="top" leftline="true" width="0in">
1165 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1166 <row topline="true" bottomline="true">
1167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1183 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1192 <row topline="true" bottomline="true">
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1220 <row bottomline="true">
1221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1248 <row bottomline="true">
1249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1300 \begin_inset Quotes srd
1304 \begin_inset Quotes srd
1318 \begin_inset Quotes srd
1322 \begin_inset Quotes srd
1350 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1359 \begin_inset Quotes srd
1362 i586-mingw32msvc-gcc
1363 \begin_inset Quotes srd
1367 \begin_inset Quotes srd
1370 i586-mingw32msvc-g++
1371 \begin_inset Quotes srd
1379 \begin_inset Quotes srd
1382 i586-mingw32msvc-ranlib
1383 \begin_inset Quotes srd
1391 \begin_inset Quotes srd
1394 i586-mingw32msvc-strip
1395 \begin_inset Quotes srd
1413 \begin_inset Quotes srd
1417 \begin_inset Quotes srd
1435 \begin_inset Quotes srd
1439 \begin_inset Quotes srd
1447 \begin_inset Quotes srd
1451 \begin_inset Quotes srd
1459 \begin_inset Quotes srd
1463 \begin_inset Quotes srd
1471 \begin_inset Quotes srd
1475 \begin_inset Quotes srd
1482 sdccconf_h_dir_separator=
1483 \begin_inset Quotes srd
1495 \begin_inset Quotes srd
1512 -disable-device-lib-build
1540 -host=i586-mingw32msvc -
1550 -build=unknown-unknown-linux-gnu
1554 \begin_inset Quotes sld
1558 \begin_inset Quotes srd
1561 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1570 \begin_inset Quotes srd
1574 \begin_inset Quotes srd
1582 \begin_inset Quotes srd
1586 \begin_inset Quotes srd
1604 \begin_inset Quotes srd
1608 \begin_inset Quotes srd
1626 \begin_inset Quotes srd
1630 \begin_inset Quotes srd
1638 \begin_inset Quotes srd
1642 \begin_inset Quotes srd
1650 \begin_inset Quotes srd
1654 \begin_inset Quotes srd
1662 \begin_inset Quotes srd
1666 \begin_inset Quotes srd
1673 sdccconf_h_dir_separator=
1674 \begin_inset Quotes srd
1686 \begin_inset Quotes srd
1706 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1717 -C' turns on caching, which gives a little bit extra speed.
1718 However if options are changed, it can be necessary to delete the config.cache
1723 \begin_inset LatexCommand \label{sub:Install-paths}
1728 \begin_inset LatexCommand \index{Install paths}
1734 \added_space_top medskip \align center
1736 \begin_inset Tabular
1737 <lyxtabular version="3" rows="5" columns="4">
1739 <column alignment="center" valignment="top" leftline="true" width="0">
1740 <column alignment="center" valignment="top" leftline="true" width="0">
1741 <column alignment="center" valignment="top" leftline="true" width="0">
1742 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1743 <row topline="true" bottomline="true">
1744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1785 <row topline="true">
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1825 <row topline="true">
1826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1841 $DATADIR/ $INCLUDE_DIR_SUFFIX
1844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 /usr/local/share/sdcc/include
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1865 <row topline="true">
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1881 $DATADIR/$LIB_DIR_SUFFIX
1884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1889 /usr/local/share/sdcc/lib
1892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1905 <row topline="true" bottomline="true">
1906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1929 /usr/local/share/sdcc/doc
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1954 *compiler, preprocessor, assembler, and linker
1960 is auto-appended by the compiler, e.g.
1961 small, large, z80, ds390 etc
1964 The install paths can still be changed during `make install` with e.g.:
1967 make install prefix=$(HOME)/local/sdcc
1970 Of course this doesn't change the search paths compiled into the binaries.
1974 Moreover the install path can be changed by defining DESTDIR
1975 \begin_inset LatexCommand \index{DESTDIR}
1982 make install DESTDIR=$(HOME)/sdcc.rpm/
1985 Please note that DESTDIR must have a trailing slash!
1989 \begin_inset LatexCommand \label{sub:Search-Paths}
1994 \begin_inset LatexCommand \index{Search path}
2001 Some search paths or parts of them are determined by configure variables
2006 , see section above).
2007 Further search paths are determined by environment variables during runtime.
2010 The paths searched when running the compiler are as follows (the first catch
2016 Binary files (preprocessor, assembler and linker)
2022 \begin_inset Tabular
2023 <lyxtabular version="3" rows="4" columns="3">
2025 <column alignment="block" valignment="top" leftline="true" width="0in">
2026 <column alignment="block" valignment="top" leftline="true" width="0in">
2027 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2028 <row topline="true" bottomline="true">
2029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2054 <row topline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2084 <row topline="true">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2090 Path of argv[0] (if available)
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2110 <row topline="true" bottomline="true">
2111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2152 \begin_inset Tabular
2153 <lyxtabular version="3" rows="6" columns="3">
2155 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2156 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2157 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2158 <row topline="true" bottomline="true">
2159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2184 <row topline="true">
2185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2240 <row topline="true">
2241 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2266 <row topline="true">
2267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2281 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2304 <row topline="true">
2305 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2386 <row topline="true" bottomline="true">
2387 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2403 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2408 /usr/local/share/sdcc/
2413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2441 -nostdinc disables the last two search paths.
2451 With the exception of
2452 \begin_inset Quotes sld
2466 \begin_inset Quotes srd
2473 is auto-appended by the compiler (e.g.
2474 small, large, z80, ds390 etc.).
2481 \begin_inset Tabular
2482 <lyxtabular version="3" rows="6" columns="3">
2484 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2485 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2486 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2487 <row topline="true" bottomline="true">
2488 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2496 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2513 <row topline="true">
2514 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2569 <row topline="true">
2570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2582 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2609 <row topline="true">
2610 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2621 $LIB_DIR_SUFFIX/<model>
2624 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2638 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2655 <row topline="true">
2656 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2671 $LIB_DIR_SUFFIX/<model>
2674 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2783 <row topline="true" bottomline="true">
2784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2793 $LIB_DIR_SUFFIX/<model>
2796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2801 /usr/local/share/sdcc/
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2826 Don't delete any of the stray spaces in the table above without checking
2827 the HTML output (last line)!
2843 -nostdlib disables the last two search paths.
2847 \begin_inset LatexCommand \index{Building SDCC}
2854 Building SDCC on Linux
2855 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2864 Download the source package
2866 either from the SDCC CVS repository or from the nightly snapshots
2868 , it will be named something like sdcc
2879 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2888 Bring up a command line terminal, such as xterm.
2893 Unpack the file using a command like:
2896 "tar -xvzf sdcc.src.tar.gz
2901 , this will create a sub-directory called sdcc with all of the sources.
2904 Change directory into the main SDCC directory, for example type:
2921 This configures the package for compilation on your system.
2937 All of the source packages will compile, this can take a while.
2953 This copies the binary executables, the include files, the libraries and
2954 the documentation to the install directories.
2955 Proceed with section
2956 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2963 Building SDCC on OSX 2.x
2966 Follow the instruction for Linux.
2970 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2971 )) fails to compile SDCC.
2972 Fortunately there's also gcc 2.9.x installed, which works fine.
2973 This compiler can be selected by running 'configure' with:
2976 ./configure CC=gcc2 CXX=g++2
2979 Cross compiling SDCC on Linux for Windows
2982 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2983 See section 'Configure Options'.
2986 Building SDCC on Windows
2989 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2991 They use Unix-sockets, which are not available on Win32.
2994 Building SDCC using Cygwin and Mingw32
2997 For building and installing a Cygwin executable follow the instructions
3003 \begin_inset Quotes sld
3007 \begin_inset Quotes srd
3010 Win32-binary can be built, which will not need the Cygwin-DLL.
3011 For the necessary 'configure' options see section 'configure options' or
3012 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3016 In order to install Cygwin on Windows download setup.exe from
3017 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3023 \begin_inset Quotes sld
3026 default text file type
3027 \begin_inset Quotes srd
3031 \begin_inset Quotes sld
3035 \begin_inset Quotes srd
3038 and download/install at least the following packages.
3039 Some packages are selected by default, others will be automatically selected
3040 because of dependencies with the manually selected packages.
3041 Never deselect these packages!
3050 gcc ; version 3.x is fine, no need to use the old 2.9x
3053 binutils ; selected with gcc
3059 rxvt ; a nice console, which makes life much easier under windoze (see below)
3062 man ; not really needed for building SDCC, but you'll miss it sooner or
3066 less ; not really needed for building SDCC, but you'll miss it sooner or
3070 cvs ; only if you use CVS access
3073 If you want to develop something you'll need:
3076 python ; for the regression tests
3079 gdb ; the gnu debugger, together with the nice GUI
3080 \begin_inset Quotes sld
3084 \begin_inset Quotes srd
3090 openssh ; to access the CF or commit changes
3093 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3094 use autoconf-stable!
3097 rxvt is a nice console with history.
3098 Replace in your cygwin.bat the line
3117 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3120 -bg black -fg white -geometry 100x65 -e bash -
3133 Text selected with the mouse is automatically copied to the clipboard, pasting
3134 works with shift-insert.
3138 The other good tip is to make sure you have no //c/-style paths anywhere,
3139 use /cygdrive/c/ instead.
3140 Using // invokes a network lookup which is very slow.
3142 \begin_inset Quotes sld
3146 \begin_inset Quotes srd
3149 is too long, you can change it with e.g.
3155 SDCC sources use the unix line ending LF.
3156 Life is much easier, if you store the source tree on a drive which is mounted
3158 And use an editor which can handle LF-only line endings.
3159 Make sure not to commit files with windows line endings.
3160 The tabulator spacing
3161 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3165 used in the project is 8.
3166 Although a tabulator spacing of 8 is a sensible choice for programmers
3167 (it's a power of 2 and allows to display 8/16 bit signed variables without
3168 loosing columns) the plan is to move towards using only spaces in the source.
3171 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3176 Download the source package
3178 either from the SDCC CVS repository or from the
3179 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3185 , it will be named something like sdcc
3192 SDCC is distributed with all the projects, workspaces, and files you need
3193 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3194 doesn't build under MSVC).
3195 The workspace name is 'sdcc.dsw'.
3196 Please note that as it is now, all the executables are created in a folder
3200 Once built you need to copy the executables from sdcc
3204 bin before running SDCC.
3209 WARNING: Visual studio is very picky with line terminations; it expects
3210 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3211 If you are getting a message such as "This makefile was not generated by
3212 Developer Studio etc.
3214 \begin_inset Quotes srd
3217 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3218 need to convert the Unix style line endings to DOS style line endings.
3219 To do so you can use the
3220 \begin_inset Quotes sld
3224 \begin_inset Quotes srd
3227 utility freely available on the internet.
3228 Doug Hawkins reported in the sdcc-user list that this works:
3236 SDCC> unix2dos sdcc.dsw
3242 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3246 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3247 flex.exe, and gawk.exe.
3248 One good place to get them is
3249 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3257 Download the file UnxUtils
3258 \begin_inset LatexCommand \index{UnxUtils}
3263 Now you have to install the utilities and setup MSVC so it can locate the
3265 Here there are two alternatives (choose one!):
3272 a) Extract UnxUtils.zip to your C:
3274 hard disk PRESERVING the original paths, otherwise bison won't work.
3275 (If you are using WinZip make certain that 'Use folder names' is selected)
3279 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3280 in 'Show directories for:' select 'Executable files', and in the directories
3281 window add a new path: 'C:
3291 (As a side effect, you get a bunch of Unix utilities that could be useful,
3292 such as diff and patch.)
3299 This one avoids extracting a bunch of files you may not use, but requires
3304 a) Create a directory were to put the tools needed, or use a directory already
3312 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3313 to such directory WITHOUT preserving the original paths.
3314 (If you are using WinZip make certain that 'Use folder names' is not selected)
3318 c) Rename bison.exe to '_bison.exe'.
3322 d) Create a batch file 'bison.bat' in 'C:
3326 ' and add these lines:
3346 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3350 Steps 'c' and 'd' are needed because bison requires by default that the
3351 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3352 '/usr/local/share/' I think.
3353 So it is necessary to tell bison where those files are located if they
3354 are not in such directory.
3355 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3359 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3360 in 'Show directories for:' select 'Executable files', and in the directories
3361 window add a new path: 'c:
3364 Note that you can use any other path instead of 'c:
3366 util', even the path where the Visual C++ tools are, probably: 'C:
3370 Microsoft Visual Studio
3375 So you don't have to execute step 'e' :)
3379 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3380 the executables from sdcc
3384 bin, and you can compile using SDCC.
3387 Building SDCC Using Borland
3390 From the sdcc directory, run the command "make -f Makefile.bcc".
3391 This should regenerate all the .exe files in the bin directory except for
3392 sdcdb.exe (which currently doesn't build under Borland C++).
3395 If you modify any source files and need to rebuild, be aware that the dependenci
3396 es may not be correctly calculated.
3397 The safest option is to delete all .obj files and run the build again.
3398 From a Cygwin BASH prompt, this can easily be done with the command (be
3399 sure you are in the sdcc directory):
3409 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3411 ) -print -exec rm {}
3420 or on Windows NT/2000/XP from the command prompt with the command:
3427 del /s *.obj *.lib *.rul
3430 from the sdcc directory.
3433 Windows Install Using a Binary Package
3434 \begin_inset LatexCommand \label{sub:Windows-Install}
3441 Download the binary package from
3442 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3446 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3447 This should unpack to a group of sub-directories.
3448 An example directory structure after unpacking the mingw32 package is:
3453 bin for the executables, c:
3461 lib for the include and libraries.
3464 Adjust your environment variable PATH to include the location of the bin
3465 directory or start sdcc using the full path.
3468 Building the Documentation
3471 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3472 as changing into the doc directory and typing
3476 \begin_inset Quotes srd
3480 \begin_inset Quotes srd
3487 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3490 \begin_inset LatexCommand \url{www.lyx.org}
3494 as editor this is straightforward.
3495 Prebuilt documentation in html and pdf format is available from
3496 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3503 Reading the Documentation
3506 Currently reading the document in pdf format is recommended, as for unknown
3507 reason the hyperlinks are working there whereas in the html version they
3514 If you should know why please drop us a note
3518 You'll find the pdf version at
3519 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3525 This documentation is in some aspects different from a commercial documentation:
3529 It tries to document SDCC for several processor architectures in one document
3530 (commercially these probably would be separate documents/products).
3532 \begin_inset LatexCommand \index{Status of documentation}
3536 currently matches SDCC for mcs51 and DS390 best and does give too few informati
3538 Z80, PIC14, PIC16 and HC08.
3541 There are many references pointing away from this documentation.
3542 Don't let this distract you.
3544 was a reference like
3545 \begin_inset LatexCommand \url{www.opencores.org}
3549 together with a statement
3550 \begin_inset Quotes sld
3553 some processors which are targetted by SDCC can be implemented in a
3570 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3575 \begin_inset Quotes srd
3578 we expect you to have a quick look there and come back.
3579 If you read this you are on the right track.
3582 Some sections attribute more space to problems, restrictions and warnings
3583 than to the solution.
3586 The installation section and the section about the debugger is intimidating.
3589 There are still lots of typos and there are more different writing styles
3593 Testing the SDCC Compiler
3594 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3601 The first thing you should do after installing your SDCC compiler is to
3617 \begin_inset LatexCommand \index{version}
3624 at the prompt, and the program should run and tell you the version.
3625 If it doesn't run, or gives a message about not finding sdcc program, then
3626 you need to check over your installation.
3627 Make sure that the sdcc bin directory is in your executable search path
3628 defined by the PATH environment setting (
3633 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3640 Install trouble-shooting for suggestions
3643 Make sure that the sdcc program is in the bin folder, if not perhaps something
3644 did not install correctly.
3652 is commonly installed as described in section
3653 \begin_inset Quotes sld
3656 Install and search paths
3657 \begin_inset Quotes srd
3666 Make sure the compiler works on a very simple example.
3667 Type in the following test.c program using your favorite
3693 Compile this using the following command:
3702 If all goes well, the compiler will generate a test.asm and test.rel file.
3703 Congratulations, you've just compiled your first program with SDCC.
3704 We used the -c option to tell SDCC not to link the generated code, just
3705 to keep things simple for this step.
3713 The next step is to try it with the linker.
3723 If all goes well the compiler will link with the libraries and produce
3724 a test.ihx output file.
3729 (no test.ihx, and the linker generates warnings), then the problem is most
3738 usr/local/share/sdcc/lib directory
3745 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3752 Install trouble-shooting for suggestions).
3760 The final test is to ensure
3768 header files and libraries.
3769 Edit test.c and change it to the following:
3786 strcpy(str1, "testing");
3793 Compile this by typing
3800 This should generate a test.ihx output file, and it should give no warnings
3801 such as not finding the string.h file.
3802 If it cannot find the string.h file, then the problem is that
3806 cannot find the /usr/local/share/sdcc/include directory
3813 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3820 Install trouble-shooting section for suggestions).
3838 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3842 to find exactly where SDCC is looking for the include and lib files.
3845 Install Trouble-shooting
3846 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3851 \begin_inset LatexCommand \index{Install trouble-shooting}
3858 If SDCC does not build correctly
3861 A thing to try is starting from scratch by unpacking the .tgz source package
3862 again in an empty directory.
3870 ./configure 2>&1 | tee configure.log
3884 make 2>&1 | tee make.log
3891 If anything goes wrong, you can review the log files to locate the problem.
3892 Or a relevant part of this can be attached to an email that could be helpful
3893 when requesting help from the mailing list.
3897 \begin_inset Quotes sld
3901 \begin_inset Quotes srd
3908 \begin_inset Quotes sld
3912 \begin_inset Quotes srd
3915 command is a script that analyzes your system and performs some configuration
3916 to ensure the source package compiles on your system.
3917 It will take a few minutes to run, and will compile a few tests to determine
3918 what compiler features are installed.
3922 \begin_inset Quotes sld
3926 \begin_inset Quotes srd
3932 This runs the GNU make tool, which automatically compiles all the source
3933 packages into the final installed binary executables.
3937 \begin_inset Quotes sld
3941 \begin_inset Quotes erd
3947 This will install the compiler, other executables libraries and include
3948 files into the appropriate directories.
3950 \begin_inset LatexCommand \ref{sub:Install-paths}
3956 \begin_inset LatexCommand \ref{sub:Search-Paths}
3961 about install and search paths.
3963 On most systems you will need super-user privileges to do this.
3969 SDCC is not just a compiler, but a collection of tools by various developers.
3970 These include linkers, assemblers, simulators and other components.
3971 Here is a summary of some of the components.
3972 Note that the included simulator and assembler have separate documentation
3973 which you can find in the source package in their respective directories.
3974 As SDCC grows to include support for other processors, other packages from
3975 various developers are included and may have their own sets of documentation.
3979 You might want to look at the files which are installed in <installdir>.
3980 At the time of this writing, we find the following programs for gcc-builds:
3984 In <installdir>/bin:
3987 sdcc - The compiler.
3990 sdcpp - The C preprocessor.
3993 asx8051 - The assembler for 8051 type processors.
4000 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4003 aslink -The linker for 8051 type processors.
4010 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4013 s51 - The ucSim 8051 simulator.
4016 sdcdb - The source debugger.
4019 packihx - A tool to pack (compress) Intel hex files.
4022 In <installdir>/share/sdcc/include
4028 In <installdir>/share/sdcc/lib
4031 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4035 In <installdir>/share/sdcc/doc
4041 As development for other processors proceeds, this list will expand to include
4042 executables to support processors like AVR, PIC, etc.
4048 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4049 the assembler and linkage editor.
4052 sdcpp - The C-Preprocessor
4056 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4060 is a modified version of the GNU preprocessor.
4061 The C preprocessor is used to pull in #include sources, process #ifdef
4062 statements, #defines and so on.
4073 - The Assemblers and Linkage Editors
4076 This is retargettable assembler & linkage editor, it was developed by Alan
4078 John Hartman created the version for 8051, and I (Sandeep) have made some
4079 enhancements and bug fixes for it to work properly with SDCC.
4086 \begin_inset LatexCommand \index{s51}
4090 is a freeware, opensource simulator developed by Daniel Drotos (
4091 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4096 The simulator is built as part of the build process.
4097 For more information visit Daniel's web site at:
4098 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4103 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4107 sdcdb - Source Level Debugger
4111 \begin_inset LatexCommand \index{sdcdb (debugger)}
4115 is the companion source level debugger.
4116 More about sdcdb in section
4117 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4122 The current version of the debugger uses Daniel's Simulator S51
4123 \begin_inset LatexCommand \index{s51}
4127 , but can be easily changed to use other simulators.
4137 Single Source File Projects
4140 For single source file 8051 projects the process is very simple.
4141 Compile your programs with the following command
4144 "sdcc sourcefile.c".
4148 This will compile, assemble and link your source file.
4149 Output files are as follows:
4153 \begin_inset LatexCommand \index{<file>.asm}
4158 \begin_inset LatexCommand \index{Assembler source}
4162 file created by the compiler
4166 \begin_inset LatexCommand \index{<file>.lst}
4171 \begin_inset LatexCommand \index{Assembler listing}
4175 file created by the Assembler
4179 \begin_inset LatexCommand \index{<file>.rst}
4184 \begin_inset LatexCommand \index{Assembler listing}
4188 file updated with linkedit information, created by linkage editor
4192 \begin_inset LatexCommand \index{<file>.sym}
4197 \begin_inset LatexCommand \index{Symbol listing}
4201 for the sourcefile, created by the assembler
4205 \begin_inset LatexCommand \index{<file>.rel}
4210 \begin_inset LatexCommand \index{<file>.o}
4215 \begin_inset LatexCommand \index{Object file}
4219 created by the assembler, input to Linkage editor
4223 \begin_inset LatexCommand \index{<file>.map}
4228 \begin_inset LatexCommand \index{Memory map}
4232 for the load module, created by the Linker
4236 \begin_inset LatexCommand \index{<file>.mem}
4240 - A file with a summary of the memory usage
4244 \begin_inset LatexCommand \index{<file>.ihx}
4248 - The load module in Intel hex format
4249 \begin_inset LatexCommand \index{Intel hex format}
4253 (you can select the Motorola S19 format
4254 \begin_inset LatexCommand \index{Motorola S19 format}
4269 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4274 If you need another format you might want to use
4281 \begin_inset LatexCommand \index{objdump (tool)}
4292 \begin_inset LatexCommand \index{srecord (tool)}
4297 Both formats are documented in the documentation of srecord
4298 \begin_inset LatexCommand \index{srecord (tool)}
4306 \begin_inset LatexCommand \index{<file>.adb}
4310 - An intermediate file containing debug information needed to create the
4322 \begin_inset LatexCommand \index{-\/-debug}
4330 \begin_inset LatexCommand \index{<file>.cdb}
4334 - An optional file (with -
4344 -debug) containing debug information.
4345 The format is documented in cdbfileformat.pdf.
4350 \begin_inset LatexCommand \index{<file> (no extension)}
4354 An optional AOMF or AOMF51
4355 \begin_inset LatexCommand \index{AOMF, AOMF51}
4359 file containing debug information (generated with option -
4386 ormat is commonly used by third party tools (debuggers
4387 \begin_inset LatexCommand \index{Debugger}
4391 , simulators, emulators)
4395 \begin_inset LatexCommand \index{<file>.dump*}
4399 - Dump file to debug the compiler it self (generated with option -
4409 -dumpall) (see section
4410 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4416 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4422 \begin_inset Quotes sld
4425 Anatomy of the compiler
4426 \begin_inset Quotes srd
4432 Projects with Multiple Source Files
4435 SDCC can compile only ONE file at a time.
4436 Let us for example assume that you have a project containing the following
4441 foo1.c (contains some functions)
4443 foo2.c (contains some more functions)
4445 foomain.c (contains more functions and the function main)
4453 The first two files will need to be compiled separately with the commands:
4485 Then compile the source file containing the
4490 \begin_inset LatexCommand \index{Linker}
4494 the files together with the following command:
4502 foomain.c\SpecialChar ~
4503 foo1.rel\SpecialChar ~
4508 \begin_inset LatexCommand \index{<file>.rel}
4520 can be separately compiled as well:
4531 sdcc foomain.rel foo1.rel foo2.rel
4538 The file containing the
4553 file specified in the command line, since the linkage editor processes
4554 file in the order they are presented to it.
4555 The linker is invoked from SDCC using a script file with extension .lnk
4556 \begin_inset LatexCommand \index{<file>.lnk}
4561 You can view this file to troubleshoot linking problems such as those arising
4562 from missing libraries.
4565 Projects with Additional Libraries
4566 \begin_inset LatexCommand \index{Libraries}
4573 Some reusable routines may be compiled into a library, see the documentation
4574 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4578 \begin_inset LatexCommand \index{<file>.lib}
4585 Libraries created in this manner can be included in the command line.
4586 Make sure you include the -L <library-path> option to tell the linker where
4587 to look for these files if they are not in the current directory.
4588 Here is an example, assuming you have the source file
4600 (if that is not the same as your current project):
4607 sdcc foomain.c foolib.lib -L mylib
4618 must be an absolute path name.
4622 The most efficient way to use libraries is to keep separate modules in separate
4624 The lib file now should name all the modules.rel
4625 \begin_inset LatexCommand \index{<file>.rel}
4630 For an example see the standard library file
4634 in the directory <installdir>/share/lib/small.
4637 Using sdcclib to Create and Manage Libraries
4638 \begin_inset LatexCommand \index{sdcclib}
4645 Alternatively, instead of having a .rel file for each entry on the library
4646 file as described in the preceding section, sdcclib can be used to embed
4647 all the modules belonging to such library in the library file itself.
4648 This results in a larger library file, but it greatly reduces the number
4649 of disk files accessed by the linker.
4650 Additionally, the packed library file contains an index of all include
4651 modules and symbols that significantly speeds up the linking process.
4652 To display a list of options supported by sdcclib type:
4661 \begin_inset LatexCommand \index{sdcclib}
4672 To create a new library file, start by compiling all the required modules.
4710 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4712 The next step is to add the .rel files to the library file:
4720 sdcclib libint.lib _divsint.rel
4723 \begin_inset LatexCommand \index{sdcclib}
4733 sdcclib libint.lib _divuint.rel
4739 sdcclib libint.lib _modsint.rel
4745 sdcclib libint.lib _moduint.rel
4751 sdcclib libint.lib _mulint.rel
4758 If the file already exists in the library, it will be replaced.
4759 To see what modules and symbols are included in the library, options -s
4760 and -m are available.
4768 sdcclib -s libint.lib
4771 \begin_inset LatexCommand \index{sdcclib}
4881 If the source files are compiled using -
4892 \begin_inset LatexCommand \index{-\/-debug}
4896 , the corresponding debug information file .adb will be include in the library
4898 The library files created with sdcclib are plain text files, so they can
4899 be viewed with a text editor.
4900 It is not recomended to modify a library file created with sdcclib using
4901 a text editor, as there are file indexes numbers located accross the file
4902 used by the linker to quickly locate the required module to link.
4903 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4904 it can be safely deleted, since all the information required for linking
4905 is embedded in the library file itself.
4906 Library files created using sdcclib are used as described in the preceding
4910 Command Line Options
4911 \begin_inset LatexCommand \index{Command Line Options}
4918 Processor Selection Options
4919 \begin_inset LatexCommand \index{Options processor selection}
4924 \begin_inset LatexCommand \index{Processor selection options}
4930 \labelwidthstring 00.00.0000
4935 \begin_inset LatexCommand \index{-mmcs51}
4941 Generate code for the Intel MCS51
4942 \begin_inset LatexCommand \index{MCS51}
4946 family of processors.
4947 This is the default processor target.
4949 \labelwidthstring 00.00.0000
4954 \begin_inset LatexCommand \index{-mds390}
4960 Generate code for the Dallas DS80C390
4961 \begin_inset LatexCommand \index{DS80C390}
4967 \labelwidthstring 00.00.0000
4972 \begin_inset LatexCommand \index{-mds400}
4978 Generate code for the Dallas DS80C400
4979 \begin_inset LatexCommand \index{DS80C400}
4985 \labelwidthstring 00.00.0000
4990 \begin_inset LatexCommand \index{-mhc08}
4996 Generate code for the Motorola HC08
4997 \begin_inset LatexCommand \index{HC08}
5001 family of processors (added Oct 2003).
5003 \labelwidthstring 00.00.0000
5008 \begin_inset LatexCommand \index{-mz80}
5014 Generate code for the Zilog Z80
5015 \begin_inset LatexCommand \index{Z80}
5019 family of processors.
5021 \labelwidthstring 00.00.0000
5026 \begin_inset LatexCommand \index{-mgbz80}
5032 Generate code for the GameBoy Z80
5033 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5037 processor (Not actively maintained).
5039 \labelwidthstring 00.00.0000
5044 \begin_inset LatexCommand \index{-mavr}
5050 Generate code for the Atmel AVR
5051 \begin_inset LatexCommand \index{AVR}
5055 processor (In development, not complete).
5056 AVR users should probably have a look at avr-gcc
5057 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
5062 \begin_inset LatexCommand \url{http://winavr.sourceforge.net}
5069 I think it is fair to direct users there for now.
5070 Open source is also about avoiding unnecessary work .
5071 But I didn't find the 'official' link.
5073 \labelwidthstring 00.00.0000
5078 \begin_inset LatexCommand \index{-mpic14}
5084 Generate code for the Microchip PIC 14
5085 \begin_inset LatexCommand \index{PIC14}
5089 -bit processors (p16f84 and variants.
5090 In development, not complete).
5093 p16f627 p16f628 p16f84 p16f873 p16f877?
5095 \labelwidthstring 00.00.0000
5100 \begin_inset LatexCommand \index{-mpic16}
5106 Generate code for the Microchip PIC 16
5107 \begin_inset LatexCommand \index{PIC16}
5111 -bit processors (p18f452 and variants.
5112 In development, not complete).
5114 \labelwidthstring 00.00.0000
5120 Generate code for the Toshiba TLCS-900H
5121 \begin_inset LatexCommand \index{TLCS-900H}
5125 processor (Not maintained, not complete).
5127 \labelwidthstring 00.00.0000
5132 \begin_inset LatexCommand \index{-mxa51}
5138 Generate code for the Phillips XA51
5139 \begin_inset LatexCommand \index{XA51}
5143 processor (Not maintained, not complete).
5146 Preprocessor Options
5147 \begin_inset LatexCommand \index{Options preprocessor}
5152 \begin_inset LatexCommand \index{Preprocessor options}
5157 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5163 \labelwidthstring 00.00.0000
5168 \begin_inset LatexCommand \index{-I<path>}
5174 The additional location where the pre processor will look for <..h> or
5175 \begin_inset Quotes eld
5179 \begin_inset Quotes erd
5184 \labelwidthstring 00.00.0000
5189 \begin_inset LatexCommand \index{-D<macro[=value]>}
5195 Command line definition of macros.
5196 Passed to the preprocessor.
5198 \labelwidthstring 00.00.0000
5203 \begin_inset LatexCommand \index{-M}
5209 Tell the preprocessor to output a rule suitable for make describing the
5210 dependencies of each object file.
5211 For each source file, the preprocessor outputs one make-rule whose target
5212 is the object file name for that source file and whose dependencies are
5213 all the files `#include'd in it.
5214 This rule may be a single line or may be continued with `
5216 '-newline if it is long.
5217 The list of rules is printed on standard output instead of the preprocessed
5220 \begin_inset LatexCommand \index{-E}
5226 \labelwidthstring 00.00.0000
5231 \begin_inset LatexCommand \index{-C}
5237 Tell the preprocessor not to discard comments.
5238 Used with the `-E' option.
5240 \labelwidthstring 00.00.0000
5245 \begin_inset LatexCommand \index{-MM}
5256 Like `-M' but the output mentions only the user header files included with
5258 \begin_inset Quotes eld
5262 System header files included with `#include <file>' are omitted.
5264 \labelwidthstring 00.00.0000
5269 \begin_inset LatexCommand \index{-Aquestion(answer)}
5275 Assert the answer answer for question, in case it is tested with a preprocessor
5276 conditional such as `#if #question(answer)'.
5277 `-A-' disables the standard assertions that normally describe the target
5280 \labelwidthstring 00.00.0000
5285 \begin_inset LatexCommand \index{-Umacro}
5291 Undefine macro macro.
5292 `-U' options are evaluated after all `-D' options, but before any `-include'
5293 and `-imacros' options.
5295 \labelwidthstring 00.00.0000
5300 \begin_inset LatexCommand \index{-dM}
5306 Tell the preprocessor to output only a list of the macro definitions that
5307 are in effect at the end of preprocessing.
5308 Used with the `-E' option.
5310 \labelwidthstring 00.00.0000
5315 \begin_inset LatexCommand \index{-dD}
5321 Tell the preprocessor to pass all macro definitions into the output, in
5322 their proper sequence in the rest of the output.
5324 \labelwidthstring 00.00.0000
5329 \begin_inset LatexCommand \index{-dN}
5340 Like `-dD' except that the macro arguments and contents are omitted.
5341 Only `#define name' is included in the output.
5343 \labelwidthstring 00.00.0000
5348 preprocessorOption[,preprocessorOption]
5351 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5356 Pass the preprocessorOption to the preprocessor
5361 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5366 SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5367 Collection (gcc), if you need more dedicated options please refer to the
5369 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5377 \begin_inset LatexCommand \index{Options linker}
5382 \begin_inset LatexCommand \index{Linker options}
5388 \labelwidthstring 00.00.0000
5408 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5413 \begin_inset LatexCommand \index{-L -\/-lib-path}
5420 <absolute path to additional libraries> This option is passed to the linkage
5421 editor's additional libraries
5422 \begin_inset LatexCommand \index{Libraries}
5427 The path name must be absolute.
5428 Additional library files may be specified in the command line.
5429 See section Compiling programs for more details.
5431 \labelwidthstring 00.00.0000
5448 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5453 <Value> The start location of the external ram
5454 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5458 , default value is 0.
5459 The value entered can be in Hexadecimal or Decimal format, e.g.: -
5469 -xram-loc 0x8000 or -
5481 \labelwidthstring 00.00.0000
5498 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5503 <Value> The start location of the code
5504 \begin_inset LatexCommand \index{code}
5508 segment, default value 0.
5509 Note when this option is used the interrupt vector table is also relocated
5510 to the given address.
5511 The value entered can be in Hexadecimal or Decimal format, e.g.: -
5521 -code-loc 0x8000 or -
5533 \labelwidthstring 00.00.0000
5550 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5555 <Value> By default the stack
5556 \begin_inset LatexCommand \index{stack}
5560 is placed after the data segment.
5561 Using this option the stack can be placed anywhere in the internal memory
5563 The value entered can be in Hexadecimal or Decimal format, e.g.
5574 -stack-loc 0x20 or -
5585 Since the sp register is incremented before a push or call, the initial
5586 sp will be set to one byte prior the provided value.
5587 The provided value should not overlap any other memory areas such as used
5588 register banks or the data segment and with enough space for the current
5591 \labelwidthstring 00.00.0000
5608 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5613 <Value> The start location of the internal ram data
5614 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5619 The value entered can be in Hexadecimal or Decimal format, eg.
5641 (By default, the start location of the internal ram data segment is set
5642 as low as possible in memory, taking into account the used register banks
5643 and the bit segment at address 0x20.
5644 For example if register banks 0 and 1 are used without bit variables, the
5645 data segment will be set, if -
5655 -data-loc is not used, to location 0x10.)
5657 \labelwidthstring 00.00.0000
5674 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5679 <Value> The start location of the indirectly addressable internal ram
5680 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5684 of the 8051, default value is 0x80.
5685 The value entered can be in Hexadecimal or Decimal format, eg.
5696 -idata-loc 0x88 or -
5708 \labelwidthstring 00.00.0000
5725 <Value> The start location of the bit
5726 \begin_inset LatexCommand \index{bit}
5730 addressable internal ram of the 8051.
5736 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5739 \labelwidthstring 00.00.0000
5754 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5763 The linker output (final object code) is in Intel Hex format.
5764 \begin_inset LatexCommand \index{Intel hex format}
5768 This is the default option.
5769 The format itself is documented in the documentation of srecord
5770 \begin_inset LatexCommand \index{srecord (tool)}
5776 \labelwidthstring 00.00.0000
5791 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5800 The linker output (final object code) is in Motorola S19 format
5801 \begin_inset LatexCommand \index{Motorola S19 format}
5806 The format itself is documented in the documentation of srecord.
5808 \labelwidthstring 00.00.0000
5813 linkOption[,linkOption]
5816 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5821 Pass the linkOption to the linker.
5822 See file sdcc/as/doc/asxhtm.html for more on linker options.
5826 \begin_inset LatexCommand \index{Options MCS51}
5831 \begin_inset LatexCommand \index{MCS51 options}
5837 \labelwidthstring 00.00.0000
5852 \begin_inset LatexCommand \index{-\/-model-small}
5863 Generate code for Small Model programs, see section Memory Models for more
5865 This is the default model.
5867 \labelwidthstring 00.00.0000
5882 \begin_inset LatexCommand \index{-\/-model-large}
5888 Generate code for Large model programs, see section Memory Models for more
5890 If this option is used all source files in the project have to be compiled
5893 \labelwidthstring 00.00.0000
5908 \begin_inset LatexCommand \index{-\/-xstack}
5914 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5915 variables and passing parameters.
5917 \begin_inset LatexCommand \ref{sub:External-Stack}
5922 External Stack for more details.
5924 \labelwidthstring 00.00.0000
5942 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5946 Causes the linker to check if the internal ram usage is within limits of
5949 \labelwidthstring 00.00.0000
5967 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5971 Causes the linker to check if the external ram usage is within limits of
5974 \labelwidthstring 00.00.0000
5992 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5996 Causes the linker to check if the code memory usage is within limits of
5999 \labelwidthstring 00.00.0000
6017 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6021 Causes the linker to check if there is at minimum <Value> bytes for stack.
6023 \labelwidthstring 00.00.0000
6041 \begin_inset LatexCommand \index{-\/-pack-iram}
6045 Causes the linker use unused register banks for data variables or stack.
6048 DS390 / DS400 Options
6049 \begin_inset LatexCommand \index{Options DS390}
6054 \begin_inset LatexCommand \index{DS390 options}
6060 \labelwidthstring 00.00.0000
6077 \begin_inset LatexCommand \index{-\/-model-flat24}
6087 Generate 24-bit flat mode code.
6088 This is the one and only that the ds390 code generator supports right now
6089 and is default when using
6094 See section Memory Models for more details.
6096 \labelwidthstring 00.00.0000
6111 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6117 disable interrupts during ESP:SP updates.
6119 \labelwidthstring 00.00.0000
6136 \begin_inset LatexCommand \index{-\/-stack-10bit}
6140 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6141 This is the one and only that the ds390 code generator supports right now
6142 and is default when using
6147 In this mode, the stack is located in the lower 1K of the internal RAM,
6148 which is mapped to 0x400000.
6149 Note that the support is incomplete, since it still uses a single byte
6150 as the stack pointer.
6151 This means that only the lower 256 bytes of the potential 1K stack space
6152 will actually be used.
6153 However, this does allow you to reclaim the precious 256 bytes of low RAM
6154 for use for the DATA and IDATA segments.
6155 The compiler will not generate any code to put the processor into 10 bit
6157 It is important to ensure that the processor is in this mode before calling
6158 any re-entrant functions compiled with this option.
6159 In principle, this should work with the
6172 \begin_inset LatexCommand \index{-\/-stack-auto}
6178 option, but that has not been tested.
6179 It is incompatible with the
6192 \begin_inset LatexCommand \index{-\/-xstack}
6199 It also only makes sense if the processor is in 24 bit contiguous addressing
6212 -model-flat24 option
6216 \labelwidthstring 00.00.0000
6231 \begin_inset LatexCommand \index{-\/-stack-probe}
6237 insert call to function __stack_probe at each function prologue.
6239 \labelwidthstring 00.00.0000
6254 \begin_inset LatexCommand \index{-\/-tini-libid}
6260 <nnnn> LibraryID used in -mTININative.
6263 \labelwidthstring 00.00.0000
6278 \begin_inset LatexCommand \index{-\/-use-accelerator}
6284 generate code for DS390 Arithmetic Accelerator.
6289 \begin_inset LatexCommand \index{Options Z80}
6294 \begin_inset LatexCommand \index{Z80 options}
6300 \labelwidthstring 00.00.0000
6317 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6327 Force a called function to always save BC.
6329 \labelwidthstring 00.00.0000
6346 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6350 When linking, skip the standard crt0.o object file.
6351 You must provide your own crt0.o for your system when linking.
6355 Optimization Options
6356 \begin_inset LatexCommand \index{Options optimization}
6361 \begin_inset LatexCommand \index{Optimization options}
6367 \labelwidthstring 00.00.0000
6382 \begin_inset LatexCommand \index{-\/-nogcse}
6388 Will not do global subexpression elimination, this option may be used when
6389 the compiler creates undesirably large stack/data spaces to store compiler
6391 A warning message will be generated when this happens and the compiler
6392 will indicate the number of extra bytes it allocated.
6393 It is recommended that this option NOT be used, #pragma\SpecialChar ~
6395 \begin_inset LatexCommand \index{\#pragma nogcse}
6399 can be used to turn off global subexpression elimination
6400 \begin_inset LatexCommand \index{Subexpression elimination}
6404 for a given function only.
6406 \labelwidthstring 00.00.0000
6421 \begin_inset LatexCommand \index{-\/-noinvariant}
6427 Will not do loop invariant optimizations, this may be turned off for reasons
6428 explained for the previous option.
6429 For more details of loop optimizations performed see Loop Invariants in
6431 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6436 It is recommended that this option NOT be used, #pragma\SpecialChar ~
6438 \begin_inset LatexCommand \index{\#pragma noinvariant}
6442 can be used to turn off invariant optimizations for a given function only.
6444 \labelwidthstring 00.00.0000
6459 \begin_inset LatexCommand \index{-\/-noinduction}
6465 Will not do loop induction optimizations, see section strength reduction
6467 It is recommended that this option is NOT used, #pragma\SpecialChar ~
6469 \begin_inset LatexCommand \index{\#pragma noinduction}
6473 can be used to turn off induction optimizations for a given function only.
6475 \labelwidthstring 00.00.0000
6490 \begin_inset LatexCommand \index{-\/-nojtbound}
6501 Will not generate boundary condition check when switch statements
6502 \begin_inset LatexCommand \index{switch statement}
6506 are implemented using jump-tables.
6508 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6513 Switch Statements for more details.
6514 It is recommended that this option is NOT used, #pragma\SpecialChar ~
6516 \begin_inset LatexCommand \index{\#pragma nojtbound}
6520 can be used to turn off boundary checking for jump tables for a given function
6523 \labelwidthstring 00.00.0000
6538 \begin_inset LatexCommand \index{-\/-noloopreverse}
6547 Will not do loop reversal
6548 \begin_inset LatexCommand \index{Loop reversing}
6554 \labelwidthstring 00.00.0000
6571 \begin_inset LatexCommand \index{-\/-nolabelopt }
6575 Will not optimize labels (makes the dumpfiles more readable).
6577 \labelwidthstring 00.00.0000
6592 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6598 Will not memcpy initialized data from code space into xdata space.
6599 This saves a few bytes in code space if you don't have initialized data.
6601 \labelwidthstring 00.00.0000
6616 \begin_inset LatexCommand \index{-\/-nooverlay}
6622 The compiler will not overlay parameters and local variables of any function,
6623 see section Parameters and local variables for more details.
6625 \labelwidthstring 00.00.0000
6640 \begin_inset LatexCommand \index{-\/-no-peep}
6646 Disable peep-hole optimization.
6648 \labelwidthstring 00.00.0000
6665 \begin_inset LatexCommand \index{-\/-peep-file}
6670 <filename> This option can be used to use additional rules to be used by
6671 the peep hole optimizer.
6673 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6678 Peep Hole optimizations for details on how to write these rules.
6680 \labelwidthstring 00.00.0000
6695 \begin_inset LatexCommand \index{-\/-peep-asm}
6701 Pass the inline assembler code through the peep hole optimizer.
6702 This can cause unexpected changes to inline assembler code, please go through
6703 the peephole optimizer
6704 \begin_inset LatexCommand \index{Peephole optimizer}
6708 rules defined in the source file tree '<target>/peeph.def' before using
6711 \labelwidthstring 00.00.0000
6726 \begin_inset LatexCommand \index{-\/-opt-code-speed}
6732 The compiler will optimize code generation towards fast code, possibly
6733 at the expense of code size.
6735 \labelwidthstring 00.00.0000
6750 \begin_inset LatexCommand \index{-\/-opt-code-size}
6756 The compiler will optimize code generation towards compact code, possibly
6757 at the expense of code speed.
6761 \begin_inset LatexCommand \index{Options other}
6767 \labelwidthstring 00.00.0000
6783 \begin_inset LatexCommand \index{-\/-compile-only}
6788 \begin_inset LatexCommand \index{-c -\/-compile-only}
6794 will compile and assemble the source, but will not call the linkage editor.
6796 \labelwidthstring 00.00.0000
6815 \begin_inset LatexCommand \index{-\/-c1mode}
6821 reads the preprocessed source from standard input and compiles it.
6822 The file name for the assembler output must be specified using the -o option.
6824 \labelwidthstring 00.00.0000
6829 \begin_inset LatexCommand \index{-E}
6835 Run only the C preprocessor.
6836 Preprocess all the C source files specified and output the results to standard
6839 \labelwidthstring 00.00.0000
6845 \begin_inset LatexCommand \index{-o <path/file>}
6851 The output path resp.
6852 file where everything will be placed.
6853 If the parameter is a path, it must have a trailing slash (or backslash
6854 for the Windows binaries) to be recognized as a path.
6857 \labelwidthstring 00.00.0000
6872 \begin_inset LatexCommand \index{-\/-stack-auto}
6883 All functions in the source file will be compiled as
6888 \begin_inset LatexCommand \index{reentrant}
6893 the parameters and local variables will be allocated on the stack
6894 \begin_inset LatexCommand \index{stack}
6900 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
6904 Parameters and Local Variables for more details.
6905 If this option is used all source files in the project should be compiled
6909 \labelwidthstring 00.00.0000
6924 \begin_inset LatexCommand \index{-\/-callee-saves}
6928 function1[,function2][,function3]....
6931 The compiler by default uses a caller saves convention for register saving
6932 across function calls, however this can cause unnecessary register pushing
6933 & popping when calling small functions from larger functions.
6934 This option can be used to switch the register saving convention for the
6935 function names specified.
6936 The compiler will not save registers when calling these functions, no extra
6937 code will be generated at the entry & exit (function prologue
6940 \begin_inset LatexCommand \index{function prologue}
6949 \begin_inset LatexCommand \index{function epilogue}
6955 ) for these functions to save & restore the registers used by these functions,
6956 this can SUBSTANTIALLY reduce code & improve run time performance of the
6958 In the future the compiler (with inter procedural analysis) will be able
6959 to determine the appropriate scheme to use for each function call.
6960 DO NOT use this option for built-in functions such as _mulint..., if this
6961 option is used for a library function the appropriate library function
6962 needs to be recompiled with the same option.
6963 If the project consists of multiple source files then all the source file
6964 should be compiled with the same -
6974 -callee-saves option string.
6975 Also see #pragma\SpecialChar ~
6977 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6983 \labelwidthstring 00.00.0000
6998 \begin_inset LatexCommand \index{-\/-debug}
7007 When this option is used the compiler will generate debug information.
7008 The debug information collected in a file with .cdb extension can be used
7010 For more information see documentation for SDCDB.
7011 Another file with no extension contains debug information in AOMF or AOMF51
7012 \begin_inset LatexCommand \index{AOMF, AOMF51}
7016 format which is commonly used by third party tools.
7018 \labelwidthstring 00.00.0000
7023 \begin_inset LatexCommand \index{-S}
7034 Stop after the stage of compilation proper; do not assemble.
7035 The output is an assembler code file for the input file specified.
7037 \labelwidthstring 00.00.0000
7052 \begin_inset LatexCommand \index{-\/-int-long-reent}
7058 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7059 Note by default these libraries are compiled as non-reentrant.
7060 See section Installation for more details.
7062 \labelwidthstring 00.00.0000
7077 \begin_inset LatexCommand \index{-\/-cyclomatic}
7086 This option will cause the compiler to generate an information message for
7087 each function in the source file.
7088 The message contains some
7092 information about the function.
7093 The number of edges and nodes the compiler detected in the control flow
7094 graph of the function, and most importantly the
7096 cyclomatic complexity
7097 \begin_inset LatexCommand \index{Cyclomatic complexity}
7103 see section on Cyclomatic Complexity for more details.
7105 \labelwidthstring 00.00.0000
7120 \begin_inset LatexCommand \index{-\/-float-reent}
7126 Floating point library is compiled as reentrant
7127 \begin_inset LatexCommand \index{reentrant}
7132 See section Installation for more details.
7134 \labelwidthstring 00.00.0000
7149 \begin_inset LatexCommand \index{-\/-main-return}
7155 This option can be used if the code generated is called by a monitor program
7156 or if the main routine includes an endless loop.
7157 This option might result in slightly smaller code and save two bytes of
7159 The return from the 'main'
7160 \begin_inset LatexCommand \index{main return}
7164 function will return to the function calling main.
7165 The default setting is to lock up i.e.
7172 \labelwidthstring 00.00.0000
7187 \begin_inset LatexCommand \index{-\/-nostdincl}
7193 This will prevent the compiler from passing on the default include path
7194 to the preprocessor.
7196 \labelwidthstring 00.00.0000
7211 \begin_inset LatexCommand \index{-\/-nostdlib}
7217 This will prevent the compiler from passing on the default library
7218 \begin_inset LatexCommand \index{Libraries}
7224 \labelwidthstring 00.00.0000
7239 \begin_inset LatexCommand \index{-\/-verbose}
7245 Shows the various actions the compiler is performing.
7247 \labelwidthstring 00.00.0000
7252 \begin_inset LatexCommand \index{-V}
7258 Shows the actual commands the compiler is executing.
7260 \labelwidthstring 00.00.0000
7275 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7281 Hides your ugly and inefficient c-code from the asm file, so you can always
7282 blame the compiler :)
7284 \labelwidthstring 00.00.0000
7299 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7305 Will not include peep-hole comments in the generated files.
7307 \labelwidthstring 00.00.0000
7322 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7328 Include i-codes in the asm file.
7329 Sounds like noise but is most helpful for debugging the compiler itself.
7331 \labelwidthstring 00.00.0000
7346 \begin_inset LatexCommand \index{-\/-less-pedantic}
7352 Disable some of the more pedantic warnings
7353 \begin_inset LatexCommand \index{Warnings}
7357 (jwk burps: please be more specific here, please!).
7358 If you want rather more than less warnings you should consider using a
7359 separate tool dedicated to syntax checking like splint
7360 \begin_inset LatexCommand \url{www.splint.org}
7366 \labelwidthstring 00.00.0000
7381 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7387 Display the directories in the compiler's search path
7389 \labelwidthstring 00.00.0000
7404 \begin_inset LatexCommand \index{-\/-vc}
7410 Display errors and warnings using MSVC style, so you can use SDCC with
7413 \labelwidthstring 00.00.0000
7428 \begin_inset LatexCommand \index{-\/-use-stdout}
7434 Send errors and warnings to stdout instead of stderr.
7436 \labelwidthstring 00.00.0000
7441 asmOption[,asmOption]
7444 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7449 Pass the asmOption to the assembler
7450 \begin_inset LatexCommand \index{Options assembler}
7455 \begin_inset LatexCommand \index{Assembler options}
7460 See file sdcc/as/doc/asxhtm.html for assembler options.
7463 Intermediate Dump Options
7464 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7469 \begin_inset LatexCommand \index{Options intermediate dump}
7474 \begin_inset LatexCommand \index{Intermediate dump options}
7481 The following options are provided for the purpose of retargetting and debugging
7483 These provided a means to dump the intermediate code (iCode
7484 \begin_inset LatexCommand \index{iCode}
7488 ) generated by the compiler in human readable form at various stages of
7489 the compilation process.
7490 More on iCodes see chapter
7491 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7496 \begin_inset Quotes srd
7499 The anatomy of the compiler
7500 \begin_inset Quotes srd
7505 \labelwidthstring 00.00.0000
7520 \begin_inset LatexCommand \index{-\/-dumpraw}
7526 This option will cause the compiler to dump the intermediate code into
7529 <source filename>.dumpraw
7531 just after the intermediate code has been generated for a function, i.e.
7532 before any optimizations are done.
7534 \begin_inset LatexCommand \index{Basic blocks}
7538 at this stage ordered in the depth first number, so they may not be in
7539 sequence of execution.
7541 \labelwidthstring 00.00.0000
7556 \begin_inset LatexCommand \index{-\/-dumpgcse}
7562 Will create a dump of iCode's, after global subexpression elimination
7563 \begin_inset LatexCommand \index{Global subexpression elimination}
7569 <source filename>.dumpgcse.
7571 \labelwidthstring 00.00.0000
7586 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7592 Will create a dump of iCode's, after deadcode elimination
7593 \begin_inset LatexCommand \index{Dead-code elimination}
7599 <source filename>.dumpdeadcode.
7601 \labelwidthstring 00.00.0000
7616 \begin_inset LatexCommand \index{-\/-dumploop}
7625 Will create a dump of iCode's, after loop optimizations
7626 \begin_inset LatexCommand \index{Loop optimization}
7632 <source filename>.dumploop.
7634 \labelwidthstring 00.00.0000
7649 \begin_inset LatexCommand \index{-\/-dumprange}
7658 Will create a dump of iCode's, after live range analysis
7659 \begin_inset LatexCommand \index{Live range analysis}
7665 <source filename>.dumprange.
7667 \labelwidthstring 00.00.0000
7682 \begin_inset LatexCommand \index{-\/-dumlrange}
7688 Will dump the life ranges
7689 \begin_inset LatexCommand \index{Live range analysis}
7695 \labelwidthstring 00.00.0000
7710 \begin_inset LatexCommand \index{-\/-dumpregassign}
7719 Will create a dump of iCode's, after register assignment
7720 \begin_inset LatexCommand \index{Register assignment}
7726 <source filename>.dumprassgn.
7728 \labelwidthstring 00.00.0000
7743 \begin_inset LatexCommand \index{-\/-dumplrange}
7749 Will create a dump of the live ranges of iTemp's
7751 \labelwidthstring 00.00.0000
7766 \begin_inset LatexCommand \index{-\/-dumpall}
7777 Will cause all the above mentioned dumps to be created.
7780 Redirecting output on Windows Shells
7783 By default SDCC writes it's error messages to
7784 \begin_inset Quotes sld
7788 \begin_inset Quotes srd
7792 To force all messages to
7793 \begin_inset Quotes sld
7797 \begin_inset Quotes srd
7821 \begin_inset LatexCommand \index{-\/-use-stdout}
7826 Additionally, if you happen to have visual studio installed in your windows
7827 machine, you can use it to compile your sources using a custom build and
7843 \begin_inset LatexCommand \index{-\/-vc}
7848 Something like this should work:
7892 -model-large -c $(InputPath)
7895 Environment variables
7896 \begin_inset LatexCommand \index{Environment variables}
7903 SDCC recognizes the following environment variables:
7905 \labelwidthstring 00.00.0000
7910 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7916 SDCC installs a signal handler
7917 \begin_inset LatexCommand \index{signal handler}
7921 to be able to delete temporary files after an user break (^C) or an exception.
7922 If this environment variable is set, SDCC won't install the signal handler
7923 in order to be able to debug SDCC.
7925 \labelwidthstring 00.00.0000
7932 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7938 Path, where temporary files will be created.
7939 The order of the variables is the search order.
7940 In a standard *nix environment these variables are not set, and there's
7941 no need to set them.
7942 On Windows it's recommended to set one of them.
7944 \labelwidthstring 00.00.0000
7949 \begin_inset LatexCommand \index{SDCC\_HOME}
7956 \begin_inset LatexCommand \ref{sub:Install-paths}
7962 \begin_inset Quotes sld
7966 \begin_inset Quotes srd
7971 \labelwidthstring 00.00.0000
7976 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7983 \begin_inset LatexCommand \ref{sub:Search-Paths}
7989 \begin_inset Quotes sld
7993 \begin_inset Quotes srd
7998 \labelwidthstring 00.00.0000
8003 \begin_inset LatexCommand \index{SDCC\_LIB}
8010 \begin_inset LatexCommand \ref{sub:Search-Paths}
8016 \begin_inset Quotes sld
8020 \begin_inset Quotes srd
8026 There are some more environment variables recognized by SDCC, but these
8027 are solely used for debugging purposes.
8028 They can change or disappear very quickly, and will never be documented.
8031 Storage Class Language Extensions
8034 MCS51/DS390 Storage Class
8035 \begin_inset LatexCommand \index{Storage class}
8042 In addition to the ANSI storage classes SDCC allows the following MCS51
8043 specific storage classes:
8044 \layout Subsubsection
8047 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8052 \begin_inset LatexCommand \index{near (storage class)}
8063 storage class for the Small Memory model (
8071 can be used synonymously).
8072 Variables declared with this storage class will be allocated in the directly
8073 addressable portion of the internal RAM of a 8051, e.g.:
8078 data unsigned char test_data;
8081 Writing 0x01 to this variable generates the assembly code:
8086 75*00 01\SpecialChar ~
8092 \layout Subsubsection
8095 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8100 \begin_inset LatexCommand \index{far (storage class)}
8107 Variables declared with this storage class will be placed in the external
8113 storage class for the Large Memory model, e.g.:
8118 xdata unsigned char test_xdata;
8121 Writing 0x01 to this variable generates the assembly code:
8126 90s00r00\SpecialChar ~
8155 \layout Subsubsection
8158 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8165 Variables declared with this storage class will be allocated into the indirectly
8166 addressable portion of the internal ram of a 8051, e.g.:
8171 idata unsigned char test_idata;
8174 Writing 0x01 to this variable generates the assembly code:
8203 Please note, the first 128 byte of idata physically access the same RAM
8205 The original 8051 had 128 byte idata memory, nowadays most devices have
8206 256 byte idata memory.
8208 \begin_inset LatexCommand \index{stack}
8212 is located in idata memory.
8213 \layout Subsubsection
8216 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8223 Paged xdata access is currently not as straightforward as using the other
8224 addressing modes of a 8051.
8225 The following example writes 0x01 to the address pointed to.
8226 Please note, pdata access physically accesses xdata memory.
8227 The high byte of the address is determined by port P2
8228 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8232 (or in case of some 8051 variants by a separate Special Function Register,
8234 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8243 pdata unsigned char *test_pdata_ptr;
8255 test_pdata_ptr = (pdata *)0xfe;
8261 *test_pdata_ptr = 1;
8266 Generates the assembly code:
8271 75*01 FE\SpecialChar ~
8275 _test_pdata_ptr,#0xFE
8307 Be extremely carefull if you use pdata together with the -
8318 \begin_inset LatexCommand \index{-\/-xstack}
8323 \layout Subsubsection
8326 \begin_inset LatexCommand \index{code}
8333 'Variables' declared with this storage class will be placed in the code
8339 code unsigned char test_code;
8342 Read access to this variable generates the assembly code:
8347 90s00r6F\SpecialChar ~
8350 mov dptr,#_test_code
8379 indexed arrays of characters in code memory can be accessed efficiently:
8384 code char test_array[] = {'c','h','e','a','p'};
8387 Read access to this array using an 8-bit unsigned index generates the assembly
8404 90s00r41\SpecialChar ~
8407 mov dptr,#_test_array
8422 \layout Subsubsection
8425 \begin_inset LatexCommand \index{bit}
8432 This is a data-type and a storage class specifier.
8433 When a variable is declared as a bit, it is allocated into the bit addressable
8434 memory of 8051, e.g.:
8442 Writing 1 to this variable generates the assembly code:
8458 The bit addressable memory consists of 128 bits which are located from 0x20
8459 to 0x2f in data memory.
8462 Apart from this 8051 specific storage class most architectures support ANSI-C
8464 \begin_inset LatexCommand \index{bitfields}
8474 Not really meant as examples, but nevertheless showing what bitfields are
8475 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8479 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8480 signed modifier are implemented as unsigned.
8481 \layout Subsubsection
8484 \begin_inset LatexCommand \index{sfr}
8489 \begin_inset LatexCommand \index{sbit}
8496 Like the bit keyword,
8500 signifies both a data-type and storage class, they are used to describe
8521 variables of a 8051, eg:
8527 \begin_inset LatexCommand \index{at}
8531 0x80 P0;\SpecialChar ~
8532 /* special function register P0 at location 0x80 */
8534 sbit at 0xd7 CY; /* CY (Carry Flag
8535 \begin_inset LatexCommand \index{Flags}
8540 \begin_inset LatexCommand \index{Carry flag}
8547 Special function registers which are located on an address dividable by
8548 8 are bit-addressable, an
8552 addresses a specific bit within these sfr.
8553 \layout Subsubsection
8556 \begin_inset LatexCommand \index{Pointer}
8560 to MCS51/DS390 specific memory spaces
8563 SDCC allows (via language extensions) pointers to explicitly point to any
8564 of the memory spaces
8565 \begin_inset LatexCommand \index{Memory model}
8570 In addition to the explicit pointers, the compiler uses (by default) generic
8571 pointers which can be used to point to any of the memory spaces.
8575 Pointer declaration examples:
8580 /* pointer physically in internal ram pointing to object in external ram
8583 xdata unsigned char * data p;
8587 /* pointer physically in external ram pointing to object in internal ram
8590 data unsigned char * xdata p;
8594 /* pointer physically in code rom pointing to data in xdata space */
8596 xdata unsigned char * code p;
8600 /* pointer physically in code space pointing to data in code space */
8602 code unsigned char * code p;
8606 /* the following is a generic pointer physically located in xdata space
8612 Well you get the idea.
8617 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
8630 The highest order byte of the
8634 pointers contains the data space information.
8635 Assembler support routines are called whenever data is stored or retrieved
8641 These are useful for developing reusable library
8642 \begin_inset LatexCommand \index{Libraries}
8647 Explicitly specifying the pointer type will generate the most efficient
8649 \layout Subsubsection
8651 Notes on MCS51 memory
8652 \begin_inset LatexCommand \index{MCS51 memory}
8659 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8660 RAM memory which is structured as follows:
8664 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8667 - Bytes 20-2F - 16 bytes to hold 128 bit
8668 \begin_inset LatexCommand \index{bit}
8674 - Bytes 30-7F - 80 bytes for general purpose use.
8679 Additionally some members of the MCS51 family may have up to 128 bytes of
8680 additional, indirectly addressable, internal RAM memory (
8685 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8690 Furthermore, some chips may have some built in external memory (
8695 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8699 ) which should not be confused with the internal, directly addressable RAM
8705 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8710 Sometimes this built in
8714 memory has to be activated before using it (you can probably find this
8715 information on the datasheet of the microcontroller your are using, see
8717 \begin_inset LatexCommand \ref{sub:Startup-Code}
8725 Normally SDCC will only use the first bank
8726 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8730 of registers (register bank 0), but it is possible to specify that other
8731 banks of registers should be used in interrupt
8732 \begin_inset LatexCommand \index{interrupt}
8737 By default, the compiler will place the stack after the last byte of allocated
8738 memory for variables.
8739 For example, if the first 2 banks of registers are used, and only four
8744 variables, it will position the base of the internal stack at address 20
8746 This implies that as the stack
8747 \begin_inset LatexCommand \index{stack}
8751 grows, it will use up the remaining register banks, and the 16 bytes used
8752 by the 128 bit variables, and 80 bytes for general purpose use.
8753 If any bit variables are used, the data variables will be placed after
8754 the byte holding the last bit variable.
8755 For example, if register banks 0 and 1 are used, and there are 9 bit variables
8760 variables will be placed starting at address 0x22.
8772 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8776 to specify the start address of the
8790 -iram-size to specify the size of the total internal RAM (
8802 By default the 8051 linker will place the stack after the last byte of data
8815 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8819 allows you to specify the start of the stack, i.e.
8820 you could start it after any data in the general purpose area.
8821 If your microcontroller has additional indirectly addressable internal
8826 ) you can place the stack on it.
8827 You may also need to use -
8838 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8842 to set the start address of the external RAM (
8857 \begin_inset LatexCommand \index{-\/-data-loc}
8861 to specify its size.
8862 Same goes for the code memory, using -
8873 \begin_inset LatexCommand \index{-\/-data-loc}
8888 \begin_inset LatexCommand \index{-\/-data-loc}
8893 If in doubt, don't specify any options and see if the resulting memory
8894 layout is appropriate, then you can adjust it.
8897 The linker generates two files with memory allocation information.
8898 The first, with extension .map
8899 \begin_inset LatexCommand \index{<file>.map}
8903 shows all the variables and segments.
8904 The second with extension .mem
8905 \begin_inset LatexCommand \index{<file>.mem}
8909 shows the final memory layout.
8910 The linker will complain either if memory segments overlap, there is not
8911 enough memory, or there is not enough space for stack.
8912 If you get any linking warnings and/or errors related to stack or segments
8913 allocation, take a look at either the .map or .mem files to find out what
8915 The .mem file may even suggest a solution to the problem.
8918 Z80/Z180 Storage Class
8919 \begin_inset LatexCommand \index{Storage class}
8924 \layout Subsubsection
8927 \begin_inset LatexCommand \index{sfr}
8931 (in/out to 8-bit addresses)
8935 \begin_inset LatexCommand \index{Z80}
8939 family has separate address spaces for memory and
8949 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8953 is accessed with special instructions, e.g.:
8958 sfr at 0x78 IoPort;\SpecialChar ~
8960 /* define a var in I/O space at 78h called IoPort */
8964 Writing 0x01 to this variable generates the assembly code:
8984 \layout Subsubsection
8987 \begin_inset LatexCommand \index{sfr}
8991 (in/out to 16-bit addresses)
8998 is used to support 16 bit addresses in I/O memory e.g.:
9004 \begin_inset LatexCommand \index{at}
9011 Writing 0x01 to this variable generates the assembly code:
9016 01 23 01\SpecialChar ~
9036 \layout Subsubsection
9039 \begin_inset LatexCommand \index{sfr}
9043 (in0/out0 to 8 bit addresses on Z180
9044 \begin_inset LatexCommand \index{Z180}
9049 \begin_inset LatexCommand \index{HD64180}
9056 The compiler option -
9066 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
9068 \begin_inset LatexCommand \index{\#pragma portmode}
9072 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
9082 If you include the file z180.h this will be set automatically.
9086 \begin_inset LatexCommand \index{Storage class}
9091 \layout Subsubsection
9094 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9101 The data storage class declares a variable that resides in the first 256
9102 bytes of memory (the direct page).
9103 The HC08 is most efficient at accessing variables (especially pointers)
9105 \layout Subsubsection
9108 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9115 The xdata storage class declares a variable that can reside anywhere in
9117 This is the default if no storage class is specified.
9122 \begin_inset LatexCommand \index{Absolute addressing}
9129 Data items can be assigned an absolute address with the
9132 \begin_inset LatexCommand \index{at}
9138 keyword, in addition to a storage class, e.g.:
9144 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9149 \begin_inset LatexCommand \index{at}
9153 0x7ffe unsigned int chksum;
9156 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
9157 of the external ram.
9162 reserve any space for variables declared in this way (they are implemented
9163 with an equate in the assembler).
9164 Thus it is left to the programmer to make sure there are no overlaps with
9165 other variables that are declared without the absolute address.
9166 The assembler listing file (.lst
9167 \begin_inset LatexCommand \index{<file>.lst}
9171 ) and the linker output files (.rst
9172 \begin_inset LatexCommand \index{<file>.rst}
9177 \begin_inset LatexCommand \index{<file>.map}
9181 ) are good places to look for such overlaps.
9182 Variables with an absolute address are
9187 \begin_inset LatexCommand \index{Variable initialization}
9194 In case of memory mapped I/O devices the keyword
9198 has to be used to tell the compiler that accesses might not be removed:
9204 \begin_inset LatexCommand \index{volatile}
9209 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9214 \begin_inset LatexCommand \index{at}
9218 0x8000 unsigned char PORTA_8255;
9221 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9226 \begin_inset LatexCommand \index{Aligned array}
9233 starts at a block (256 byte) boundary
9234 \begin_inset LatexCommand \index{block boundary}
9239 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9245 Absolute addresses can be specified for variables in all storage classes,
9252 \begin_inset LatexCommand \index{bit}
9257 \begin_inset LatexCommand \index{at}
9264 The above example will allocate the variable at offset 0x02 in the bit-addressab
9266 There is no real advantage to assigning absolute addresses to variables
9267 in this manner, unless you want strict control over all the variables allocated.
9268 One possible use would be to write hardware portable code.
9269 For example, if you have a routine that uses one or more of the microcontroller
9270 I/O pins, and such pins are different for two different hardwares, you
9271 can declare the I/O pins in your routine using:
9276 extern volatile bit MOSI;\SpecialChar ~
9280 /* master out, slave in */
9282 extern volatile bit MISO;\SpecialChar ~
9286 /* master in, slave out */
9288 extern volatile bit MCLK;\SpecialChar ~
9296 /* Input and Output of a byte on a 3-wire serial bus.
9301 If needed adapt polarity of clock, polarity of data and bit order
9306 unsigned char spi_io(unsigned char out_byte)
9330 MOSI = out_byte & 0x80;
9360 /* _asm nop _endasm; */\SpecialChar ~
9368 /* for slow peripherals */
9419 Then, someplace in the code for the first hardware you would use
9424 bit at 0x80 MOSI;\SpecialChar ~
9428 /* I/O port 0, bit 0 */
9430 bit at 0x81 MISO;\SpecialChar ~
9434 /* I/O port 0, bit 1 */
9436 bit at 0x82 MCLK;\SpecialChar ~
9440 /* I/O port 0, bit 2 */
9443 Similarly, for the second hardware you would use
9448 bit at 0x83 MOSI;\SpecialChar ~
9452 /* I/O port 0, bit 3 */
9454 bit at 0x91 MISO;\SpecialChar ~
9458 /* I/O port 1, bit 1 */
9461 \begin_inset LatexCommand \index{bit}
9465 at 0x92 MCLK;\SpecialChar ~
9469 /* I/O port 1, bit 2 */
9472 and you can use the same hardware dependent routine without changes, as
9473 for example in a library.
9474 This is somehow similar to sbit, but only one absolute address has to be
9475 specified in the whole project.
9479 \begin_inset LatexCommand \index{Parameters}
9484 \begin_inset LatexCommand \index{function parameter}
9489 \begin_inset LatexCommand \index{local variables}
9494 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
9501 Automatic (local) variables and parameters to functions can either be placed
9502 on the stack or in data-space.
9503 The default action of the compiler is to place these variables in the internal
9504 RAM (for small model) or external RAM (for large model).
9505 This in fact makes them similar to
9508 \begin_inset LatexCommand \index{static}
9514 so by default functions are non-reentrant
9515 \begin_inset LatexCommand \index{reentrant}
9524 They can be placed on the stack
9525 \begin_inset LatexCommand \index{stack}
9542 \begin_inset LatexCommand \index{-\/-stack-auto}
9550 #pragma\SpecialChar ~
9554 \begin_inset LatexCommand \index{\#pragma stackauto}
9561 \begin_inset LatexCommand \index{reentrant}
9567 keyword in the function declaration, e.g.:
9572 unsigned char foo(char i) reentrant
9586 Since stack space on 8051 is limited, the
9604 option should be used sparingly.
9605 Note that the reentrant keyword just means that the parameters & local
9606 variables will be allocated to the stack, it
9610 mean that the function is register bank
9611 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9620 \begin_inset LatexCommand \index{local variables}
9624 can be assigned storage classes and absolute
9625 \begin_inset LatexCommand \index{Absolute addressing}
9642 xdata unsigned char i;
9655 \begin_inset LatexCommand \index{at}
9659 0x31 unsigned char j;
9671 In the above example the variable
9675 will be allocated in the external ram,
9679 in bit addressable space and
9698 or when a function is declared as
9702 this should only be done for static variables.
9706 \begin_inset LatexCommand \index{function parameter}
9710 however are not allowed any storage class
9711 \begin_inset LatexCommand \index{Storage class}
9715 , (storage classes for parameters will be ignored), their allocation is
9716 governed by the memory model in use, and the reentrancy options.
9720 \begin_inset LatexCommand \label{sub:Overlaying}
9725 \begin_inset LatexCommand \index{Overlaying}
9733 \begin_inset LatexCommand \index{reentrant}
9737 functions SDCC will try to reduce internal ram space usage by overlaying
9738 parameters and local variables of a function (if possible).
9739 Parameters and local variables
9740 \begin_inset LatexCommand \index{local variables}
9744 of a function will be allocated to an overlayable segment if the function
9747 no other function calls and the function is non-reentrant and the memory
9749 \begin_inset LatexCommand \index{Memory model}
9756 If an explicit storage class
9757 \begin_inset LatexCommand \index{Storage class}
9761 is specified for a local variable, it will NOT be overlayed.
9764 Note that the compiler (not the linkage editor) makes the decision for overlayin
9766 Functions that are called from an interrupt service routine should be preceded
9767 by a #pragma\SpecialChar ~
9769 \begin_inset LatexCommand \index{\#pragma nooverlay}
9773 if they are not reentrant.
9776 Also note that the compiler does not do any processing of inline assembler
9777 code, so the compiler might incorrectly assign local variables and parameters
9778 of a function into the overlay segment if the inline assembler code calls
9779 other c-functions that might use the overlay.
9780 In that case the #pragma\SpecialChar ~
9781 nooverlay should be used.
9784 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9786 \begin_inset LatexCommand \index{Multiplication}
9791 \begin_inset LatexCommand \index{Division}
9795 will NOT be overlayed since these are implemented using external functions,
9804 \begin_inset LatexCommand \index{\#pragma nooverlay}
9810 void set_error(unsigned char errcd)
9826 void some_isr () interrupt
9827 \begin_inset LatexCommand \index{interrupt}
9857 In the above example the parameter
9865 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9867 not present, this could cause unpredictable runtime behavior when called
9868 from an interrupt service routine.
9869 The #pragma\SpecialChar ~
9870 nooverlay ensures that the parameters and local variables for
9871 the function are NOT overlayed.
9874 Interrupt Service Routines
9875 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9897 outines to be coded in C, with some extended keywords.
9902 void timer_isr (void) interrupt 1 using 1
9916 The optional number following the
9919 \begin_inset LatexCommand \index{interrupt}
9925 keyword is the interrupt number this routine will service.
9926 When present, the compiler will insert a call to this routine in the interrupt
9927 vector table for the interrupt number specified.
9928 If you have multiple source files in your project, interrupt service routines
9929 can be present in any of them, but a prototype of the isr MUST be present
9930 or included in the file that contains the function
9939 keyword can be used to tell the compiler to use the specified register
9940 bank (8051 specific) when generating code for this function.
9946 Interrupt service routines open the door for some very interesting bugs:
9948 If an interrupt service routine changes variables which are accessed by
9949 other functions these variables have to be declared
9954 \begin_inset LatexCommand \index{volatile}
9962 If the access to these variables is not
9965 \begin_inset LatexCommand \index{atomic}
9972 the processor needs more than one instruction for the access and could
9973 be interrupted while accessing the variable) the interrupt must be disabled
9974 during the access to avoid inconsistent data.
9975 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9976 and should be protected by disabling interrupts.
9977 You're not automatically on the safe side if you use 8 bit variables though.
9978 We need an example here: f.e.
9979 on the 8051 the harmless looking
9980 \begin_inset Quotes srd
9990 \begin_inset Quotes sld
9999 \begin_inset Quotes srd
10004 flags\SpecialChar ~
10009 \begin_inset Quotes sld
10012 from within an interrupt routine might get lost if the interrupt occurs
10015 \begin_inset Quotes sld
10020 counter\SpecialChar ~
10025 \begin_inset Quotes srd
10028 is not atomic on the 8051 even if
10032 is located in data memory.
10033 Bugs like these are hard to reproduce and can cause a lot of trouble.
10037 The return address and the registers used in the interrupt service routine
10038 are saved on the stack
10039 \begin_inset LatexCommand \index{stack}
10043 so there must be sufficient stack space.
10044 If there isn't variables or registers (or even the return address itself)
10051 \begin_inset LatexCommand \index{stack overflow}
10055 is most likely to happen if the interrupt occurs during the
10056 \begin_inset Quotes sld
10060 \begin_inset Quotes srd
10063 subroutine when the stack is already in use for f.e.
10064 many return addresses.
10067 A special note here, int (16 bit) and long (32 bit) integer division
10068 \begin_inset LatexCommand \index{Division}
10073 \begin_inset LatexCommand \index{Multiplication}
10078 \begin_inset LatexCommand \index{Modulus}
10083 \begin_inset LatexCommand \index{Floating point support}
10087 operations are implemented using external support routines developed in
10089 If an interrupt service routine needs to do any of these operations then
10090 the support routines (as mentioned in a following section) will have to
10091 be recompiled using the
10104 \begin_inset LatexCommand \index{-\/-stack-auto}
10110 option and the source file will need to be compiled using the
10125 \begin_inset LatexCommand \index{-\/-int-long-reent}
10132 Calling other functions from an interrupt service routine is not recommended,
10133 avoid it if possible.
10134 Note that when some function is called from an interrupt service routine
10135 it should be preceded by a #pragma\SpecialChar ~
10137 \begin_inset LatexCommand \index{\#pragma nooverlay}
10141 if it is not reentrant.
10142 Furthermore nonreentrant functions should not be called from the main program
10143 while the interrupt service routine might be active.
10149 \begin_inset LatexCommand \ref{sub:Overlaying}
10154 about Overlaying and section
10155 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10160 about Functions using private register banks.
10163 MCS51/DS390 Interrupt Service Routines
10166 Interrupt numbers and the corresponding address & descriptions for the Standard
10167 8051/8052 are listed below.
10168 SDCC will automatically adjust the interrupt vector table to the maximum
10169 interrupt number specified.
10175 \begin_inset Tabular
10176 <lyxtabular version="3" rows="7" columns="3">
10178 <column alignment="center" valignment="top" leftline="true" width="0in">
10179 <column alignment="center" valignment="top" leftline="true" width="0in">
10180 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10181 <row topline="true" bottomline="true">
10182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10207 <row topline="true">
10208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10233 <row topline="true">
10234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10250 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10259 <row topline="true">
10260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10285 <row topline="true">
10286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10311 <row topline="true">
10312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10337 <row topline="true" bottomline="true">
10338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10372 If the interrupt service routine is defined without
10375 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10381 a register bank or with register bank 0 (
10385 0), the compiler will save the registers used by itself on the stack upon
10386 entry and restore them at exit, however if such an interrupt service routine
10387 calls another function then the entire register bank will be saved on the
10389 This scheme may be advantageous for small interrupt service routines which
10390 have low register usage.
10393 If the interrupt service routine is defined to be using a specific register
10398 & psw are saved and restored, if such an interrupt service routine calls
10399 another function (using another register bank) then the entire register
10400 bank of the called function will be saved on the stack.
10401 This scheme is recommended for larger interrupt service routines.
10404 HC08 Interrupt Service Routines
10407 Since the number of interrupts available is chip specific and the interrupt
10408 vector table always ends at the last byte of memory, the interrupt numbers
10409 corresponds to the interrupt vectors in reverse order of address.
10410 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10411 2 will use the interrupt vector at 0xfffa, and so on.
10412 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10413 this way; instead see section
10414 \begin_inset LatexCommand \ref{sub:Startup-Code}
10418 for details on customizing startup.
10421 Z80 Interrupt Service Routines
10424 The Z80 uses several different methods for determining the correct interrupt
10425 vector depending on the hardware implementation.
10426 Therefore, SDCC ignores the optional interrupt number and does not attempt
10427 to generate an interrupt vector table.
10430 By default, SDCC generates code for a maskable interrupt, which uses an
10431 RETI instruction to return from the interrupt.
10432 To write an interrupt handler for the non-maskable interrupt, which needs
10433 an RETN instruction instead, add the
10442 void nmi_isr (void) critical interrupt
10456 Enabling and Disabling Interrupts
10459 Critical Functions and Critical Statements
10462 A special keyword may be associated with a block or a function declaring
10468 SDCC will generate code to disable all interrupts
10469 \begin_inset LatexCommand \index{interrupt}
10473 upon entry to a critical function and restore the interrupt enable to the
10474 previous state before returning.
10475 Nesting critical functions will need one additional byte on the stack
10476 \begin_inset LatexCommand \index{stack}
10485 int foo () critical
10486 \begin_inset LatexCommand \index{critical}
10511 The critical attribute maybe used with other attributes like
10521 may also be used to disable interrupts more locally:
10529 More than one statement could have been included in the block.
10532 Enabling and Disabling Interrupts directly
10536 \begin_inset LatexCommand \index{interrupt}
10540 can also be disabled and enabled directly (8051):
10545 EA = 0;\SpecialChar ~
10608 EA = 1;\SpecialChar ~
10675 On other architectures which have seperate opcodes for enabling and disabling
10676 interrupts you might want to make use of defines with inline assembly
10677 \begin_inset LatexCommand \index{Assembler routines}
10687 \begin_inset LatexCommand \index{\_asm}
10696 \begin_inset LatexCommand \index{\_endasm}
10705 #define SEI _asm\SpecialChar ~
10717 Note: it is sometimes sufficient to disable only a specific interrupt source
10719 a timer or serial interrupt by manipulating an
10722 \begin_inset LatexCommand \index{interrupt mask}
10732 Usually the time during which interrupts are disabled should be kept as
10734 This minimizes both
10739 \begin_inset LatexCommand \index{interrupt latency}
10743 (the time between the occurrence of the interrupt and the execution of
10744 the first code in the interrupt routine) and
10749 \begin_inset LatexCommand \index{interrupt jitter}
10753 (the difference between the shortest and the longest interrupt latency).
10754 These really are something different, f.e.
10755 a serial interrupt has to be served before its buffer overruns so it cares
10756 for the maximum interrupt latency, whereas it does not care about jitter.
10757 On a loudspeaker driven via a digital to analog converter which is fed
10758 by an interrupt a latency of a few milliseconds might be tolerable, whereas
10759 a much smaller jitter will be very audible.
10762 You can reenable interrupts within an interrupt routine and on some architecture
10763 s you can make use of two (or more) levels of
10765 interrupt priorities
10768 \begin_inset LatexCommand \index{interrupt priority}
10773 On some architectures which don't support interrupt priorities these can
10774 be implemented by manipulating the interrupt mask and reenabling interrupts
10775 within the interrupt routine.
10776 Check there is sufficient space on the stack
10777 \begin_inset LatexCommand \index{stack}
10781 and don't add complexity unless you have to.
10786 \begin_inset LatexCommand \index{semaphore}
10790 locking (mcs51/ds390)
10793 Some architectures (mcs51/ds390) have an atomic
10794 \begin_inset LatexCommand \index{atomic}
10807 These type of instructions are typically used in preemptive multitasking
10808 systems, where a routine f.e.
10809 claims the use of a data structure ('acquires a lock
10810 \begin_inset LatexCommand \index{lock}
10814 on it'), makes some modifications and then releases the lock when the data
10815 structure is consistent again.
10816 The instruction may also be used if interrupt and non-interrupt code have
10817 to compete for a resource.
10818 With the atomic bit test and clear instruction interrupts
10819 \begin_inset LatexCommand \index{interrupt}
10823 don't have to be disabled for the locking operation.
10827 SDCC generates this instruction if the source follows this pattern:
10832 volatile bit resource_is_free;
10836 if (resource_is_free)
10846 resource_is_free=0;
10859 resource_is_free=1;
10866 Note, mcs51 and ds390 support only an atomic
10867 \begin_inset LatexCommand \index{atomic}
10875 instruction (as opposed to atomic bit test and
10880 Functions using private register banks
10881 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10888 Some architectures have support for quickly changing register sets.
10889 SDCC supports this feature with the
10892 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10898 attribute (which tells the compiler to use a register bank
10899 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10903 other than the default bank zero).
10904 It should only be applied to
10907 \begin_inset LatexCommand \index{interrupt}
10913 functions (see footnote below).
10914 This will in most circumstances make the generated ISR code more efficient
10915 since it will not have to save registers on the stack.
10922 attribute will have no effect on the generated code for a
10926 function (but may occasionally be useful anyway
10932 possible exception: if a function is called ONLY from 'interrupt' functions
10933 using a particular bank, it can be declared with the same 'using' attribute
10934 as the calling 'interrupt' functions.
10935 For instance, if you have several ISRs using bank one, and all of them
10936 call memcpy(), it might make sense to create a specialized version of memcpy()
10937 'using 1', since this would prevent the ISR from having to save bank zero
10938 to the stack on entry and switch to bank zero before calling the function
10945 (pending: I don't think this has been done yet)
10952 function using a non-zero bank will assume that it can trash that register
10953 bank, and will not save it.
10954 Since high-priority interrupts
10955 \begin_inset LatexCommand \index{interrupt priority}
10959 can interrupt low-priority ones on the 8051 and friends, this means that
10960 if a high-priority ISR
10964 a particular bank occurs while processing a low-priority ISR
10968 the same bank, terrible and bad things can happen.
10969 To prevent this, no single register bank should be
10973 by both a high priority and a low priority ISR.
10974 This is probably most easily done by having all high priority ISRs use
10975 one bank and all low priority ISRs use another.
10976 If you have an ISR which can change priority at runtime, you're on your
10977 own: I suggest using the default bank zero and taking the small performance
10981 It is most efficient if your ISR calls no other functions.
10982 If your ISR must call other functions, it is most efficient if those functions
10983 use the same bank as the ISR (see note 1 below); the next best is if the
10984 called functions use bank zero.
10985 It is very inefficient to call a function using a different, non-zero bank
10991 \begin_inset LatexCommand \label{sub:Startup-Code}
10996 \begin_inset LatexCommand \index{Startup code}
11003 MCS51/DS390 Startup Code
11006 The compiler inserts a call to the C routine
11008 _sdcc_external_startup()
11009 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
11018 at the start of the CODE area.
11019 This routine is in the runtime library
11020 \begin_inset LatexCommand \index{Runtime library}
11025 By default this routine returns 0, if this routine returns a non-zero value,
11026 the static & global variable initialization will be skipped and the function
11027 main will be invoked.
11028 Otherwise static & global variables will be initialized before the function
11032 _sdcc_external_startup()
11034 routine to your program to override the default if you need to setup hardware
11035 or perform some other critical operation prior to static & global variable
11037 On some mcs51 variants xdata has to be explicitly enabled before it can
11038 be accessed, this is the place to do it.
11039 The startup code clears the complete 256 byte of idata memory, this might
11040 cause problems for 128 byte devices (endless loop reported for Chipcon
11044 See also the compiler option
11063 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
11068 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11073 about MCS51-variants.
11079 The HC08 startup code follows the same scheme as the MCS51 startup code.
11085 On the Z80 the startup code is inserted by linking with crt0.o which is generated
11086 from sdcc/device/lib/z80/crt0.s.
11087 If you need a different startup code you can use the compiler option
11108 \begin_inset LatexCommand \index{-\/-no-std-crt0}
11112 and provide your own crt0.o.
11116 Inline Assembler Code
11117 \begin_inset LatexCommand \index{Assembler routines}
11124 A Step by Step Introduction
11125 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
11132 Starting from a small snippet of c-code this example shows for the MCS51
11133 how to use inline assembly, access variables, a function parameter and
11134 an array in xdata memory.
11135 The example uses an MCS51 here but is easily adapted for other architectures.
11136 This is a buffer routine which should be optimized:
11143 \begin_inset LatexCommand \index{far (storage class)}
11148 \begin_inset LatexCommand \index{at}
11153 \begin_inset LatexCommand \index{Aligned array}
11159 unsigned char head,tail;
11163 void to_buffer( unsigned char c )
11171 if( head != tail-1 )
11181 buf[ head++ ] = c;\SpecialChar ~
11185 /* access to a 256 byte aligned array */
11190 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
11191 then a corresponding buffer.asm file is generated.
11192 We define a new function
11196 in file buffer.c in which we cut and paste the generated code, removing
11197 unwanted comments and some ':'.
11199 \begin_inset Quotes sld
11203 \begin_inset Quotes srd
11207 \begin_inset Quotes sld
11211 \begin_inset Quotes srd
11214 to the beginning and the end of the function body:
11220 /* With a cut and paste from the .asm file, we have something to start with.
11225 The function is not yet OK! (registers aren't saved) */
11227 void to_buffer_asm( unsigned char c )
11236 \begin_inset LatexCommand \index{\_asm}
11250 ;buffer.c if( head != tail-1 )
11298 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11299 \begin_inset LatexCommand \index{Aligned array}
11368 The new file buffer.c should compile with only one warning about the unreferenced
11369 function argument 'c'.
11370 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11371 (1) and finally have:
11377 unsigned char far at 0x7f00 buf[0x100];
11379 unsigned char head,tail;
11381 #define USE_ASSEMBLY (1)
11389 void to_buffer( unsigned char c )
11397 if( head != tail-1 )
11417 void to_buffer( unsigned char c )
11425 c; // to avoid warning: unreferenced function argument
11432 \begin_inset LatexCommand \index{\_asm}
11446 ; save used registers here.
11457 ; If we were still using r2,r3 we would have to push them here.
11460 ; if( head != tail-1 )
11503 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11527 ; buf[ head++ ] = c;
11538 a,dpl \SpecialChar ~
11545 ; dpl holds lower byte of function argument
11556 dpl,_head \SpecialChar ~
11559 ; buf is 0x100 byte aligned so head can be used directly
11601 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11613 ; restore used registers here
11626 The inline assembler code can contain any valid code understood by the assembler
11627 , this includes any assembler directives and comment lines
11633 The assembler does not like some characters like ':' or ''' in comments.
11634 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11638 The compiler does not do any validation of the code within the
11641 \begin_inset LatexCommand \index{\_asm}
11649 Specifically it will not know which registers are used and thus register
11651 \begin_inset LatexCommand \index{push/pop}
11655 has to be done manually.
11659 It is recommended that each assembly instruction (including labels) be placed
11660 in a separate line (as the example shows).
11674 \begin_inset LatexCommand \index{-\/-peep-asm}
11680 command line option is used, the inline assembler code will be passed through
11681 the peephole optimizer
11682 \begin_inset LatexCommand \index{Peephole optimizer}
11687 There are only a few (if any) cases where this option makes sense, it might
11688 cause some unexpected changes in the inline assembler code.
11689 Please go through the peephole optimizer rules defined in file
11693 before using this option.
11697 \begin_inset LatexCommand \label{sub:Naked-Functions}
11702 \begin_inset LatexCommand \index{Naked functions}
11709 A special keyword may be associated with a function declaring it as
11712 \begin_inset LatexCommand \index{\_naked}
11723 function modifier attribute prevents the compiler from generating prologue
11724 \begin_inset LatexCommand \index{function prologue}
11729 \begin_inset LatexCommand \index{function epilogue}
11733 code for that function.
11734 This means that the user is entirely responsible for such things as saving
11735 any registers that may need to be preserved, selecting the proper register
11736 bank, generating the
11740 instruction at the end, etc.
11741 Practically, this means that the contents of the function must be written
11742 in inline assembler.
11743 This is particularly useful for interrupt functions, which can have a large
11744 (and often unnecessary) prologue/epilogue.
11745 For example, compare the code generated by these two functions:
11751 \begin_inset LatexCommand \index{volatile}
11755 data unsigned char counter;
11759 void simpleInterrupt(void) interrupt
11760 \begin_inset LatexCommand \index{interrupt}
11778 void nakedInterrupt(void) interrupt 2 _naked
11787 \begin_inset LatexCommand \index{\_asm}
11804 _counter ; does not change flags, no need to save psw
11816 ; MUST explicitly include ret or reti in _naked function.
11823 \begin_inset LatexCommand \index{\_endasm}
11832 For an 8051 target, the generated simpleInterrupt looks like:
11973 whereas nakedInterrupt looks like:
11988 _counter ; does not change flags, no need to save psw
12006 ; MUST explicitly include ret or reti in _naked function
12009 The related directive #pragma exclude
12010 \begin_inset LatexCommand \index{\#pragma exclude}
12014 allows a more fine grained control over pushing & popping
12015 \begin_inset LatexCommand \index{push/pop}
12022 While there is nothing preventing you from writing C code inside a
12026 function, there are many ways to shoot yourself in the foot doing this,
12027 and it is recommended that you stick to inline assembler.
12030 Use of Labels within Inline Assembler
12033 SDCC allows the use of in-line assembler with a few restrictions regarding
12035 In older versions of the compiler all labels defined within inline assembler
12044 where nnnn is a number less than 100 (which implies a limit of utmost 100
12045 inline assembler labels
12059 \begin_inset LatexCommand \index{\_asm}
12089 \begin_inset LatexCommand \index{\_endasm}
12096 Inline assembler code cannot reference any C-Labels, however it can reference
12098 \begin_inset LatexCommand \index{Labels}
12102 defined by the inline assembler, e.g.:
12127 ; some assembler code
12147 /* some more c code */
12149 clabel:\SpecialChar ~
12151 /* inline assembler cannot reference this label */
12163 $0003: ;label (can be referenced by inline assembler only)
12175 /* some more c code */
12180 In other words inline assembly code can access labels defined in inline
12181 assembly within the scope of the function.
12182 The same goes the other way, i.e.
12183 labels defines in inline assembly can not be accessed by C statements.
12186 Interfacing with Assembler Code
12187 \begin_inset LatexCommand \index{Assembler routines}
12194 Global Registers used for Parameter Passing
12195 \begin_inset LatexCommand \index{Parameter passing}
12202 The compiler always uses the global registers
12205 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12210 \begin_inset LatexCommand \index{DPTR}
12215 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12224 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12230 to pass the first parameter to a routine.
12231 The second parameter onwards is either allocated on the stack (for reentrant
12242 -stack-auto is used) or in data / xdata memory (depending on the memory
12247 Assembler Routine (non-reentrant)
12250 In the following example
12251 \begin_inset LatexCommand \index{reentrant}
12256 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12260 the function c_func calls an assembler routine asm_func, which takes two
12262 \begin_inset LatexCommand \index{function parameter}
12271 extern int asm_func(unsigned char, unsigned char);
12275 int c_func (unsigned char i, unsigned char j)
12283 return asm_func(i,j);
12297 return c_func(10,9);
12302 The corresponding assembler function is:
12307 .globl _asm_func_PARM_2
12408 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12425 Note here that the return values
12426 \begin_inset LatexCommand \index{return value}
12430 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12432 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12433 b' & 'acc' for four byte values.
12436 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12437 the parameter number starting from 1, and counting from the left.
12438 The first parameter is passed in
12439 \begin_inset Quotes eld
12443 \begin_inset Quotes erd
12446 for a one byte parameter,
12447 \begin_inset Quotes eld
12451 \begin_inset Quotes erd
12455 \begin_inset Quotes eld
12459 \begin_inset Quotes erd
12462 for three bytes and
12463 \begin_inset Quotes eld
12467 \begin_inset Quotes erd
12470 for a four bytes parameter.
12471 The variable name for the second parameter will be _<function_name>_PARM_2.
12475 Assemble the assembler routine with the following command:
12482 asx8051 -losg asmfunc.asm
12489 Then compile and link the assembler routine to the C source file with the
12497 sdcc cfunc.c asmfunc.rel
12500 Assembler Routine (reentrant)
12504 \begin_inset LatexCommand \index{reentrant}
12509 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12513 the second parameter
12514 \begin_inset LatexCommand \index{function parameter}
12518 onwards will be passed on the stack, the parameters are pushed from right
12520 after the call the leftmost parameter will be on the top of the stack.
12521 Here is an example:
12526 extern int asm_func(unsigned char, unsigned char);
12530 int c_func (unsigned char i, unsigned char j) reentrant
12538 return asm_func(i,j);
12552 return c_func(10,9);
12557 The corresponding assembler routine is:
12657 The compiling and linking procedure remains the same, however note the extra
12658 entry & exit linkage required for the assembler code, _bp is the stack
12659 frame pointer and is used to compute the offset into the stack for parameters
12660 and local variables.
12664 \begin_inset LatexCommand \index{int (16 bit)}
12669 \begin_inset LatexCommand \index{long (32 bit)}
12676 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12677 multiplication and modulus operations are implemented by support routines.
12678 These support routines are all developed in ANSI-C to facilitate porting
12679 to other MCUs, although some model specific assembler optimizations are
12681 The following files contain the described routines, all of them can be
12682 found in <installdir>/share/sdcc/lib.
12688 \begin_inset Tabular
12689 <lyxtabular version="3" rows="11" columns="2">
12691 <column alignment="center" valignment="top" leftline="true" width="0">
12692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12693 <row topline="true" bottomline="true">
12694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12715 <row topline="true">
12716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12729 16 bit multiplication
12733 <row topline="true">
12734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12747 signed 16 bit division (calls _divuint)
12751 <row topline="true">
12752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12765 unsigned 16 bit division
12769 <row topline="true">
12770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12783 signed 16 bit modulus (calls _moduint)
12787 <row topline="true">
12788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12801 unsigned 16 bit modulus
12805 <row topline="true">
12806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12819 32 bit multiplication
12823 <row topline="true">
12824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12837 signed 32 division (calls _divulong)
12841 <row topline="true">
12842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12855 unsigned 32 division
12859 <row topline="true">
12860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12873 signed 32 bit modulus (calls _modulong)
12877 <row topline="true" bottomline="true">
12878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12891 unsigned 32 bit modulus
12904 Since they are compiled as
12909 \begin_inset LatexCommand \index{reentrant}
12914 \begin_inset LatexCommand \index{interrupt}
12918 service routines should not do any of the above operations.
12919 If this is unavoidable then the above routines will need to be compiled
12933 \begin_inset LatexCommand \index{-\/-stack-auto}
12939 option, after which the source program will have to be compiled with
12952 \begin_inset LatexCommand \index{-\/-int-long-reent}
12959 Notice that you don't have to call these routines directly.
12960 The compiler will use them automatically every time an integer operation
12964 Floating Point Support
12965 \begin_inset LatexCommand \index{Floating point support}
12972 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12973 floating point support routines are derived from gcc's floatlib.c and consist
12974 of the following routines:
12982 \begin_inset Tabular
12983 <lyxtabular version="3" rows="17" columns="2">
12985 <column alignment="center" valignment="top" leftline="true" width="0">
12986 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12987 <row topline="true" bottomline="true">
12988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13014 <row topline="true">
13015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13046 add floating point numbers
13050 <row topline="true">
13051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13082 subtract floating point numbers
13086 <row topline="true">
13087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13118 divide floating point numbers
13122 <row topline="true">
13123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13154 multiply floating point numbers
13158 <row topline="true">
13159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13190 convert floating point to unsigned char
13194 <row topline="true">
13195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13226 convert floating point to signed char
13230 <row topline="true">
13231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13262 convert floating point to unsigned int
13266 <row topline="true">
13267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13298 convert floating point to signed int
13302 <row topline="true">
13303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13343 convert floating point to unsigned long
13347 <row topline="true">
13348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13379 convert floating point to signed long
13383 <row topline="true">
13384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13415 convert unsigned char to floating point
13419 <row topline="true">
13420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13451 convert char to floating point number
13455 <row topline="true">
13456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13487 convert unsigned int to floating point
13491 <row topline="true">
13492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13523 convert int to floating point numbers
13527 <row topline="true">
13528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13559 convert unsigned long to floating point number
13563 <row topline="true" bottomline="true">
13564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13595 convert long to floating point number
13608 These support routines are developed in ANSI-C so there is room for space
13609 and speed improvement.
13610 Note if all these routines are used simultaneously the data space might
13612 For serious floating point usage it is recommended that the large model
13614 Also notice that you don't have to call this routines directly.
13615 The compiler will use them automatically every time a floating point operation
13620 \begin_inset LatexCommand \index{Libraries}
13629 <pending: this is messy and incomplete - a little more information is in
13630 sdcc/doc/libdoc.txt
13635 Compiler support routines (_gptrget, _mulint etc.)
13638 Stdclib functions (puts, printf, strcat etc.)
13639 \layout Subsubsection
13645 \begin_inset LatexCommand \index{<stdio.h>}
13649 As usual on embedded systems you have to provide your own
13652 \begin_inset LatexCommand \index{getchar()}
13661 \begin_inset LatexCommand \index{putchar()}
13668 SDCC does not know whether the system connects to a serial line with or
13669 without handshake, LCD, keyboard or other device.
13670 You'll find examples for serial routines f.e.
13671 in sdcc/device/lib.
13674 If you're short on memory you might want to use
13685 \begin_inset LatexCommand \index{printf()}
13692 For the mcs51 there is an assembly version
13696 which should fit the requirements of many embedded systems (by unsetting
13697 #defines it can be customized to
13701 support long variables and field widths).
13704 Math functions (sin, pow, sqrt etc.)
13711 \begin_inset LatexCommand \index{Libraries}
13715 included in SDCC should have a license at least as liberal as the GNU Lesser
13716 General Public License
13717 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13728 license statements for the libraries are missing.
13729 sdcc/device/lib/ser_ir.c
13733 come with a GPL (as opposed to LGPL) License - this will not be liberal
13734 enough for many embedded programmers.
13737 If you have ported some library or want to share experience about some code
13739 falls into any of these categories Busses (I
13740 \begin_inset Formula $^{\textrm{2}}$
13743 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13744 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13745 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
13746 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13751 would certainly like to hear about it.
13752 Programmers coding for embedded systems are not especially famous for being
13753 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13754 e these references are very valuable.
13755 Let's help to create a climate where information is shared.
13761 MCS51 Memory Models
13762 \begin_inset LatexCommand \index{Memory model}
13767 \begin_inset LatexCommand \index{MCS51 memory model}
13772 \layout Subsubsection
13777 SDCC allows two memory models for MCS51 code,
13786 Modules compiled with different memory models should
13790 be combined together or the results would be unpredictable.
13791 The library routines supplied with the compiler are compiled as both small
13793 The compiled library modules are contained in separate directories as small
13794 and large so that you can link to either set.
13798 When the large model is used all variables declared without a storage class
13799 will be allocated into the external ram, this includes all parameters and
13800 local variables (for non-reentrant
13801 \begin_inset LatexCommand \index{reentrant}
13806 When the small model is used variables without storage class are allocated
13807 in the internal ram.
13810 Judicious usage of the processor specific storage classes
13811 \begin_inset LatexCommand \index{Storage class}
13815 and the 'reentrant' function type will yield much more efficient code,
13816 than using the large model.
13817 Several optimizations are disabled when the program is compiled using the
13818 large model, it is therefore recommended that the small model be used unless
13819 absolutely required.
13820 \layout Subsubsection
13823 \begin_inset LatexCommand \label{sub:External-Stack}
13828 \begin_inset LatexCommand \index{stack}
13833 \begin_inset LatexCommand \index{External stack (mcs51)}
13844 : this option wasn't maintained for a long time and is quite buggy.
13845 Small programs might work.
13846 You've been warned!
13849 The external stack (-
13860 \begin_inset LatexCommand \index{-\/-xstack}
13864 ) is located in pdata
13865 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13869 memory (usually at the start of the external ram segment) and is 256 bytes
13881 -xstack option is used to compile the program, the parameters and local
13883 \begin_inset LatexCommand \index{local variables}
13887 of all reentrant functions are allocated in this area.
13888 This option is provided for programs with large stack space requirements.
13889 When used with the -
13900 \begin_inset LatexCommand \index{-\/-stack-auto}
13904 option, all parameters and local variables are allocated on the external
13905 stack (note: support libraries will need to be recompiled with the same
13909 The compiler outputs the higher order address byte of the external ram segment
13911 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13916 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13920 ), therefore when using the External Stack option, this port
13924 be used by the application program.
13928 \begin_inset LatexCommand \index{Memory model}
13933 \begin_inset LatexCommand \index{DS390 memory model}
13940 The only model supported is Flat 24
13941 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13946 This generates code for the 24 bit contiguous addressing mode of the Dallas
13948 In this mode, up to four meg of external RAM or code space can be directly
13950 See the data sheets at www.dalsemi.com for further information on this part.
13954 Note that the compiler does not generate any code to place the processor
13955 into 24 bitmode (although
13959 in the ds390 libraries will do that for you).
13965 \begin_inset LatexCommand \index{Tinibios (DS390)}
13969 , the boot loader or similar code must ensure that the processor is in 24
13970 bit contiguous addressing mode before calling the SDCC startup code.
13988 option, variables will by default be placed into the XDATA segment.
13993 Segments may be placed anywhere in the 4 meg address space using the usual
14005 Note that if any segments are located above 64K, the -r flag must be passed
14006 to the linker to generate the proper segment relocations, and the Intel
14007 HEX output format must be used.
14008 The -r flag can be passed to the linker by using the option
14012 on the SDCC command line.
14013 However, currently the linker can not handle code segments > 64k.
14017 \begin_inset LatexCommand \index{Pragmas}
14024 SDCC supports the following #pragma directives:
14028 \begin_inset LatexCommand \index{\#pragma save}
14032 - this will save all current options to the save/restore stack.
14033 See #pragma\SpecialChar ~
14038 \begin_inset LatexCommand \index{\#pragma restore}
14042 - will restore saved options from the last save.
14043 saves & restores can be nested.
14044 SDCC uses a save/restore stack: save pushes current options to the stack,
14045 restore pulls current options from the stack.
14046 See #pragma\SpecialChar ~
14053 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14058 \begin_inset LatexCommand \index{function prologue}
14062 function1[,function2[,function3...]] - The compiler by default uses a caller
14063 saves convention for register saving across function calls, however this
14064 can cause unnecessary register pushing & popping
14065 \begin_inset LatexCommand \index{push/pop}
14069 when calling small functions from larger functions.
14070 This option can be used to switch off the register saving convention for
14071 the function names specified.
14072 The compiler will not save registers when calling these functions, extra
14073 code need to be manually inserted at the entry & exit for these functions
14074 to save & restore the registers used by these functions, this can SUBSTANTIALLY
14075 reduce code & improve run time performance of the generated code.
14076 In the future the compiler (with inter procedural analysis) may be able
14077 to determine the appropriate scheme to use for each function call.
14088 -callee-saves command line option is used, the function names specified
14089 in #pragma\SpecialChar ~
14091 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14095 is appended to the list of functions specified in the command line.
14099 \begin_inset LatexCommand \index{\#pragma exclude}
14103 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
14104 of pairs of push/pop
14105 \begin_inset LatexCommand \index{push/pop}
14114 \begin_inset LatexCommand \index{interrupt}
14127 The directive should be placed immediately before the ISR function definition
14128 and it affects ALL ISR functions following it.
14129 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
14130 exclude\SpecialChar ~
14132 \begin_inset LatexCommand \index{\#pragma exclude}
14137 See also the related keyword _naked
14138 \begin_inset LatexCommand \index{\_naked}
14146 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
14150 - the compiler will not warn you anymore for obvious mistakes, you'r on
14155 \begin_inset LatexCommand \index{\#pragma nogcse}
14159 - will stop global common subexpression elimination.
14163 \begin_inset LatexCommand \index{\#pragma noinduction}
14167 - will stop loop induction optimizations.
14171 \begin_inset LatexCommand \index{\#pragma noinvariant}
14175 - will not do loop invariant optimizations.
14176 For more details see Loop Invariants in section
14177 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14185 \begin_inset LatexCommand \index{\#pragma noiv}
14189 - Do not generate interrupt
14190 \begin_inset LatexCommand \index{interrupt}
14194 vector table entries for all ISR functions defined after the pragma.
14195 This is useful in cases where the interrupt vector table must be defined
14196 manually, or when there is a secondary, manually defined interrupt vector
14198 for the autovector feature of the Cypress EZ-USB FX2).
14199 More elegantly this can be achieved by obmitting the optional interrupt
14200 number after the interrupt keyword, see section
14201 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14210 \begin_inset LatexCommand \index{\#pragma nojtbound}
14214 - will not generate code for boundary value checking, when switch statements
14215 are turned into jump-tables (dangerous).
14216 For more details see section
14217 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14225 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14229 - Will not do loop reversal optimization
14233 \begin_inset LatexCommand \index{\#pragma nooverlay}
14237 - the compiler will not overlay the parameters and local variables of a
14242 \begin_inset LatexCommand \index{\#pragma stackauto}
14257 \begin_inset LatexCommand \index{-\/-stack-auto}
14262 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
14266 Parameters and Local Variables.
14270 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
14274 - The compiler will optimize code generation towards fast code, possibly
14275 at the expense of code size.
14279 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
14283 - The compiler will optimize code generation towards compact code, possibly
14284 at the expense of code speed.
14288 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
14292 - The compiler will attempt to generate code that is both compact and fast,
14293 as long as meeting one goal is not a detriment to the other (this is the
14298 SDCPP supports the following #pragma directives:
14302 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
14306 (+ | -) - switch _asm _endasm block preprocessing on / off.
14310 The pragma's are intended to be used to turn-on or off certain optimizations
14311 which might cause the compiler to generate extra stack / data space to
14312 store compiler generated temporary variables.
14313 This usually happens in large functions.
14314 Pragma directives should be used as shown in the following example, they
14315 are used to control options & optimizations for a given function; pragmas
14316 should be placed before and/or after a function, placing pragma's inside
14317 a function body could have unpredictable results.
14323 \begin_inset LatexCommand \index{\#pragma save}
14334 /* save the current settings */
14337 \begin_inset LatexCommand \index{\#pragma nogcse}
14346 /* turnoff global subexpression elimination */
14348 #pragma noinduction
14349 \begin_inset LatexCommand \index{\#pragma noinduction}
14353 /* turn off induction optimizations */
14376 \begin_inset LatexCommand \index{\#pragma restore}
14380 /* turn the optimizations back on */
14383 The compiler will generate a warning message when extra space is allocated.
14384 It is strongly recommended that the save and restore pragma's be used when
14385 changing options for a function.
14388 Defines Created by the Compiler
14391 The compiler creates the following #defines
14392 \begin_inset LatexCommand \index{\#defines}
14397 \begin_inset LatexCommand \index{Defines created by the compiler}
14407 \begin_inset Tabular
14408 <lyxtabular version="3" rows="10" columns="2">
14410 <column alignment="center" valignment="top" leftline="true" width="0">
14411 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14412 <row topline="true" bottomline="true">
14413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14434 <row topline="true">
14435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14441 \begin_inset LatexCommand \index{SDCC}
14448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14453 this Symbol is always defined
14457 <row topline="true">
14458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14464 \begin_inset LatexCommand \index{SDCC\_mcs51}
14469 \begin_inset LatexCommand \index{SDCC\_ds390}
14474 \begin_inset LatexCommand \index{SDCC\_z80}
14481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14486 depending on the model used (e.g.: -mds390
14490 <row topline="true">
14491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14497 \begin_inset LatexCommand \index{\_\_mcs51}
14502 \begin_inset LatexCommand \index{\_\_ds390}
14507 \begin_inset LatexCommand \index{\_\_hc08}
14512 \begin_inset LatexCommand \index{\_\_z80}
14519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14524 depending on the model used (e.g.
14529 <row topline="true">
14530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14536 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14566 <row topline="true">
14567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14573 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14603 <row topline="true">
14604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14610 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14640 <row topline="true">
14641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14647 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14677 <row topline="true">
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14684 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14704 <row topline="true" bottomline="true">
14705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14711 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14738 Notes on supported Processors
14742 \begin_inset LatexCommand \label{sub:MCS51-variants}
14747 \begin_inset LatexCommand \index{MCS51 variants}
14754 MCS51 processors are available from many vendors and come in many different
14756 While they might differ considerably in respect to Special Function Registers
14757 the core MCS51 is usually not modified or is kept compatible.
14761 pdata access by SFR
14764 With the upcome of devices with internal xdata and flash memory devices
14766 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14770 as dedicated I/O port is becoming more popular.
14771 Switching the high byte for pdata
14772 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14776 access which was formerly done by port P2 is then achieved by a Special
14778 \begin_inset LatexCommand \index{sfr}
14783 In well-established MCS51 tradition the address of this
14787 is where the chip designers decided to put it.
14788 Needless to say that they didn't agree on a common name either.
14789 So that the startup code can correctly initialize xdata variables, you
14790 should define an sfr with the name _XPAGE
14793 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14799 at the appropriate location if the default, port P2, is not used for this.
14805 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14810 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14815 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14818 For more exotic implementations further customizations may be needed.
14820 \begin_inset LatexCommand \ref{sub:Startup-Code}
14824 for other possibilities.
14827 Other Features available by SFR
14830 Some MCS51 variants offer features like Double DPTR
14831 \begin_inset LatexCommand \index{DPTR}
14835 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14836 These are currently not used for the MCS51 port.
14837 If you absolutely need them you can fall back to inline assembly or submit
14844 The DS80C400 microcontroller has a rich set of peripherals.
14845 In its built-in ROM library it includes functions to access some of the
14846 features, among them is a TCP stack with IP4 and IP6 support.
14847 Library headers (currently in beta status) and other files are provided
14851 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
14859 The Z80 and gbz80 port
14862 SDCC can target both the Zilog
14863 \begin_inset LatexCommand \index{Z80}
14867 and the Nintendo Gameboy's Z80-like gbz80
14868 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14873 The Z80 port is passed through the same
14876 \begin_inset LatexCommand \index{Regression test}
14882 as the MCS51 and DS390 ports, so floating point support, support for long
14883 variables and bitfield support is fine.
14884 See mailing lists and forums about interrupt routines.
14887 As always, the code is the authoritative reference - see z80/ralloc.c and
14890 \begin_inset LatexCommand \index{stack}
14894 frame is similar to that generated by the IAR Z80 compiler.
14895 IX is used as the base pointer, HL and IY are used as a temporary registers,
14896 and BC and DE are available for holding variables.
14898 \begin_inset LatexCommand \index{return value}
14902 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14904 The gbz80 port use the same set of registers for the return values, but
14905 in a different order of significance: E (one byte), DE (two bytes), or
14912 The port to the Motorola HC08
14913 \begin_inset LatexCommand \index{HC08}
14917 family has been added in October 2003, and is still undergoing some basic
14919 The code generator is complete, but the register allocation is still quite
14921 Some of the SDCC's standard C library functions have embedded non-HC08
14922 inline assembly and so are not yet usable.
14933 \begin_inset LatexCommand \index{PIC14}
14937 port still requires a major effort from the development community.
14938 However it can work for very simple code.
14941 C code and 14bit PIC code page
14942 \begin_inset LatexCommand \index{code page (pic14)}
14947 \begin_inset LatexCommand \index{RAM bank (pic14)}
14954 The linker organizes allocation for the code page and RAM banks.
14955 It does not have intimate knowledge of the code flow.
14956 It will put all the code section of a single asm file into a single code
14958 In order to make use of multiple code pages, separate asm files must be
14960 The compiler treats all functions of a single C file as being in the same
14961 code page unless it is non static.
14962 The compiler treats all local variables of a single C file as being in
14963 the same RAM bank unless it is an extern.
14967 To get the best follow these guide lines:
14970 make local functions static, as non static functions require code page selection
14974 Make local variables static as extern variables require RAM bank selection
14978 For devices that have multiple code pages it is more efficient to use the
14979 same number of files as pages, i.e.
14980 for the 16F877 use 4 separate files and i.e.
14981 for the 16F874 use 2 separate files.
14982 This way the linker can put the code for each file into different code
14983 pages and the compiler can allocate reusable variables more efficiently
14984 and there's less page selection overhead.
14985 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14986 instruction set) use 'unsigned char' whereever possible instead of 'int'.
14989 Creating a device include file
14992 For generating a device include file use the support perl script inc2h.pl
14993 kept in directory support/script.
14999 For the interrupt function, use the keyword 'interrupt'
15000 \begin_inset LatexCommand \index{interrupt}
15004 with level number of 0 (PIC14 only has 1 interrupt so this number is only
15005 there to avoid a syntax error - it ought to be fixed).
15011 void Intr(void) interrupt 0
15017 T0IF = 0; /* Clear timer interrupt */
15022 Linking and assembling
15025 For assembling you can use either GPUTILS'
15026 \begin_inset LatexCommand \index{gputils (pic tools)}
15030 gpasm.exe or MPLAB's mpasmwin.exe.
15031 GPUTILS is available from
15032 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
15037 For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
15038 If you use MPLAB and an interrupt function then the linker script file
15039 vectors section will need to be enlarged to link with mplink.
15062 sdcc -S -V -mpic14 -p16F877 $<
15076 $(PRJ).hex: $(OBJS)
15086 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
15108 sdcc -S -V -mpic14 -p16F877 $<
15118 mpasmwin /q /o $*.asm
15122 $(PRJ).hex: $(OBJS)
15132 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
15135 Please note that indentations within a
15139 have to be done with a tabulator character.
15143 \begin_inset LatexCommand \index{PIC16}
15151 \begin_inset LatexCommand \index{PIC16}
15155 port is the portion of SDCC that is responsible to produce code for the
15157 \begin_inset LatexCommand \index{Microchip}
15161 (TM) microcontrollers with 16 bit core.
15162 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
15168 PIC16 port supports the standard command line arguments as supposed, with
15169 the exception of certain cases that will be mentioned in the following
15172 \labelwidthstring 00.00.0000
15184 -stack-auto Auto variables that are function parameters, will be saved on
15188 There is no need to specify this in the command line.
15190 \labelwidthstring 00.00.0000
15202 -float-reent All floating point functions are reentrant by default.
15205 There is no need to specifiy this in the command line.
15207 \labelwidthstring 00.00.0000
15219 -callee-saves See -
15231 \labelwidthstring 00.00.0000
15243 -all-callee-saves All function arguments are passed on stack by default.
15246 There is no need to specify this in the command line.
15248 \labelwidthstring 00.00.0000
15260 -fommit-frame-pointer Frame pointer will be omitted when the function uses
15261 no local variables.
15264 Port Specific Options
15265 \begin_inset LatexCommand \index{Options PIC16}
15272 The port specific options appear after the global options in the sdcc --help
15274 \layout Subsubsection
15279 General options enable certain port features and optimizations.
15281 \labelwidthstring 00.00.0000
15293 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
15294 that use the Bank Select Register (BSR).
15296 \labelwidthstring 00.00.0000
15308 -pomit-config-words Instructs the port to omit the generation of the configurati
15311 \labelwidthstring 00.00.0000
15323 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
15325 \labelwidthstring 00.00.0000
15337 -pleave-reset-vector Used in conjuction with the previous command, instructs
15338 the port NOT to omit the reset vector.
15340 \labelwidthstring 00.00.0000
15352 -stack-model=[model] Used in conjuction with the command above.
15353 Defines the stack model to be used, valid stack models are :
15356 \labelwidthstring 00.00.0000
15362 Selects small stack model.
15363 8 bit stack and frame pointers.
15364 Supports 256 bytes stack size.
15366 \labelwidthstring 00.00.0000
15372 Selects large stack model.
15373 16 bit stack and frame pointers.
15374 Supports 65536 bytes stack size.
15377 \labelwidthstring 00.00.0000
15389 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
15390 unitialized data variables with [kword].
15391 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
15393 \labelwidthstring 00.00.0000
15405 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
15406 Useful for bootloaders.
15408 \labelwidthstring 00.00.0000
15420 -asm= sets the full path and name of an external assembler to call.
15422 \labelwidthstring 00.00.0000
15434 -link= sets the full path and name of an external linker to call.
15435 \layout Subsubsection
15440 Debugging options enable extra debugging information in the output files.
15442 \labelwidthstring 00.00.0000
15454 -debug-xtra Similar to -
15465 \begin_inset LatexCommand \index{-\/-debug}
15469 , but dumps more information.
15471 \labelwidthstring 00.00.0000
15483 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15485 <source> is the name of the file compiled.
15487 \labelwidthstring 00.00.0000
15499 -pcode-verbose Enable pcode debugging information in translation.
15502 Preprocessor Macros
15505 PIC16 port defines the following preprocessor macros while translating a
15510 \begin_inset Tabular
15511 <lyxtabular version="3" rows="2" columns="2">
15513 <column alignment="center" valignment="top" leftline="true" width="0">
15514 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15515 <row topline="true" bottomline="true">
15516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15533 <row topline="true" bottomline="true">
15534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15547 MCU Identification.
15552 is the microcontrol identification number, i.e.
15568 \begin_inset LatexCommand \index{PIC16}
15572 port uses the following directories for searching header files and libraries.
15576 \begin_inset Tabular
15577 <lyxtabular version="3" rows="3" columns="4">
15579 <column alignment="center" valignment="top" leftline="true" width="0">
15580 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15581 <column alignment="center" valignment="top" width="0">
15582 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15583 <row topline="true" bottomline="true">
15584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15617 <row topline="true">
15618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15623 PREFIX/sdcc/include/pic16
15626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15631 PIC16 specific headers
15634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15651 <row topline="true" bottomline="true">
15652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15657 PREFIX/sdcc/lib/pic16
15660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15665 PIC16 specific libraries
15668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15693 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15700 PIC16 port currently supports the following pragmas:
15702 \labelwidthstring 00.00.0000
15704 stack pragma stack forces the code generator to initialize the stack & frame
15705 pointers at a specific address.
15706 This is an adhoc solution since gplink does not support yet stack.
15707 When the gplink issue is resolved the pragma will be deprecated
15715 It is important to initialize the stack, otherwise strange things can happen.
15716 Stack is not initialized by default because there are some sources that
15718 (like library sources)
15723 The stack pragma should be used only once in a project.
15724 Multiple pragmas may result in indeterminate behaviour of the program.
15732 /* initializes stack at RAM address 0x5ff */
15735 #pragma stack 0x5ff
15737 \labelwidthstring 00.00.0000
15739 udata pragma udata instructs the compiler to emit code so that linker will
15740 place a variable at a specific memory bank
15748 /* places variable foo at bank2 */
15751 #pragma udata bank2 foo
15757 In order for this pragma to work there are some changes that must be made
15758 in the .lkr script used in link stage.
15759 In the following example a sample .lkr file is shown:
15764 // Sample linker script for the PIC18F452 processor
15770 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
15773 CODEPAGE NAME=page START=0x2A END=0x7FFF
15776 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
15779 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
15782 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
15785 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
15788 ACCESSBANK NAME=accessram START=0x0 END=0x7F
15793 DATABANK NAME=gpr0 START=0x80 END=0xFF
15796 DATABANK NAME=gpr1 START=0x100 END=0x1FF
15799 DATABANK NAME=gpr2 START=0x200 END=0x2FF
15802 DATABANK NAME=gpr3 START=0x300 END=0x3FF
15805 DATABANK NAME=gpr4 START=0x400 END=0x4FF
15808 DATABANK NAME=gpr5 START=0x500 END=0x5FF
15811 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
15816 SECTION NAME=CONFIG ROM=config
15821 SECTION NAME=bank0 RAM=gpr0
15824 SECTION NAME=bank1 RAM=gpr1
15827 SECTION NAME=bank2 RAM=gpr2
15830 SECTION NAME=bank3 RAM=gpr3
15833 SECTION NAME=bank4 RAM=gpr4
15836 SECTION NAME=bank5 RAM=gpr5
15839 The linker will recognise the section name set in the pragma statement and
15840 will position the variable at the memory bank set with the RAM field at
15841 the SECTION line in the linker script file.
15845 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
15852 There is one main header file that can be included to the source files using
15859 This header file contains the definitions for the processor special registers,
15860 so it is necessary if the source accesses them.
15861 It can be included by adding the following line in the beginning of the
15865 #include <pic18fregs.h>
15868 The specific microcontroller is selected within the pic18fregs.h automatically,
15869 so the same source can be used with a variety of devices.
15875 The libraries that PIC16
15876 \begin_inset LatexCommand \index{PIC16}
15880 port depends on are the microcontroller device libraries which contain
15881 the symbol definitions for the microcontroller special function registers.
15882 These libraries have the format pic18fxxxx.lib, where
15886 is the microcontroller identification number.
15887 The specific library is selected automatically by the compiler at link
15888 stage according to the selected device.
15891 Libraries are created with gplib which is part of the gputils package
15892 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15902 The following memory models are supported by the PIC16 port:
15911 Memory model affects the default size of pointers within the source.
15912 The sizes are shown in the next table:
15916 \begin_inset Tabular
15917 <lyxtabular version="3" rows="3" columns="3">
15919 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15920 <column alignment="center" valignment="top" leftline="true" width="0">
15921 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15922 <row topline="true" bottomline="true">
15923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15928 Pointer sizes according to memory model
15931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15948 <row topline="true" bottomline="true">
15949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15957 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15974 <row topline="true" bottomline="true">
15975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15983 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16007 It is advisable that all sources within a project are compiled with the
16009 If one wants to override the default memory model, this can be done by
16010 declaring a pointer as
16019 Far selects large memory model's pointers, while near selects small memory
16023 The standard device libraries (see
16024 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
16028 ) contain no reference to pointers, so they can be used with both memory
16035 The stack implementation for the PIC16 port uses two indirect registers,
16038 \labelwidthstring 00.00.0000
16040 FSR1 is assigned as stack pointer
16042 \labelwidthstring 00.00.0000
16044 FSR2 is assigned as frame pointer
16047 The following stack models are supported by the PIC16 port
16060 model means that only the FSRxL byte is used to access stack and frame,
16067 uses both FSRxL and FSRxH registers.
16068 The following table shows the stack/frame pointers sizes according to stack
16069 model and the maximum space they can address:
16073 \begin_inset Tabular
16074 <lyxtabular version="3" rows="3" columns="3">
16076 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16077 <column alignment="center" valignment="top" leftline="true" width="0">
16078 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16079 <row topline="true" bottomline="true">
16080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16085 Stack & Frame pointer sizes according to stack model
16088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16105 <row topline="true">
16106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16131 <row topline="true" bottomline="true">
16132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16166 Currently stack and frame pointers should be initialized explicit by the
16167 user at the desired Data RAM position (see
16168 \begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
16173 Uninitialized stack and frame pointers can result in unexpected behavior
16174 of the resulting binary.
16177 Function return values
16180 Return values from functions are placed to the appropriate registers following
16181 a modified Microchip policy optimized for SDCC.
16182 The following table shows these registers:
16186 \begin_inset Tabular
16187 <lyxtabular version="3" rows="6" columns="2">
16189 <column alignment="center" valignment="top" leftline="true" width="0">
16190 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16191 <row topline="true" bottomline="true">
16192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16205 destination register
16209 <row topline="true">
16210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16227 <row topline="true">
16228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16245 <row topline="true">
16246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16263 <row topline="true">
16264 <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">
16277 FSR0L:PRODH:PRODL:WREG
16281 <row topline="true" bottomline="true">
16282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16295 on stack, FSR0 points to the beginning
16309 When entering an interrupt, currently the PIC16
16310 \begin_inset LatexCommand \index{PIC16}
16314 port automatically saves the following registers:
16326 PROD (PRODL and PRODH)
16329 FSR0 (FSR0L and FSR0H)
16332 These registers are restored upon return from the interrupt routine.
16336 When entering a high priority interrupt WREG, STATUS and BSR are not explicit
16338 The hardware shadow registers for WREG, STATUS and BSR are used in these
16348 NOTE that when the _naked attribute is specified for an interrupt routine,
16349 then NO registers are stored or restored.
16355 Debugging with SDCDB
16356 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
16361 \begin_inset LatexCommand \index{sdcdb (debugger)}
16368 SDCC is distributed with a source level debugger
16369 \begin_inset LatexCommand \index{Debugger}
16374 The debugger uses a command line interface, the command repertoire of the
16375 debugger has been kept as close to gdb
16376 \begin_inset LatexCommand \index{gdb}
16380 (the GNU debugger) as possible.
16381 The configuration and build process is part of the standard compiler installati
16382 on, which also builds and installs the debugger in the target directory
16383 specified during configuration.
16384 The debugger allows you debug BOTH at the C source and at the ASM source
16386 Sdcdb is available on Unix platforms only.
16389 Compiling for Debugging
16403 \begin_inset LatexCommand \index{-\/-debug}
16407 option must be specified for all files for which debug information is to
16409 The complier generates a .adb file for each of these files.
16410 The linker creates the .cdb
16411 \begin_inset LatexCommand \index{<file>.cdb}
16416 \begin_inset LatexCommand \index{<file>.adb}
16420 files and the address information.
16421 This .cdb is used by the debugger.
16424 How the Debugger Works
16437 -debug option is specified the compiler generates extra symbol information
16438 some of which are put into the assembler source and some are put into the
16440 Then the linker creates the .cdb file from the individual .adb files with
16441 the address information for the symbols.
16442 The debugger reads the symbolic information generated by the compiler &
16443 the address information generated by the linker.
16444 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
16445 execution is controlled by the debugger.
16446 When a command is issued for the debugger, it translates it into appropriate
16447 commands for the simulator.
16450 Starting the Debugger
16453 The debugger can be started using the following command line.
16454 (Assume the file you are debugging has the file name foo).
16468 The debugger will look for the following files.
16471 foo.c - the source file.
16474 foo.cdb - the debugger symbol information file.
16477 foo.ihx - the Intel hex format
16478 \begin_inset LatexCommand \index{Intel hex format}
16485 Command Line Options.
16498 -directory=<source file directory> this option can used to specify the directory
16500 The debugger will look into the directory list specified for source, cdb
16502 The items in the directory list must be separated by ':', e.g.
16503 if the source files can be in the directories /home/src1 and /home/src2,
16514 -directory option should be -
16524 -directory=/home/src1:/home/src2.
16525 Note there can be no spaces in the option.
16529 -cd <directory> - change to the <directory>.
16532 -fullname - used by GUI front ends.
16535 -cpu <cpu-type> - this argument is passed to the simulator please see the
16536 simulator docs for details.
16539 -X <Clock frequency > this options is passed to the simulator please see
16540 the simulator docs for details.
16543 -s <serial port file> passed to simulator see the simulator docs for details.
16546 -S <serial in,out> passed to simulator see the simulator docs for details.
16549 -k <port number> passed to simulator see the simulator docs for details.
16555 As mentioned earlier the command interface for the debugger has been deliberatel
16556 y kept as close the GNU debugger gdb, as possible.
16557 This will help the integration with existing graphical user interfaces
16558 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
16559 If you use a graphical user interface for the debugger you can skip the
16561 \layout Subsubsection*
16563 break [line | file:line | function | file:function]
16566 Set breakpoint at specified line or function:
16575 sdcdb>break foo.c:100
16577 sdcdb>break funcfoo
16579 sdcdb>break foo.c:funcfoo
16580 \layout Subsubsection*
16582 clear [line | file:line | function | file:function ]
16585 Clear breakpoint at specified line or function:
16594 sdcdb>clear foo.c:100
16596 sdcdb>clear funcfoo
16598 sdcdb>clear foo.c:funcfoo
16599 \layout Subsubsection*
16604 Continue program being debugged, after breakpoint.
16605 \layout Subsubsection*
16610 Execute till the end of the current function.
16611 \layout Subsubsection*
16616 Delete breakpoint number 'n'.
16617 If used without any option clear ALL user defined break points.
16618 \layout Subsubsection*
16620 info [break | stack | frame | registers ]
16623 info break - list all breakpoints
16626 info stack - show the function call stack.
16629 info frame - show information about the current execution frame.
16632 info registers - show content of all registers.
16633 \layout Subsubsection*
16638 Step program until it reaches a different source line.
16639 Note: pressing <return> repeats the last command.
16640 \layout Subsubsection*
16645 Step program, proceeding through subroutine calls.
16646 \layout Subsubsection*
16651 Start debugged program.
16652 \layout Subsubsection*
16657 Print type information of the variable.
16658 \layout Subsubsection*
16663 print value of variable.
16664 \layout Subsubsection*
16669 load the given file name.
16670 Note this is an alternate method of loading file for debugging.
16671 \layout Subsubsection*
16676 print information about current frame.
16677 \layout Subsubsection*
16682 Toggle between C source & assembly source.
16683 \layout Subsubsection*
16685 ! simulator command
16688 Send the string following '!' to the simulator, the simulator response is
16690 Note the debugger does not interpret the command being sent to the simulator,
16691 so if a command like 'go' is sent the debugger can loose its execution
16692 context and may display incorrect values.
16693 \layout Subsubsection*
16700 My name is Bobby Brown"
16703 Interfacing with XEmacs
16704 \begin_inset LatexCommand \index{XEmacs}
16709 \begin_inset LatexCommand \index{Emacs}
16716 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
16717 sdcdb.el and sdcdbsrc.el.
16718 These two files can be found in the $(prefix)/bin directory after the installat
16720 These files need to be loaded into XEmacs for the interface to work.
16721 This can be done at XEmacs startup time by inserting the following into
16722 your '.xemacs' file (which can be found in your HOME directory):
16728 (load-file sdcdbsrc.el)
16734 .xemacs is a lisp file so the () around the command is REQUIRED.
16735 The files can also be loaded dynamically while XEmacs is running, set the
16736 environment variable 'EMACSLOADPATH' to the installation bin directory
16737 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
16738 To start the interface enter the following command:
16752 You will prompted to enter the file name to be debugged.
16757 The command line options that are passed to the simulator directly are bound
16758 to default values in the file sdcdbsrc.el.
16759 The variables are listed below, these values maybe changed as required.
16762 sdcdbsrc-cpu-type '51
16765 sdcdbsrc-frequency '11059200
16768 sdcdbsrc-serial nil
16771 The following is a list of key mapping for the debugger interface.
16782 ;;key\SpecialChar ~
16796 binding\SpecialChar ~
16820 ;;---\SpecialChar ~
16834 -------\SpecialChar ~
16876 sdcdb-next-from-src\SpecialChar ~
16904 sdcdb-back-from-src\SpecialChar ~
16932 sdcdb-cont-from-src\SpecialChar ~
16942 SDCDB continue command
16960 sdcdb-step-from-src\SpecialChar ~
16988 sdcdb-whatis-c-sexp\SpecialChar ~
16998 SDCDB ptypecommand for data at
17065 sdcdbsrc-delete\SpecialChar ~
17079 SDCDB Delete all breakpoints if no arg
17128 given or delete arg (C-u arg x)
17146 sdcdbsrc-frame\SpecialChar ~
17161 SDCDB Display current frame if no arg,
17210 given or display frame arg
17277 sdcdbsrc-goto-sdcdb\SpecialChar ~
17287 Goto the SDCDB output buffer
17305 sdcdb-print-c-sexp\SpecialChar ~
17316 SDCDB print command for data at
17383 sdcdbsrc-goto-sdcdb\SpecialChar ~
17393 Goto the SDCDB output buffer
17411 sdcdbsrc-mode\SpecialChar ~
17427 Toggles Sdcdbsrc mode (turns it off)
17442 sdcdb-finish-from-src\SpecialChar ~
17450 SDCDB finish command
17465 sdcdb-break\SpecialChar ~
17483 Set break for line with point
17498 sdcdbsrc-mode\SpecialChar ~
17514 Toggle Sdcdbsrc mode
17529 sdcdbsrc-srcmode\SpecialChar ~
17552 Here are a few guidelines that will help the compiler generate more efficient
17553 code, some of the tips are specific to this compiler others are generally
17554 good programming practice.
17557 Use the smallest data type to represent your data-value.
17558 If it is known in advance that the value is going to be less than 256 then
17559 use an 'unsigned char' instead of a 'short' or 'int'.
17560 Please note, that ANSI C requires both signed and unsigned chars to be
17561 promoted to 'signed int' before doing any operation.
17562 This promotion can be omitted, if the result is the same.
17563 The effect of the promotion rules together with the sign-extension is often
17570 unsigned char uc = 0xfe;
17572 if (uc * uc < 0) /* this is true! */
17591 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
17601 (unsigned char) -12 / (signed char) -3 = ...
17604 No, the result is not 4:
17609 (int) (unsigned char) -12 / (int) (signed char) -3 =
17611 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
17613 (int) 0x00f4 / (int) 0xfffd =
17615 (int) 0x00f4 / (int) 0xfffd =
17617 (int) 244 / (int) -3 =
17619 (int) -81 = (int) 0xffaf;
17622 Don't complain, that gcc gives you a different result.
17623 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
17624 Therefore the results are different.
17627 \begin_inset Quotes sld
17631 \begin_inset Quotes srd
17637 If well-defined overflow characteristics are important and negative values
17638 are not, or if you want to steer clear of sign-extension problems when
17639 manipulating bits or bytes, use one of the corresponding unsigned types.
17640 (Beware when mixing signed and unsigned values in expressions, though.)
17642 Although character types (especially unsigned char) can be used as "tiny"
17643 integers, doing so is sometimes more trouble than it's worth, due to unpredicta
17644 ble sign extension and increased code size.
17648 Use unsigned when it is known in advance that the value is not going to
17650 This helps especially if you are doing division or multiplication, bit-shifting
17651 or are using an array index.
17654 NEVER jump into a LOOP.
17657 Declare the variables to be local
17658 \begin_inset LatexCommand \index{local variables}
17662 whenever possible, especially loop control variables (induction).
17665 Since the compiler does not always do implicit integral promotion, the programme
17666 r should do an explicit cast when integral promotion is required.
17669 Reducing the size of division, multiplication & modulus operations can reduce
17670 code size substantially.
17671 Take the following code for example.
17677 foobar(unsigned int p1, unsigned char ch)
17685 unsigned char ch1 = p1 % ch ;
17696 For the modulus operation the variable ch will be promoted to unsigned int
17697 first then the modulus operation will be performed (this will lead to a
17698 call to support routine _moduint()), and the result will be casted to a
17700 If the code is changed to
17705 foobar(unsigned int p1, unsigned char ch)
17713 unsigned char ch1 = (unsigned char)p1 % ch ;
17724 It would substantially reduce the code generated (future versions of the
17725 compiler will be smart enough to detect such optimization opportunities).
17729 Have a look at the assembly listing to get a
17730 \begin_inset Quotes sld
17734 \begin_inset Quotes srd
17737 for the code generation.
17741 \begin_inset LatexCommand \index{Tools}
17745 included in the distribution
17749 \begin_inset Tabular
17750 <lyxtabular version="3" rows="12" columns="3">
17752 <column alignment="center" valignment="top" leftline="true" width="0pt">
17753 <column alignment="center" valignment="top" leftline="true" width="0pt">
17754 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17755 <row topline="true" bottomline="true">
17756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17781 <row topline="true">
17782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17795 Simulator for various architectures
17798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17807 <row topline="true">
17808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17821 header file conversion
17824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17829 sdcc/support/scripts
17833 <row topline="true">
17834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17847 header file conversion
17850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17855 sdcc/support/scripts
17859 <row topline="true">
17860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
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">
17894 <row topline="true">
17895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17929 <row topline="true">
17930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17964 <row topline="true">
17965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18034 <row topline="true">
18035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18069 <row topline="true">
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18104 <row topline="true" bottomline="true">
18105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18149 \begin_inset LatexCommand \index{Documentation}
18153 included in the distribution
18157 \begin_inset Tabular
18158 <lyxtabular version="3" rows="10" columns="2">
18160 <column alignment="left" valignment="top" leftline="true" width="0">
18161 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
18162 <row topline="true" bottomline="true">
18163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18176 Where to get / filename
18180 <row topline="true">
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18186 SDCC Compiler User Guide
18189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18194 You're reading it right now
18198 <row topline="true">
18199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18216 <row topline="true">
18217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18223 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
18228 \begin_inset LatexCommand \index{Assembler documentation}
18232 Assemblers and ASLINK
18233 \begin_inset LatexCommand \index{aslink}
18238 \begin_inset LatexCommand \index{Linker documentation}
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18250 sdcc/as/doc/asxhtm.html
18254 <row topline="true">
18255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18260 SDCC regression test
18261 \begin_inset LatexCommand \index{Regression test}
18268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18273 sdcc/doc/test_suite_spec.pdf
18277 <row topline="true">
18278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18295 <row topline="true">
18296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18301 Notes on debugging with sdcdb
18302 \begin_inset LatexCommand \index{sdcdb (debugger)}
18309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18314 sdcc/debugger/README
18318 <row topline="true">
18319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18324 Software simulator for microcontrollers
18327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18354 <row topline="true">
18355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18360 Temporary notes on the pic16
18361 \begin_inset LatexCommand \index{PIC16}
18368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18373 sdcc/src/pic16/NOTES
18377 <row topline="true" bottomline="true">
18378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18383 SDCC internal documentation (debugging file format)
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18422 Related open source tools
18423 \begin_inset LatexCommand \index{Related tools}
18431 \begin_inset Tabular
18432 <lyxtabular version="3" rows="11" columns="3">
18434 <column alignment="center" valignment="top" leftline="true" width="0pt">
18435 <column alignment="block" valignment="top" leftline="true" width="30line%">
18436 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18437 <row topline="true" bottomline="true">
18438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18463 <row topline="true">
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18470 \begin_inset LatexCommand \index{gpsim (pic simulator)}
18477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18491 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
18499 <row topline="true">
18500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18506 \begin_inset LatexCommand \index{gputils (pic tools)}
18513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18527 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
18535 <row topline="true">
18536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18558 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
18566 <row topline="true">
18567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18573 \begin_inset LatexCommand \index{indent (source formatting tool)}
18580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18585 Formats C source - Master of the white spaces
18588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18594 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
18602 <row topline="true">
18603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18609 \begin_inset LatexCommand \index{srecord (tool)}
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18621 Object file conversion, checksumming, ...
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18630 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
18638 <row topline="true">
18639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18645 \begin_inset LatexCommand \index{objdump (tool)}
18652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18657 Object file conversion, ...
18660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18665 Part of binutils (should be there anyway)
18669 <row topline="true">
18670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18676 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
18683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18688 Source code documentation system
18691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18697 \begin_inset LatexCommand \url{http://www.doxygen.org}
18705 <row topline="true">
18706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18719 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
18722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18728 \begin_inset LatexCommand \url{http://www.kdevelop.org}
18736 <row topline="true">
18737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18743 \begin_inset LatexCommand \index{splint (syntax checking tool)}
18750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18755 Statically checks c sources (has anyone adapted splint for SDCC?)
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18764 \begin_inset LatexCommand \url{http://www.splint.org}
18772 <row topline="true" bottomline="true">
18773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18779 \begin_inset LatexCommand \index{ddd (debugger)}
18786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18791 Debugger, serves nicely as GUI to sdcdb
18792 \begin_inset LatexCommand \index{sdcdb (debugger)}
18799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18805 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
18822 Related documentation / recommended reading
18826 \begin_inset Tabular
18827 <lyxtabular version="3" rows="6" columns="3">
18829 <column alignment="center" valignment="top" leftline="true" width="0pt">
18830 <column alignment="block" valignment="top" leftline="true" width="30line%">
18831 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18832 <row topline="true" bottomline="true">
18833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18858 <row topline="true">
18859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18882 \begin_inset LatexCommand \index{C Reference card}
18889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18895 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18903 <row topline="true">
18904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18926 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18934 <row topline="true">
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18947 Latest datasheet of the target CPU
18950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18959 <row topline="true">
18960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18972 Revision history of datasheet
18975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18984 <row topline="true" bottomline="true">
18985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19000 Advanced Compiler Design and Implementation
19003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19008 bookstore (very dedicated, probably read other books first)
19024 Some questions answered, some pointers given - it might be time to in turn
19032 can you solve your project with the selected microcontroller? Would you
19033 find out early or rather late that your target is too small/slow/whatever?
19034 Can you switch to a slightly better device if it doesn't fit?
19037 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
19038 and/or another programming language be more adequate? Would an operating
19039 system on the target device help?
19042 if you solved the problem, will the marketing department be happy?
19045 if the marketing department is happy, will customers be happy?
19048 if you're the project manager, marketing department and maybe even the customer
19049 in one person, have you tried to see the project from the outside?
19052 is the project done if you think it is done? Or is just that other interface/pro
19053 tocol/feature/configuration/option missing? How about website, manual(s),
19054 internationali(z|s)ation, packaging, labels, 2nd source for components,
19055 electromagnetic compatability/interference, documentation for production,
19056 production test software, update mechanism, patent issues?
19059 is your project adequately positioned in that magic triangle: fame, fortune,
19063 Maybe not all answers to these questions are known and some answers may
19068 , nevertheless knowing these questions may help you to avoid burnout
19074 burnout is bad for electronic devices, programmers and motorcycle tyres
19078 Chances are you didn't want to hear some of them...
19082 \begin_inset LatexCommand \index{Support}
19089 SDCC has grown to be a large project.
19090 The compiler alone (without the preprocessor, assembler and linker) is
19091 well over 100,000 lines of code (blank stripped).
19092 The open source nature of this project is a key to its continued growth
19094 You gain the benefit and support of many active software developers and
19096 Is SDCC perfect? No, that's why we need your help.
19097 The developers take pride in fixing reported bugs.
19098 You can help by reporting the bugs and helping other SDCC users.
19099 There are lots of ways to contribute, and we encourage you to take part
19100 in making SDCC a great software package.
19104 The SDCC project is hosted on the SDCC sourceforge site at
19105 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
19110 You'll find the complete set of mailing lists
19111 \begin_inset LatexCommand \index{Mailing list(s)}
19115 , forums, bug reporting system, patch submission
19116 \begin_inset LatexCommand \index{Patch submission}
19121 \begin_inset LatexCommand \index{download}
19125 area and cvs code repository
19126 \begin_inset LatexCommand \index{cvs code repository}
19134 \begin_inset LatexCommand \index{Bug reporting}
19139 \begin_inset LatexCommand \index{Reporting bugs}
19146 The recommended way of reporting bugs is using the infrastructure of the
19148 You can follow the status of bug reports there and have an overview about
19152 Bug reports are automatically forwarded to the developer mailing list and
19153 will be fixed ASAP.
19154 When reporting a bug, it is very useful to include a small test program
19155 (the smaller the better) which reproduces the problem.
19156 If you can isolate the problem by looking at the generated assembly code,
19157 this can be very helpful.
19158 Compiling your program with the -
19169 \begin_inset LatexCommand \index{-\/-dumpall}
19173 option can sometimes be useful in locating optimization problems.
19174 When reporting a bug please maker sure you:
19177 Attach the code you are compiling with SDCC.
19181 Specify the exact command you use to run SDCC, or attach your Makefile.
19185 Specify the SDCC version (type "
19191 "), your platform, and operating system.
19195 Provide an exact copy of any error message or incorrect output.
19199 Put something meaningful in the subject of your message.
19202 Please attempt to include these 5 important parts, as applicable, in all
19203 requests for support or when reporting any problems or bugs with SDCC.
19204 Though this will make your message lengthy, it will greatly improve your
19205 chance that SDCC users and developers will be able to help you.
19206 Some SDCC developers are frustrated by bug reports without code provided
19207 that they can use to reproduce and ultimately fix the problem, so please
19208 be sure to provide sample code if you are reporting a bug!
19211 Please have a short check that you are using a recent version of SDCC and
19212 the bug is not yet known.
19213 This is the link for reporting bugs:
19214 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
19221 Requesting Features
19222 \begin_inset LatexCommand \label{sub:Requesting-Features}
19227 \begin_inset LatexCommand \index{Feature request}
19232 \begin_inset LatexCommand \index{Requesting features}
19239 Like bug reports feature requests are forwarded to the developer mailing
19241 This is the link for requesting features:
19242 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
19252 Like bug reports contributed patches are forwarded to the developer mailing
19254 This is the link for submitting patches
19255 \begin_inset LatexCommand \index{Patch submission}
19260 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
19267 You need to specify some parameters to the
19271 command for the patches to be useful.
19272 If you modified more than one file a patch created f.e.
19277 \begin_inset Quotes sld
19280 diff -Naur unmodified_directory modified_directory >my_changes.patch
19281 \begin_inset Quotes srd
19287 will be fine, otherwise
19291 \begin_inset Quotes sld
19294 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
19295 \begin_inset Quotes srd
19308 These links should take you directly to the
19309 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
19319 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
19320 automated messages (mid 2003)
19324 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
19329 \begin_inset LatexCommand \index{Mailing list(s)}
19333 and forums are archived and searchable so if you are lucky someone already
19334 had a similar problem.
19335 While mails to the lists themselves are delivered promptly their web front
19336 end on sourceforge sometimes shows a severe time lag (up to several weeks),
19337 if you're seriously using SDCC please consider subscribing to the lists.
19343 You can follow the status of the cvs version
19344 \begin_inset LatexCommand \index{version}
19348 of SDCC by watching the Changelog
19349 \begin_inset LatexCommand \index{Changelog}
19353 in the cvs-repository
19358 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
19366 \begin_inset LatexCommand \index{Release policy}
19373 Historically there often were long delays between official releases and
19374 the sourceforge download area tends to get not updated at all.
19375 Excuses in the past might have referred to problems with live range analysis,
19376 but as this was fixed a while ago, the current problem is that another
19377 excuse has to be found.
19378 Kidding aside, we have to get better there! On the other hand there are
19379 daily snapshots available at
19380 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
19384 , and you can always build the very last version (hopefully with many bugs
19385 fixed, and features added) from the source code available at
19386 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
19394 \begin_inset LatexCommand \index{Examples}
19401 You'll find some small examples in the directory
19403 sdcc/device/examples/.
19406 More examples and libraries are available at
19408 The SDCC Open Knowledge Resource
19409 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
19416 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
19423 I did insert a reference to Paul's web site here although it seems rather
19424 dedicated to a specific 8032 board (I think it's okay because it f.e.
19425 shows LCD/Harddisc interface and has a free 8051 monitor.
19426 Independent 8032 board vendors face hard competition of heavily subsidized
19427 development boards anyway).
19430 Maybe we should include some links to real world applications.
19431 Preferably pointer to pointers (one for each architecture) so this stays
19436 \begin_inset LatexCommand \index{Quality control}
19443 The compiler is passed through nightly compile and build checks.
19449 \begin_inset LatexCommand \index{Regression test}
19453 check that SDCC itself compiles flawlessly on several platforms and checks
19454 the quality of the code generated by SDCC by running the code through simulator
19456 There is a separate document
19459 \begin_inset LatexCommand \index{Test suite}
19468 You'll find the test code in the directory
19470 sdcc/support/regression
19473 You can run these tests manually by running
19477 in this directory (or f.e.
19482 \begin_inset Quotes sld
19486 \begin_inset Quotes srd
19492 if you don't want to run the complete tests).
19493 The test code might also be interesting if you want to look for examples
19494 \begin_inset LatexCommand \index{Examples}
19498 checking corner cases of SDCC or if you plan to submit patches
19499 \begin_inset LatexCommand \index{Patch submission}
19506 The pic port uses a different set of regression tests, you'll find them
19509 sdcc/src/regression
19514 SDCC Technical Data
19518 \begin_inset LatexCommand \index{Optimizations}
19525 SDCC performs a host of standard optimizations in addition to some MCU specific
19530 Sub-expression Elimination
19531 \begin_inset LatexCommand \index{Subexpression elimination}
19538 The compiler does local and
19564 will be translated to
19576 Some subexpressions are not as obvious as the above example, e.g.:
19586 In this case the address arithmetic a->b[i] will be computed only once;
19587 the equivalent code in C would be.
19599 The compiler will try to keep these temporary variables in registers.
19602 Dead-Code Elimination
19603 \begin_inset LatexCommand \index{Dead-code elimination}
19624 i = 1; \SpecialChar ~
19633 global = 1;\SpecialChar ~
19646 global = 3;\SpecialChar ~
19671 \begin_inset LatexCommand \index{Copy propagation}
19727 Note: the dead stores created by this copy propagation will be eliminated
19728 by dead-code elimination.
19732 \begin_inset LatexCommand \index{Loop optimization}
19737 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
19744 Two types of loop optimizations are done by SDCC
19752 of loop induction variables.
19753 In addition to the strength reduction the optimizer marks the induction
19754 variables and the register allocator tries to keep the induction variables
19755 in registers for the duration of the loop.
19756 Because of this preference of the register allocator
19757 \begin_inset LatexCommand \index{Register allocation}
19761 , loop induction optimization causes an increase in register pressure, which
19762 may cause unwanted spilling of other temporary variables into the stack
19763 \begin_inset LatexCommand \index{stack}
19768 The compiler will generate a warning message when it is forced to allocate
19769 extra space either on the stack or data space.
19770 If this extra space allocation is undesirable then induction optimization
19771 can be eliminated either for the entire source file (with -
19781 -noinduction option) or for a given function only using #pragma\SpecialChar ~
19783 \begin_inset LatexCommand \index{\#pragma noinduction}
19796 for (i = 0 ; i < 100 ; i ++)
19812 for (i = 0; i < 100; i++)
19821 As mentioned previously some loop invariants are not as apparent, all static
19822 address computations are also moved out of the loop.
19827 \begin_inset LatexCommand \index{Strength reduction}
19831 , this optimization substitutes an expression by a cheaper expression:
19836 for (i=0;i < 100; i++)
19854 for (i=0;i< 100;i++) {
19860 ar[itemp1] = itemp2;
19877 The more expensive multiplication
19878 \begin_inset LatexCommand \index{Multiplication}
19882 is changed to a less expensive addition.
19886 \begin_inset LatexCommand \index{Loop reversing}
19893 This optimization is done to reduce the overhead of checking loop boundaries
19894 for every iteration.
19895 Some simple loops can be reversed and implemented using a
19896 \begin_inset Quotes eld
19899 decrement and jump if not zero
19900 \begin_inset Quotes erd
19904 SDCC checks for the following criterion to determine if a loop is reversible
19905 (note: more sophisticated compilers use data-dependency analysis to make
19906 this determination, SDCC uses a more simple minded analysis).
19909 The 'for' loop is of the form
19915 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19925 The <for body> does not contain
19926 \begin_inset Quotes eld
19930 \begin_inset Quotes erd
19934 \begin_inset Quotes erd
19940 All goto's are contained within the loop.
19943 No function calls within the loop.
19946 The loop control variable <sym> is not assigned any value within the loop
19949 The loop control variable does NOT participate in any arithmetic operation
19953 There are NO switch statements in the loop.
19956 Algebraic Simplifications
19959 SDCC does numerous algebraic simplifications, the following is a small sub-set
19960 of these optimizations.
19965 i = j + 0;\SpecialChar ~
19969 /* changed to: */\SpecialChar ~
19975 i /= 2;\SpecialChar ~
19982 /* changed to: */\SpecialChar ~
19988 i = j - j;\SpecialChar ~
19992 /* changed to: */\SpecialChar ~
19998 i = j / 1;\SpecialChar ~
20002 /* changed to: */\SpecialChar ~
20009 Note the subexpressions
20010 \begin_inset LatexCommand \index{Subexpression}
20014 given above are generally introduced by macro expansions or as a result
20015 of copy/constant propagation.
20018 'switch' Statements
20019 \begin_inset LatexCommand \label{sub:'switch'-Statements}
20024 \begin_inset LatexCommand \index{switch statement}
20031 SDCC can optimize switch statements to jump tables
20032 \begin_inset LatexCommand \index{jump tables}
20037 It makes the decision based on an estimate of the generated code size.
20038 SDCC is quite liberal in the requirements for jump table generation:
20041 The labels need not be in order, and the starting number need not be one
20042 or zero, the case labels are in numerical sequence or not too many case
20043 labels are missing.
20049 switch(i) {\SpecialChar ~
20080 case 4: ...\SpecialChar ~
20112 case 5: ...\SpecialChar ~
20144 case 3: ...\SpecialChar ~
20175 case 6: ...\SpecialChar ~
20207 case 7: ...\SpecialChar ~
20239 case 8: ...\SpecialChar ~
20271 case 9: ...\SpecialChar ~
20303 case 10: ...\SpecialChar ~
20334 case 11: ...\SpecialChar ~
20401 Both the above switch statements will be implemented using a jump-table.
20402 The example to the right side is slightly more efficient as the check for
20403 the lower boundary of the jump-table is not needed.
20407 The number of case labels is not larger than supported by the target architectur
20411 If the case labels are not in numerical sequence ('gaps' between cases)
20412 SDCC checks whether a jump table with additionally inserted dummy cases
20413 is still attractive.
20417 If the starting number is not zero and a check for the lower boundary of
20418 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
20423 Switch statements which have large gaps in the numeric sequence or those
20424 that have too many case labels can be split into more than one switch statement
20425 for efficient code generation, e.g.:
20505 If the above switch statement is broken down into two switch statements
20595 then both the switch statements will be implemented using jump-tables whereas
20596 the unmodified switch statement will not be.
20599 There might be reasons which SDCC cannot know about to either favour or
20600 not favour jump tables.
20601 If the target system has to be as quick for the last switch case as for
20602 the first (pro jump table), or if the switch argument is known to be zero
20603 in the majority of the cases (contra jump table).
20606 The pragma nojtbound
20607 \begin_inset LatexCommand \index{\#pragma nojtbound}
20611 can be used to turn off checking the
20624 It has no effect if a default label is supplied.
20625 Use of this pragma is dangerous: if the switch argument is not matched
20626 by a case statement the processor will happily jump into Nirvana.
20629 Bit-shifting Operations
20630 \begin_inset LatexCommand \index{Bit shifting}
20637 Bit shifting is one of the most frequently used operation in embedded programmin
20639 SDCC tries to implement bit-shift operations in the most efficient way
20655 generates the following code:
20672 In general SDCC will never setup a loop if the shift count is known.
20715 \begin_inset LatexCommand \index{Bit rotation}
20722 A special case of the bit-shift operation is bit rotation
20723 \begin_inset LatexCommand \index{rotating bits}
20727 , SDCC recognizes the following expression to be a left bit-rotation:
20737 char i;\SpecialChar ~
20748 /* unsigned is needed for rotation */
20753 i = ((i << 1) | (i >> 7));
20762 will generate the following code:
20781 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
20782 ns of this case will also be recognized as bit-rotation, i.e.:
20787 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
20790 Nibble and Byte Swapping
20793 Other special cases of the bit-shift operations are nibble or byte swapping
20794 \begin_inset LatexCommand \index{swapping nibbles/bytes}
20798 , SDCC recognizes the following expressions:
20821 i = ((i << 4) | (i >> 4));
20827 j = ((j << 8) | (j >> 8));
20830 and generates a swap instruction for the nibble swapping
20831 \begin_inset LatexCommand \index{Nibble swapping}
20835 or move instructions for the byte swapping
20836 \begin_inset LatexCommand \index{Byte swapping}
20842 \begin_inset Quotes sld
20846 \begin_inset Quotes srd
20849 example can be used to convert from little to big-endian or vice versa.
20850 If you want to change the endianness of a
20854 integer you have to cast to
20861 Note that SDCC stores numbers in little-endian
20867 Usually 8-bit processors don't care much about endianness.
20868 This is not the case for the standard 8051 which only has an instruction
20874 \begin_inset LatexCommand \index{DPTR}
20882 so little-endian is the more efficient byte order.
20886 \begin_inset LatexCommand \index{little-endian}
20891 \begin_inset LatexCommand \index{Endianness}
20896 lowest order first).
20900 \begin_inset LatexCommand \index{Highest Order Bit}
20907 It is frequently required to obtain the highest order bit of an integral
20908 type (long, int, short or char types).
20909 SDCC recognizes the following expression to yield the highest order bit
20910 and generates optimized code for it, e.g.:
20932 hob = (gint >> 15) & 1;
20942 will generate the following code:
20975 000A E5*01\SpecialChar ~
21002 000C 23\SpecialChar ~
21033 000D 54 01\SpecialChar ~
21060 000F F5*02\SpecialChar ~
21088 Variations of this case however will
21093 It is a standard C expression, so I heartily recommend this be the only
21094 way to get the highest order bit, (it is portable).
21095 Of course it will be recognized even if it is embedded in other expressions,
21101 xyz = gint + ((gint >> 15) & 1);
21104 will still be recognized.
21108 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
21113 \begin_inset LatexCommand \index{Peephole optimizer}
21120 The compiler uses a rule based, pattern matching and re-writing mechanism
21121 for peep-hole optimization.
21126 a peep-hole optimizer by Christopher W.
21127 Fraser (cwfraser@microsoft.com).
21128 A default set of rules are compiled into the compiler, additional rules
21129 may be added with the
21142 \begin_inset LatexCommand \index{-\/-peep-file}
21149 The rule language is best illustrated with examples.
21173 The above rule will change the following assembly
21174 \begin_inset LatexCommand \index{Assembler routines}
21196 Note: All occurrences of a
21200 (pattern variable) must denote the same string.
21201 With the above rule, the assembly sequence:
21211 will remain unmodified.
21215 Other special case optimizations may be added by the user (via
21231 some variants of the 8051 MCU
21232 \begin_inset LatexCommand \index{MCS51 variants}
21245 The following two rules will change all
21264 replace { lcall %1 } by { acall %1 }
21266 replace { ljmp %1 } by { ajmp %1 }
21271 inline-assembler code
21273 is also passed through the peep hole optimizer, thus the peephole optimizer
21274 can also be used as an assembly level macro expander.
21275 The rules themselves are MCU dependent whereas the rule language infra-structur
21276 e is MCU independent.
21277 Peephole optimization rules for other MCU can be easily programmed using
21282 The syntax for a rule is as follows:
21287 rule := replace [ restart ] '{' <assembly sequence> '
21325 <assembly sequence> '
21343 '}' [if <functionName> ] '
21348 <assembly sequence> := assembly instruction (each instruction including
21349 labels must be on a separate line).
21353 The optimizer will apply to the rules one by one from the top in the sequence
21354 of their appearance, it will terminate when all rules are exhausted.
21355 If the 'restart' option is specified, then the optimizer will start matching
21356 the rules again from the top, this option for a rule is expensive (performance)
21357 , it is intended to be used in situations where a transformation will trigger
21358 the same rule again.
21359 An example of this (not a good one, it has side effects) is the following
21382 Note that the replace pattern cannot be a blank, but can be a comment line.
21383 Without the 'restart' option only the innermost 'pop' 'push' pair would
21384 be eliminated, i.e.:
21414 the restart option the rule will be applied again to the resulting code
21415 and then all the pop-push pairs will be eliminated to yield:
21425 A conditional function can be attached to a rule.
21426 Attaching rules are somewhat more involved, let me illustrate this with
21453 The optimizer does a look-up of a function name table defined in function
21458 in the source file SDCCpeeph.c, with the name
21463 If it finds a corresponding entry the function is called.
21464 Note there can be no parameters specified for these functions, in this
21469 is crucial, since the function
21473 expects to find the label in that particular variable (the hash table containin
21474 g the variable bindings is passed as a parameter).
21475 If you want to code more such functions, take a close look at the function
21476 labelInRange and the calling mechanism in source file SDCCpeeph.c.
21477 Currently implemented are
21479 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
21480 24bitMode, portIsDS390, 24bitModeAndPortDS390
21489 I know this whole thing is a little kludgey, but maybe some day we will
21490 have some better means.
21491 If you are looking at this file, you will see the default rules that are
21492 compiled into the compiler, you can add your own rules in the default set
21493 there if you get tired of specifying the -
21507 \begin_inset LatexCommand \index{ANSI-compliance}
21512 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
21519 Deviations from the compliance:
21522 functions are not always reentrant
21523 \begin_inset LatexCommand \index{reentrant}
21530 structures cannot be assigned values directly, cannot be passed as function
21531 parameters or assigned to each other and cannot be a return value from
21558 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
21569 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
21591 return rets;/* is invalid in SDCC although allowed in ANSI */
21598 \begin_inset LatexCommand \index{long long (not supported)}
21603 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
21611 \begin_inset LatexCommand \index{double (not supported)}
21615 ' precision floating point
21616 \begin_inset LatexCommand \index{Floating point support}
21623 No support for setjmp
21624 \begin_inset LatexCommand \index{setjmp (not supported)}
21629 \begin_inset LatexCommand \index{longjmp (not supported)}
21637 \begin_inset LatexCommand \index{K\&R style}
21641 function declarations are NOT allowed.
21647 foo(i,j) /* this old style of function declarations */
21649 int i,j; /* are valid in ANSI but not valid in SDCC */
21664 Cyclomatic Complexity
21665 \begin_inset LatexCommand \index{Cyclomatic complexity}
21672 Cyclomatic complexity of a function is defined as the number of independent
21673 paths the program can take during execution of the function.
21674 This is an important number since it defines the number test cases you
21675 have to generate to validate the function.
21676 The accepted industry standard for complexity number is 10, if the cyclomatic
21677 complexity reported by SDCC exceeds 10 you should think about simplification
21678 of the function logic.
21679 Note that the complexity level is not related to the number of lines of
21680 code in a function.
21681 Large functions can have low complexity, and small functions can have large
21687 SDCC uses the following formula to compute the complexity:
21692 complexity = (number of edges in control flow graph) - (number of nodes
21693 in control flow graph) + 2;
21697 Having said that the industry standard is 10, you should be aware that in
21698 some cases it be may unavoidable to have a complexity level of less than
21700 For example if you have switch statement with more than 10 case labels,
21701 each case label adds one to the complexity level.
21702 The complexity level is by no means an absolute measure of the algorithmic
21703 complexity of the function, it does however provide a good starting point
21704 for which functions you might look at for further optimization.
21707 Retargetting for other Processors
21710 The issues for retargetting the compiler are far too numerous to be covered
21712 What follows is a brief description of each of the seven phases of the
21713 compiler and its MCU dependency.
21716 Parsing the source and building the annotated parse tree.
21717 This phase is largely MCU independent (except for the language extensions).
21718 Syntax & semantic checks are also done in this phase, along with some initial
21719 optimizations like back patching labels and the pattern matching optimizations
21720 like bit-rotation etc.
21723 The second phase involves generating an intermediate code which can be easy
21724 manipulated during the later phases.
21725 This phase is entirely MCU independent.
21726 The intermediate code generation assumes the target machine has unlimited
21727 number of registers, and designates them with the name iTemp.
21728 The compiler can be made to dump a human readable form of the code generated
21742 This phase does the bulk of the standard optimizations and is also MCU independe
21744 This phase can be broken down into several sub-phases:
21748 Break down intermediate code (iCode) into basic blocks.
21750 Do control flow & data flow analysis on the basic blocks.
21752 Do local common subexpression elimination, then global subexpression elimination
21754 Dead code elimination
21758 If loop optimizations caused any changes then do 'global subexpression eliminati
21759 on' and 'dead code elimination' again.
21762 This phase determines the live-ranges; by live range I mean those iTemp
21763 variables defined by the compiler that still survive after all the optimization
21765 Live range analysis
21766 \begin_inset LatexCommand \index{Live range analysis}
21770 is essential for register allocation, since these computation determines
21771 which of these iTemps will be assigned to registers, and for how long.
21774 Phase five is register allocation.
21775 There are two parts to this process.
21779 The first part I call 'register packing' (for lack of a better term).
21780 In this case several MCU specific expression folding is done to reduce
21785 The second part is more MCU independent and deals with allocating registers
21786 to the remaining live ranges.
21787 A lot of MCU specific code does creep into this phase because of the limited
21788 number of index registers available in the 8051.
21791 The Code generation phase is (unhappily), entirely MCU dependent and very
21792 little (if any at all) of this code can be reused for other MCU.
21793 However the scheme for allocating a homogenized assembler operand for each
21794 iCode operand may be reused.
21797 As mentioned in the optimization section the peep-hole optimizer is rule
21798 based system, which can reprogrammed for other MCUs.
21802 \begin_inset LatexCommand \index{Compiler internals}
21809 The anatomy of the compiler
21810 \begin_inset LatexCommand \label{sub:The-anatomy-of}
21819 This is an excerpt from an article published in Circuit Cellar Magazine
21821 It's a little outdated (the compiler is much more efficient now and user/develo
21822 per friendly), but pretty well exposes the guts of it all.
21828 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
21829 It is fairly easy to retarget for other 8-bit MCU.
21830 Here we take a look at some of the internals of the compiler.
21835 \begin_inset LatexCommand \index{Parsing}
21842 Parsing the input source file and creating an AST (Annotated Syntax Tree
21843 \begin_inset LatexCommand \index{Annotated syntax tree}
21848 This phase also involves propagating types (annotating each node of the
21849 parse tree with type information) and semantic analysis.
21850 There are some MCU specific parsing rules.
21851 For example the storage classes, the extended storage classes are MCU specific
21852 while there may be a xdata storage class for 8051 there is no such storage
21853 class for z80 or Atmel AVR.
21854 SDCC allows MCU specific storage class extensions, i.e.
21855 xdata will be treated as a storage class specifier when parsing 8051 C
21856 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
21861 \begin_inset LatexCommand \index{iCode}
21868 Intermediate code generation.
21869 In this phase the AST is broken down into three-operand form (iCode).
21870 These three operand forms are represented as doubly linked lists.
21871 ICode is the term given to the intermediate form generated by the compiler.
21872 ICode example section shows some examples of iCode generated for some simple
21873 C source functions.
21877 \begin_inset LatexCommand \index{Optimizations}
21884 Bulk of the target independent optimizations is performed in this phase.
21885 The optimizations include constant propagation, common sub-expression eliminati
21886 on, loop invariant code movement, strength reduction of loop induction variables
21887 and dead-code elimination.
21890 Live range analysis
21891 \begin_inset LatexCommand \index{Live range analysis}
21898 During intermediate code generation phase, the compiler assumes the target
21899 machine has infinite number of registers and generates a lot of temporary
21901 The live range computation determines the lifetime of each of these compiler-ge
21902 nerated temporaries.
21903 A picture speaks a thousand words.
21904 ICode example sections show the live range annotations for each of the
21906 It is important to note here, each iCode is assigned a number in the order
21907 of its execution in the function.
21908 The live ranges are computed in terms of these numbers.
21909 The from number is the number of the iCode which first defines the operand
21910 and the to number signifies the iCode which uses this operand last.
21913 Register Allocation
21914 \begin_inset LatexCommand \index{Register allocation}
21921 The register allocation determines the type and number of registers needed
21923 In most MCUs only a few registers can be used for indirect addressing.
21924 In case of 8051 for example the registers R0 & R1 can be used to indirectly
21925 address the internal ram and DPTR to indirectly address the external ram.
21926 The compiler will try to allocate the appropriate register to pointer variables
21928 ICode example section shows the operands annotated with the registers assigned
21930 The compiler will try to keep operands in registers as much as possible;
21931 there are several schemes the compiler uses to do achieve this.
21932 When the compiler runs out of registers the compiler will check to see
21933 if there are any live operands which is not used or defined in the current
21934 basic block being processed, if there are any found then it will push that
21935 operand and use the registers in this block, the operand will then be popped
21936 at the end of the basic block.
21940 There are other MCU specific considerations in this phase.
21941 Some MCUs have an accumulator; very short-lived operands could be assigned
21942 to the accumulator instead of a general-purpose register.
21948 Figure II gives a table of iCode operations supported by the compiler.
21949 The code generation involves translating these operations into corresponding
21950 assembly code for the processor.
21951 This sounds overly simple but that is the essence of code generation.
21952 Some of the iCode operations are generated on a MCU specific manner for
21953 example, the z80 port does not use registers to pass parameters so the
21954 SEND and RECV iCode operations will not be generated, and it also does
21955 not support JUMPTABLES.
21962 <Where is Figure II?>
21965 In the original article Figure II was announced to be downloadable on
21970 Unfortunately it never seemed to have shown up there, so: where is Figure
21975 \begin_inset LatexCommand \index{iCode}
21982 This section shows some details of iCode.
21983 The example C code does not do anything useful; it is used as an example
21984 to illustrate the intermediate code generated by the compiler.
21996 /* This function does nothing useful.
22003 for the purpose of explaining iCode */
22006 short function (data int *x)
22014 short i=10; \SpecialChar ~
22016 /* dead initialization eliminated */
22021 short sum=10; /* dead initialization eliminated */
22034 while (*x) *x++ = *p++;
22048 /* compiler detects i,j to be induction variables */
22052 for (i = 0, j = 10 ; i < 10 ; i++, j
22078 mul += i * 3; \SpecialChar ~
22080 /* this multiplication remains */
22086 gint += j * 3;\SpecialChar ~
22088 /* this multiplication changed to addition */
22102 In addition to the operands each iCode contains information about the filename
22103 and line it corresponds to in the source file.
22104 The first field in the listing should be interpreted as follows:
22109 Filename(linenumber: iCode Execution sequence number : ICode hash table
22110 key : loop depth of the iCode).
22115 Then follows the human readable form of the ICode operation.
22116 Each operand of this triplet form can be of three basic types a) compiler
22117 generated temporary b) user defined variable c) a constant value.
22118 Note that local variables and parameters are replaced by compiler generated
22121 \begin_inset LatexCommand \index{Live range analysis}
22125 are computed only for temporaries (i.e.
22126 live ranges are not computed for global variables).
22128 \begin_inset LatexCommand \index{Register allocation}
22132 are allocated for temporaries only.
22133 Operands are formatted in the following manner:
22138 Operand Name [lr live-from : live-to ] { type information } [ registers
22144 As mentioned earlier the live ranges are computed in terms of the execution
22145 sequence number of the iCodes, for example
22147 the iTemp0 is live from (i.e.
22148 first defined in iCode with execution sequence number 3, and is last used
22149 in the iCode with sequence number 5).
22150 For induction variables such as iTemp21 the live range computation extends
22151 the lifetime from the start to the end of the loop.
22153 The register allocator used the live range information to allocate registers,
22154 the same registers may be used for different temporaries if their live
22155 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
22156 iTemp17 since their live ranges do not overlap.
22157 In addition the allocator also takes into consideration the type and usage
22158 of a temporary, for example itemp6 is a pointer to near space and is used
22159 as to fetch data from (i.e.
22160 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
22161 Some short lived temporaries are allocated to special registers which have
22162 meaning to the code generator e.g.
22163 iTemp13 is allocated to a pseudo register CC which tells the back end that
22164 the temporary is used only for a conditional jump the code generation makes
22165 use of this information to optimize a compare and jump ICode.
22167 There are several loop optimizations
22168 \begin_inset LatexCommand \index{Loop optimization}
22172 performed by the compiler.
22173 It can detect induction variables iTemp21(i) and iTemp23(j).
22174 Also note the compiler does selective strength reduction
22175 \begin_inset LatexCommand \index{Strength reduction}
22180 the multiplication of an induction variable in line 18 (gint = j * 3) is
22181 changed to addition, a new temporary iTemp17 is allocated and assigned
22182 a initial value, a constant 3 is then added for each iteration of the loop.
22183 The compiler does not change the multiplication
22184 \begin_inset LatexCommand \index{Multiplication}
22188 in line 17 however since the processor does support an 8 * 8 bit multiplication.
22190 Note the dead code elimination
22191 \begin_inset LatexCommand \index{Dead-code elimination}
22195 optimization eliminated the dead assignments in line 7 & 8 to I and sum
22203 Sample.c (5:1:0:0) _entry($9) :
22208 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
22213 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
22218 Sample.c(11:4:53:0) preHeaderLbl0($11) :
22223 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
22229 Sample.c(11:6:5:1) _whilecontinue_0($1) :
22234 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
22240 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22245 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
22251 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
22257 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
22263 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
22269 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
22270 * int}[r0] + 0x2 {short}
22275 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
22280 Sample.c(11:17:21:0)_whilebreak_0($3) :
22285 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22290 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
22295 Sample.c(15:20:54:0)preHeaderLbl1($13) :
22300 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
22305 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
22310 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
22315 Sample.c(15:24:26:1)_forcond_0($4) :
22320 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
22326 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22331 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
22332 + ITemp21 [lr21:38]{short}[r4]
22337 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
22343 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
22344 + iTemp15 [lr29:30]{short}[r1]
22349 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
22355 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
22361 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
22367 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
22373 Sample.c(19:38:47:1) goto _forcond_0($4)
22378 Sample.c(19:39:48:0)_forbreak_0($7) :
22383 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
22384 + ITemp11 [lr19:40]{short}[r3]
22389 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
22394 Sample.c(20:42:51:0)_return($8) :
22399 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
22405 Finally the code generated for this function:
22446 ; ----------------------------------------------
22451 ; function function
22456 ; ----------------------------------------------
22466 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
22478 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
22490 ;_whilecontinue_0($1) :
22500 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
22505 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22564 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
22583 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
22630 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
22670 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
22696 ; iTemp6 [lr5:16]{_near * int}[r0] =
22701 ; iTemp6 [lr5:16]{_near * int}[r0] +
22718 ; goto _whilecontinue_0($1)
22730 ; _whilebreak_0($3) :
22740 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22752 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
22764 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
22776 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
22795 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
22824 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
22829 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22874 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
22879 ; iTemp21 [lr21:38]{short}[r4]
22905 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
22938 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
22943 ; iTemp15 [lr29:30]{short}[r1]
22962 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
23009 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
23056 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
23068 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
23082 cjne r5,#0xff,00104$
23094 ; goto _forcond_0($4)
23106 ; _forbreak_0($7) :
23116 ; ret iTemp24 [lr40:41]{short}
23159 A few words about basic block successors, predecessors and dominators
23162 Successors are basic blocks
23163 \begin_inset LatexCommand \index{Basic blocks}
23167 that might execute after this basic block.
23169 Predecessors are basic blocks that might execute before reaching this basic
23172 Dominators are basic blocks that WILL execute before reaching this basic
23206 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
23209 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
23212 c) domVect of [BB4] = BB1 ...
23213 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
23221 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
23231 Thanks to all the other volunteer developers who have helped with coding,
23232 testing, web-page creation, distribution sets, etc.
23233 You know who you are :-)
23240 This document was initially written by Sandeep Dutta
23243 All product names mentioned herein may be trademarks
23244 \begin_inset LatexCommand \index{Trademarks}
23248 of their respective companies.
23255 To avoid confusion, the installation and building options for SDCC itself
23256 (chapter 2) are not part of the index.
23260 \begin_inset LatexCommand \printindex{}