1 #LyX 1.5.7 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \font_typewriter courier
28 \font_default_family default
34 \paperfontsize default
36 \papersize letterpaper
42 \paperorientation portrait
49 \paragraph_separation indent
51 \quotes_language swedish
55 \tracking_changes false
63 \begin_layout Standard
64 \begin_inset Note Note
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69 --version) are written this way: -
73 \begin_layout Standard
85 \begin_layout Standard
87 three consecutive dashes would otherwise result in a long resp.
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
111 SDCC Compiler User Guide
126 \begin_layout Standard
127 \begin_inset Note Note
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
147 \begin_layout Chapter
151 \begin_layout Section
155 \begin_layout Standard
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
181 designed for 8 bit Microprocessors.
182 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190 Zilog Z80 based MCUs.
191 It can be retargeted for other microprocessors, support for Microchip PIC,
192 Atmel AVR is under development.
193 The entire source code for the compiler is distributed under GPL.
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
201 \begin_inset LatexCommand index
206 , an open source retargetable assembler & linker.
207 SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
213 In addition to the MCU specific optimizations SDCC also does a host of
214 standard optimizations like:
217 \begin_layout Itemize
218 global sub expression elimination,
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
226 \begin_layout Itemize
227 constant folding & propagation,
230 \begin_layout Itemize
234 \begin_layout Itemize
235 dead code elimination
238 \begin_layout Itemize
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248 be well suited for other 8 bit MCUs.
253 The peep hole optimizer uses a rule based substitution mechanism which
259 Supported data-types are:
262 \begin_layout Standard
264 <lyxtabular version="3" rows="8" columns="5">
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 \begin_layout Standard
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_layout Standard
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
293 \begin_layout Standard
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_layout Standard
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
311 \begin_layout Standard
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 \begin_layout Standard
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_layout Standard
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
340 \begin_layout Standard
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
349 \begin_layout Standard
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
358 \begin_layout Standard
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
369 \begin_layout Standard
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
378 \begin_layout Standard
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
387 \begin_layout Standard
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
396 \begin_layout Standard
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
405 \begin_layout Standard
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
416 \begin_layout Standard
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
425 \begin_layout Standard
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
434 \begin_layout Standard
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 \begin_layout Standard
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
452 \begin_layout Standard
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
463 \begin_layout Standard
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
472 \begin_layout Standard
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
481 \begin_layout Standard
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 \begin_layout Standard
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
499 \begin_layout Standard
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_layout Standard
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
519 \begin_layout Standard
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_layout Standard
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
546 \begin_layout Standard
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 \begin_layout Standard
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
566 \begin_layout Standard
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
575 \begin_layout Standard
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
584 \begin_layout Standard
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
593 \begin_layout Standard
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
613 \begin_layout Standard
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
622 \begin_layout Standard
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
631 \begin_layout Standard
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
640 \begin_layout Standard
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
649 \begin_layout Standard
662 The compiler also allows
664 inline assembler code
666 to be embedded anywhere in a function.
667 In addition, routines developed in assembly can also be called.
672 provides an option (-
676 \begin_layout Standard
685 -cyclomatic) to report the relative complexity of a function.
686 These functions can then be further optimized, or hand coded in assembly
692 SDCC also comes with a companion source level debugger SDCDB.
693 The debugger currently uses ucSim, a free open source simulator for 8051
694 and other micro-controllers.
698 The latest SDCC version can be downloaded from
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
708 Please note: the compiler will probably always be some steps ahead of this
713 \begin_inset LatexCommand index
714 name "Status of documentation"
722 \begin_layout Standard
723 Obviously this has pros and cons
731 \begin_layout Section
735 \begin_layout Standard
736 All packages used in this compiler system are
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745 etc.) is distributed with the package.
746 This documentation is maintained using a free open source word processor
749 This program is free software; you can redistribute it and/or modify
750 it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
756 as published by the Free Software Foundation; either version 2, or (at
757 your option) any later version.
758 This program is distributed in the hope that it will be useful, but WITHOUT
759 ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
765 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766 See the GNU General Public License for more details.
767 You should have received a copy of the GNU General Public License along
768 with this program; if not, write to the Free Software Foundation, 59 Temple
769 Place - Suite 330, Boston, MA 02111-1307, USA.
770 In other words, you are welcome to use, share and improve this program.
771 You are forbidden to forbid anyone else to use, share and improve what
773 Help stamp out software-hoarding!
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788 Commands you have to type in are printed in
796 Code samples are printed in
801 Interesting items and new terms are printed in
806 \begin_layout Section
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
813 with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
825 But we also sometimes introduce some incompatibilities with older versions.
826 Not just for the fun of it, but to make the compiler more stable, efficient
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
839 for ANSI-Compliance).
841 \begin_inset Note Note
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857 (8 bits) which is not ANSI compliant.
858 To maintain compatibility, old programs may be compiled using the -
862 \begin_layout Standard
871 -short-is-8bits commandline option (see
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882 files are stored is now in /usr/local/share.
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
892 functions are casted to int unless explicitly casted and
898 \begin_layout Standard
908 \begin_inset LatexCommand index
921 \begin_layout Standard
931 \begin_inset LatexCommand index
938 command line option are not defined
939 \begin_inset Marginal
942 \begin_layout Standard
967 will push a as an int and as a char resp if
973 \begin_layout Standard
983 \begin_inset LatexCommand index
996 \begin_layout Standard
1006 \begin_inset LatexCommand index
1013 command line options are not defined,
1015 will push a as two ints if
1021 \begin_layout Standard
1031 \begin_inset LatexCommand index
1044 \begin_layout Standard
1054 \begin_inset LatexCommand index
1061 command line option is defined.
1064 \begin_layout Itemize
1069 \begin_layout Standard
1078 -regextend has been removed.
1081 \begin_layout Itemize
1086 \begin_layout Standard
1095 -noregparms has been removed.
1098 \begin_layout Itemize
1103 \begin_layout Standard
1112 -stack-after-data has been removed.
1115 \begin_layout Itemize
1117 \begin_inset LatexCommand index
1123 \begin_inset LatexCommand index
1129 \begin_inset LatexCommand index
1134 types now consistently behave like the C99 _Bool type with respect to type
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1148 The most common incompatibility resulting from this change is related to
1150 \begin_inset LatexCommand index
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1175 \begin_layout Standard
1188 b = !b; /* toggles b */
1192 In previous versions, both forms would have toggled the bit.
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with
1202 \begin_layout Standard
1212 \begin_inset LatexCommand index
1225 \begin_layout Standard
1237 This is no longer true, and can cause compilation failures on code built
1244 \begin_layout Standard
1254 \begin_inset LatexCommand index
1261 but using c99 preprocessor features, such as one-line (//) comments
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266 functions supported undocumented and not standard compliant 'b' binary
1267 format specifier ("%b", "%hb" and "%lb").
1268 The 'b' specifier is now disabled by default.
1269 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277 (see section Section 6.7.8 Initialization, clause 9)
1281 Old behavior, before
1317 /* s.a = 1, s.b = 3 */
1358 /* s.a = 1, s.b = 2 */
1361 \begin_layout Section
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367 a desire to compute.
1368 The preferred method of installation is to compile SDCC from source using
1370 For Windows some pre-compiled binary distributions are available for your
1372 You should have some experience with command line tools and compiler use.
1375 \begin_layout Section
1379 \begin_layout Standard
1380 The SDCC home page at
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1386 is a great place to find distribution sets.
1387 You can also find links to the user mailing lists that offer help or discuss
1388 SDCC with other SDCC users.
1389 Web links to other SDCC related sites can also be found here.
1390 This document can be found in the DOC directory of the source package as
1391 a text or HTML file.
1392 A pdf version of this document is available at
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1399 Some of the other tools (simulator and assembler) included with SDCC contain
1400 their own documentation and can be found in the source distribution.
1401 If you want the latest unreleased software, the complete source package
1402 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1406 \begin_layout Section
1407 Wishes for the future
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412 Here are some I can think of:
1417 \begin_layout Standard
1420 char KernelFunction3(char p) at 0x340;
1425 \begin_layout Standard
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1440 If you can think of some more, please see the section
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1446 about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1463 \begin_layout Chapter
1465 \begin_inset LatexCommand index
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1487 More detailed instructions follow below.
1490 \begin_layout Section
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1503 The defaults can be overridden by:
1507 \labelwidthstring 00.00.0000
1512 \begin_layout Standard
1521 -prefix see table below
1525 \labelwidthstring 00.00.0000
1530 \begin_layout Standard
1539 -exec_prefix see table below
1543 \labelwidthstring 00.00.0000
1548 \begin_layout Standard
1557 -bindir see table below
1561 \labelwidthstring 00.00.0000
1566 \begin_layout Standard
1575 -datadir see table below
1579 \labelwidthstring 00.00.0000
1584 \begin_layout Standard
1593 -datarootdir see table below
1599 \labelwidthstring 00.00.0000
1602 docdir environment variable, see table below
1606 \labelwidthstring 00.00.0000
1609 include_dir_suffix environment variable, see table below
1613 \labelwidthstring 00.00.0000
1616 lib_dir_suffix environment variable, see table below
1620 \labelwidthstring 00.00.0000
1623 sdccconf_h_dir_separator environment variable, either / or
1628 This character will only be used in sdccconf.h; don't forget it's a C-header,
1629 therefore a double-backslash is needed there.
1635 \labelwidthstring 00.00.0000
1640 \begin_layout Standard
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1653 \labelwidthstring 00.00.0000
1658 \begin_layout Standard
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1671 \labelwidthstring 00.00.0000
1676 \begin_layout Standard
1685 -disable-z80-port Excludes the z80 port
1689 \labelwidthstring 00.00.0000
1694 \begin_layout Standard
1703 -disable-avr-port Excludes the AVR port
1707 \labelwidthstring 00.00.0000
1712 \begin_layout Standard
1721 -disable-ds390-port Excludes the DS390 port
1725 \labelwidthstring 00.00.0000
1730 \begin_layout Standard
1739 -disable-hc08-port Excludes the HC08 port
1743 \labelwidthstring 00.00.0000
1748 \begin_layout Standard
1757 -disable-pic-port Excludes the PIC14 port
1761 \labelwidthstring 00.00.0000
1766 \begin_layout Standard
1775 -disable-pic16-port Excludes the PIC16 port
1779 \labelwidthstring 00.00.0000
1784 \begin_layout Standard
1793 -disable-xa51-port Excludes the XA51 port
1797 \labelwidthstring 00.00.0000
1802 \begin_layout Standard
1811 -disable-ucsim Disables configuring and building of ucsim
1815 \labelwidthstring 00.00.0000
1820 \begin_layout Standard
1829 -disable-device-lib Disables automatically building device libraries
1833 \labelwidthstring 00.00.0000
1838 \begin_layout Standard
1847 -disable-packihx Disables building packihx
1853 \labelwidthstring 00.00.0000
1858 \begin_layout Standard
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1871 \labelwidthstring 00.00.0000
1876 \begin_layout Standard
1885 -enable-libgc Use the Bohem memory allocator.
1886 Lower runtime footprint.
1890 \labelwidthstring 00.00.0000
1895 \begin_layout Standard
1904 -without-ccache Do not use ccache even if available
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909 the tools and their arguments can be influenced.
1910 Please see `configure -
1914 \begin_layout Standard
1923 -help' and the man/info pages of `configure' for details.
1928 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930 SDCC_LIB_NAME are defined by `configure' too.
1931 At the moment it's not possible to change the default settings (it was
1932 simply never required).
1936 These configure options are compiled into the binaries,
1937 and can only be changed by rerunning 'configure' and recompiling SDCC.
1938 The configure options are written in
1942 to distinguish them from run time environment variables (see section search
1948 \begin_inset Quotes sld
1952 \begin_inset Quotes srd
1955 are used by the SDCC team to build the official Win32 binaries.
1956 The SDCC team uses Mingw32 to build the official Windows binaries, because
1960 \begin_layout Enumerate
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1986 \begin_layout Standard
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1998 \begin_layout Standard
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 \begin_layout Standard
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_layout Standard
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 \begin_layout Standard
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2082 \begin_layout Standard
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2095 \begin_layout Standard
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2106 \begin_layout Standard
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2119 \begin_layout Standard
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2136 \begin_layout Standard
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_layout Standard
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 \begin_layout Standard
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_layout Standard
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2208 \begin_layout Standard
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_layout Standard
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_layout Standard
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_layout Standard
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 \begin_layout Standard
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2269 \begin_layout Standard
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_layout Standard
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_layout Standard
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2300 \begin_layout Standard
2316 \begin_layout Standard
2318 'configure' also computes relative paths.
2319 This is needed for full relocatability of a binary package and to complete
2320 search paths (see section search paths below):
2325 \begin_layout Standard
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_layout Standard
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_layout Standard
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_layout Standard
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2366 \begin_layout Standard
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2377 \begin_layout Standard
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2386 \begin_layout Standard
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2397 \begin_layout Standard
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2408 \begin_layout Standard
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2417 \begin_layout Standard
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2428 \begin_layout Standard
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 \begin_layout Standard
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2448 \begin_layout Standard
2464 \begin_layout Standard
2469 \begin_layout LyX-Code
2476 \begin_layout Standard
2486 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2497 \begin_layout Standard
2507 \begin_inset Quotes srd
2511 \begin_inset Quotes srd
2520 \begin_layout Standard
2533 \begin_layout Standard
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2550 \begin_layout LyX-Code
2556 \begin_inset Quotes srd
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2564 \begin_inset Quotes srd
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2576 \begin_inset Quotes srd
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2588 \begin_inset Quotes srd
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2603 \begin_layout Standard
2613 \begin_inset Quotes srd
2617 \begin_inset Quotes srd
2628 \begin_layout Standard
2638 \begin_inset Quotes srd
2642 \begin_inset Quotes srd
2650 \begin_inset Quotes srd
2656 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2668 \begin_inset Quotes srd
2676 \begin_inset Quotes srd
2680 \begin_inset Quotes srd
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2700 \begin_inset Quotes srd
2711 \begin_layout Standard
2728 \begin_layout Standard
2737 -host=i586-mingw32msvc
2745 \begin_layout Standard
2754 -build=unknown-unknown-linux-gnu
2757 \begin_layout Standard
2759 \begin_inset Quotes sld
2763 \begin_inset Quotes srd
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2770 \begin_layout LyX-Code
2779 \begin_layout Standard
2789 \begin_inset Quotes srd
2793 \begin_inset Quotes srd
2804 \begin_layout Standard
2814 \begin_inset Quotes srd
2818 \begin_inset Quotes srd
2826 \begin_inset Quotes srd
2832 \begin_inset Quotes srd
2840 \begin_inset Quotes srd
2844 \begin_inset Quotes srd
2852 \begin_inset Quotes srd
2856 \begin_inset Quotes srd
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2876 \begin_inset Quotes srd
2884 \begin_inset Quotes srd
2888 \begin_inset Quotes srd
2896 \begin_inset Quotes srd
2900 \begin_inset Quotes srd
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2912 \begin_layout Standard
2921 -C' turns on caching, which gives a little bit extra speed.
2922 However if options are changed, it can be necessary to delete the config.cache
2926 \begin_layout Section
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2949 \begin_layout Standard
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_layout Standard
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 \begin_layout Standard
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2984 \begin_layout Standard
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2995 \begin_layout Standard
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3008 \begin_layout Standard
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_layout Standard
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3028 \begin_layout Standard
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3037 \begin_layout Standard
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_layout Standard
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_layout Standard
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_layout Standard
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 \begin_layout Standard
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3105 \begin_layout Standard
3108 $DATADIR/$LIB_DIR_SUFFIX
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3125 \begin_layout Standard
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_layout Standard
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3149 \begin_layout Standard
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_layout Standard
3190 *compiler, preprocessor, assembler, and linker
3196 is auto-appended by the compiler, e.g.
3197 small, large, z80, ds390 etc
3200 \begin_layout Standard
3202 The install paths can still be changed during `make install' with e.g.:
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3232 \begin_layout Section
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3240 \begin_inset LatexCommand index
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3254 , see section above).
3255 Further search paths are determined by environment variables during runtime.
3258 The paths searched when running the compiler are as follows (the first
3264 Binary files (preprocessor, assembler and linker)
3269 \begin_layout Standard
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_layout Standard
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3290 \begin_layout Standard
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3299 \begin_layout Standard
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3310 \begin_layout Standard
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3330 \begin_layout Standard
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3352 \begin_layout Standard
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3361 \begin_layout Standard
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3372 \begin_layout Standard
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3381 \begin_layout Standard
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3390 \begin_layout Standard
3406 \begin_layout Standard
3414 \begin_layout Standard
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3435 \begin_layout Standard
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3444 \begin_layout Standard
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3455 \begin_layout Standard
3460 \begin_layout Standard
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3477 \begin_layout Standard
3482 \begin_layout Standard
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3499 \begin_layout Standard
3504 \begin_layout Standard
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3523 \begin_layout Standard
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3532 \begin_layout Standard
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3541 \begin_layout Standard
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3552 \begin_layout Standard
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3567 \begin_layout Standard
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3580 \begin_layout Standard
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3593 \begin_layout Standard
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3612 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3678 \begin_layout Standard
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3706 \begin_layout Standard
3722 \begin_layout Standard
3728 \begin_layout Standard
3737 -nostdinc disables the last two search paths.
3747 \begin_layout Standard
3748 With the exception of
3749 \begin_inset Quotes sld
3756 \begin_layout Standard
3766 \begin_inset Quotes srd
3773 is auto-appended by the compiler (e.g.
3774 small, large, z80, ds390 etc.).
3780 \begin_layout Standard
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3801 \begin_layout Standard
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3810 \begin_layout Standard
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3821 \begin_layout Standard
3826 \begin_layout Standard
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3843 \begin_layout Standard
3848 \begin_layout Standard
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3865 \begin_layout Standard
3870 \begin_layout Standard
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3889 \begin_layout Standard
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3902 \begin_layout Standard
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3915 \begin_layout Standard
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3932 \begin_layout Standard
3939 $LIB_DIR_SUFFIX/<model>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3947 \begin_layout Standard
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3962 \begin_layout Standard
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3981 \begin_layout Standard
3992 $LIB_DIR_SUFFIX/<model>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4000 \begin_layout Standard
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4054 \begin_layout Standard
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4112 \begin_layout Standard
4117 $LIB_DIR_SUFFIX/<model>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4138 \begin_layout Standard
4154 \begin_layout Standard
4155 \begin_inset Note Note
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160 the HTML output (last line)!
4168 \begin_layout Standard
4176 \begin_layout Standard
4185 -nostdlib disables the last two search paths.
4188 \begin_layout Section
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4208 \begin_layout Enumerate
4211 Download the source package
4213 either from the SDCC Subversion repository or from snapshot builds
4215 , it will be named something like sdcc
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4234 \begin_layout Enumerate
4237 Bring up a command line terminal, such as xterm.
4240 \begin_layout Enumerate
4243 Unpack the file using a command like:
4248 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4255 , this will create a sub-directory called sdcc with all of the sources.
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type:
4267 \begin_layout Enumerate
4279 This configures the package for compilation on your system.
4282 \begin_layout Enumerate
4298 All of the source packages will compile, this can take a while.
4301 \begin_layout Enumerate
4317 This copies the binary executables, the include files, the libraries and
4318 the documentation to the install directories.
4319 Proceed with section
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4337 On Mac OS X 10.2.x it was reported, that the
4338 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339 Fortunately there's also gcc 2.9.x installed, which works fine.
4340 This compiler can be selected by running 'configure' with:
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4350 Run 'configure' with:
4353 \begin_layout LyX-Code
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383 See section 'Configure Options'.
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4397 \begin_inset Quotes sld
4401 \begin_inset Quotes srd
4404 Win32-binary can be built, which will not need the Cygwin-DLL.
4405 For the necessary 'configure' options see section 'configure options' or
4406 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4411 Cygwin on Windows download setup.exe from
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4420 \begin_inset Quotes sld
4423 default text file type
4424 \begin_inset Quotes srd
4428 \begin_inset Quotes sld
4432 \begin_inset Quotes srd
4435 and download/install at least the following packages.
4436 Some packages are selected by default, others will be automatically selected
4437 because of dependencies with the manually selected packages.
4438 Never deselect these packages!
4441 \begin_layout Itemize
4445 \begin_layout Itemize
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4457 \begin_layout Itemize
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4483 \begin_layout Itemize
4484 python ; for the regression tests
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI
4489 \begin_inset Quotes sld
4493 \begin_inset Quotes srd
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505 use autoconf-stable!
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510 Replace in your cygwin.bat the line
4513 \begin_layout LyX-Code
4518 \begin_layout Standard
4530 \begin_layout Standard
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4538 \begin_layout LyX-Code
4539 -bg black -fg white -geometry 100x65 -e bash -
4543 \begin_layout Standard
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557 works with shift-insert.
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563 Using // invokes a network lookup which is very slow.
4565 \begin_inset Quotes sld
4569 \begin_inset Quotes srd
4572 is too long, you can change it with e.g.
4575 \begin_layout LyX-Code
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581 Life is much easier, if you store the source tree on a drive which is mounted
4583 And use an editor which can handle LF-only line endings.
4584 Make sure not to commit files with windows line endings.
4585 The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4591 used in the project is 8.
4592 Although a tabulator spacing of 8 is a sensible choice for programmers
4593 (it's a power of 2 and allows to display 8/16 bit signed variables without
4594 loosing columns) the plan is to move towards using only spaces in the source.
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4601 \begin_layout Standard
4604 Download the source package
4606 either from the SDCC Subversion repository or from the
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4615 , it will be named something like sdcc
4619 -yyyymmdd-rrrr.tar.bz2.
4622 SDCC is distributed with all the projects, workspaces, and files you need
4623 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624 The workspace name is 'sdcc.dsw'.
4625 Please note that as it is now, all the executables are created in a folder
4629 Once built you need to copy the executables from sdcc
4633 bin before running SDCC.
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640 When using the Subversion repository it's easiest to configure the svn
4641 client to convert automatically for you.
4642 If however you are getting a message such as "This makefile was not generated
4643 by Developer Studio etc.
4645 \begin_inset Quotes srd
4648 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649 need to convert the Unix style line endings to DOS style line endings.
4650 To do so you can use the
4651 \begin_inset Quotes sld
4655 \begin_inset Quotes srd
4658 utility freely available on the internet.
4659 Doug Hawkins reported in the sdcc-user list that this works:
4667 SDCC> unix2dos sdcc.dsw
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4677 In order to build SDCC with MSVC
4678 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679 One good place to get them is
4680 \begin_inset LatexCommand url
4682 target "http://unxutils.sourceforge.net"
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4697 Now you have to install the utilities and setup MSVC so it can locate the
4699 Here there are two alternatives (choose one!):
4702 \begin_layout Enumerate
4707 a) Extract UnxUtils.zip to your C:
4709 hard disk PRESERVING the original paths, otherwise bison won't work.
4710 (If you are using WinZip make certain that 'Use folder names' is selected)
4715 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716 'Show directories for:' select 'Executable files', and in the directories
4717 window add a new path: 'C:
4727 (As a side effect, you get a bunch of Unix utilities that
4728 could be useful, such as diff and patch.)
4731 \begin_layout Enumerate
4736 This one avoids extracting a bunch of files you may not
4737 use, but requires some extra work:
4741 a) Create a directory were to put the
4742 tools needed, or use a directory already present.
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750 gawk.exe to such directory WITHOUT preserving the original paths.
4751 (If you are using WinZip make certain that 'Use folder names' is not selected)
4756 ) Rename bison.exe to '_bison.exe'.
4760 d) Create a batch file 'bison.bat' in 'C:
4764 ' and add these lines:
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4788 Steps 'c' and 'd' are needed
4789 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790 reside in some weird Unix directory, '/usr/local/share/' I think.
4791 So it is necessary to tell bison where those files are located if they
4792 are not in such directory.
4793 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799 in 'Show directories for:' select 'Executable files', and in the directories
4800 window add a new path: 'c:
4803 Note that you can use any other path instead of 'c:
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4809 Microsoft Visual Studio
4814 So you don't have to execute step 'e' :)
4817 \begin_layout Standard
4819 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820 the executables from sdcc
4824 bin, and you can compile using SDCC.
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833 This should regenerate all the .exe files in the bin directory except for
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840 The safest option is to delete all .obj files and run the build again.
4841 From a Cygwin BASH prompt, this can easily be done with the command (be
4842 sure you are in the sdcc directory):
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4854 ) -print -exec rm {}
4863 or on Windows NT/2000/XP from the command prompt with the command:
4870 del /s *.obj *.lib *.rul
4873 from the sdcc directory.
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4880 \begin_layout Enumerate
4881 Download the binary zip package from
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4887 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888 This should unpack to a group of sub-directories.
4889 An example directory structure after unpacking the mingw32 package is:
4894 bin for the executables, c:
4902 lib for the include and libraries.
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907 directory or start sdcc using the full path.
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4920 \begin_layout Standard
4921 Download the setup program
4923 sdcc-x.y.z-setup.exe
4925 for an official release from
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4933 or a setup program for one of the snapshots
4935 sdcc-yyyymmdd-xxxx-setup.exe
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4944 A windows typical installer will guide you through the installation process.
4947 \begin_layout Subsection
4949 \begin_inset LatexCommand index
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959 It allows to separate the source and build trees.
4963 \begin_layout Standard
4990 \begin_layout Standard
4993 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4994 # extract source to directory sdcc
4997 \begin_layout Standard
5000 mkdir sdcc.build\InsetSpace ~
5009 # put output in sdcc.build
5012 \begin_layout Standard
5018 \begin_layout Standard
5021 ../sdcc/configure\InsetSpace ~
5029 # configure is doing all the magic!
5032 \begin_layout Standard
5038 \begin_layout Standard
5044 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5045 It automagically computes the variables srcdir, top_srcdir and top_buildir
5051 the generated files will be in ~/sdcc.build, while the source files stay
5054 This is not only usefull for building different binaries, e.g.
5055 when cross compiling.
5056 It also gives you a much better overview in the source tree when all the
5057 generated files are not scattered between the source files.
5058 And the best thing is: if you want to change a file you can leave the original
5059 file untouched in the source directory.
5060 Simply copy it to the build directory, edit it, enter `make clean', `rm
5061 Makefile.dep' and `make'.
5066 will do the rest for you!
5069 \begin_layout Section
5070 Building the Documentation
5073 \begin_layout Standard
5078 \begin_layout Standard
5087 -enable-doc to the configure arguments to build the documentation together
5088 with all the other stuff.
5089 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5090 dvips and makeindex) to get the job done.
5091 Another possibility is to change to the doc directory and to type
5095 \begin_inset Quotes srd
5099 \begin_inset Quotes srd
5106 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5109 \begin_inset LatexCommand url
5110 target "http://www.lyx.org"
5114 as editor is straightforward.
5115 Prebuilt documentation in html and pdf format is available from
5116 \begin_inset LatexCommand url
5117 target "http://sdcc.sf.net/snap.php"
5124 \begin_layout Section
5125 Reading the Documentation
5126 \begin_inset LatexCommand index
5127 name "Documentation"
5134 \begin_layout Standard
5135 Currently reading the document in pdf format is recommended, as for unknown
5136 reason the hyperlinks are working there whereas in the html version they
5141 \begin_layout Standard
5142 If you should know why please drop us a note
5150 You'll find the pdf version
5151 \begin_inset LatexCommand index
5152 name "PDF version of this document"
5157 \begin_inset LatexCommand url
5158 target "http://sdcc.sf.net/doc/sdccman.pdf"
5166 \begin_inset LatexCommand index
5167 name "HTML version of this document"
5172 \begin_inset LatexCommand url
5173 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5179 This documentation is in some aspects different from a commercial documentation:
5183 \begin_layout Itemize
5184 It tries to document SDCC for several processor architectures in one document
5185 (commercially these probably would be separate documents/products).
5187 \begin_inset LatexCommand index
5188 name "Status of documentation"
5192 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5194 Z80, PIC14, PIC16 and HC08.
5197 \begin_layout Itemize
5198 There are many references pointing away from this documentation.
5199 Don't let this distract you.
5201 was a reference like
5202 \begin_inset LatexCommand url
5203 target "http://www.opencores.org"
5207 together with a statement
5208 \begin_inset Quotes sld
5211 some processors which are targetted by SDCC can be implemented in a
5228 \begin_inset LatexCommand index
5229 name "FPGA (field programmable gate array)"
5234 \begin_inset Quotes srd
5238 \begin_inset LatexCommand url
5239 target "http://sf.net/projects/fpgac"
5244 \begin_inset LatexCommand index
5245 name "FpgaC ((subset of) C to FPGA compiler)"
5250 \begin_inset Quotes sld
5253 have you ever heard of an open source compiler that compiles a subset of
5255 \begin_inset Quotes srd
5258 we expect you to have a quick look there and come back.
5259 If you read this you are on the right track.
5262 \begin_layout Itemize
5263 Some sections attribute more space to problems, restrictions and warnings
5264 than to the solution.
5267 \begin_layout Itemize
5268 The installation section and the section about the debugger is intimidating.
5271 \begin_layout Itemize
5272 There are still lots of typos and there are more different writing styles
5276 \begin_layout Section
5277 Testing the SDCC Compiler
5278 \begin_inset LatexCommand label
5279 name "sec:Testing-the-SDCC"
5286 \begin_layout Standard
5287 The first thing you should do after installing your SDCC compiler is to
5296 \begin_layout Standard
5306 \begin_inset LatexCommand index
5314 at the prompt, and the program should run and output its version like:
5319 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5323 \begin_layout Standard
5324 If it doesn't run, or gives a message about not finding sdcc program, then
5325 you need to check over your installation.
5326 Make sure that the sdcc bin directory is in your executable search path
5327 defined by the PATH environment setting (
5332 \begin_inset LatexCommand ref
5333 reference "sub:Install-Trouble-shooting"
5340 Install trouble-shooting for suggestions
5343 Make sure that the sdcc program is in the bin folder, if not perhaps something
5344 did not install correctly.
5352 is commonly installed as described in section
5353 \begin_inset Quotes sld
5356 Install and search paths
5357 \begin_inset Quotes srd
5366 Make sure the compiler works on a very simple example.
5367 Type in the following test.c program using your favorite
5392 \begin_layout Standard
5395 Compile this using the following command:
5406 If all goes well, the compiler will generate a test.asm and test.rel file.
5407 Congratulations, you've just compiled your first program with SDCC.
5408 We used the -c option to tell SDCC not to link the generated code, just
5409 to keep things simple for this step.
5417 The next step is to try it with the linker.
5429 If all goes well the compiler will link with the libraries and produce
5430 a test.ihx output file.
5435 (no test.ihx, and the linker generates warnings), then the problem is most
5444 usr/local/share/sdcc/lib directory
5451 \begin_inset LatexCommand ref
5452 reference "sub:Install-Trouble-shooting"
5459 Install trouble-shooting for suggestions).
5467 The final test is to ensure
5475 header files and libraries.
5476 Edit test.c and change it to the following:
5494 strcpy(str1, "testing");
5499 \begin_layout Standard
5502 Compile this by typing
5511 This should generate a test.ihx output file, and it should give no warnings
5512 such as not finding the string.h file.
5513 If it cannot find the string.h file, then the problem is that
5517 cannot find the /usr/local/share/sdcc/include directory
5524 \begin_inset LatexCommand ref
5525 reference "sub:Install-Trouble-shooting"
5532 Install trouble-shooting section for suggestions).
5541 \begin_layout Standard
5553 \begin_inset LatexCommand index
5554 name "-\\/-print-search-dirs"
5558 to find exactly where SDCC is looking for the include and lib files.
5561 \begin_layout Section
5562 Install Trouble-shooting
5563 \begin_inset LatexCommand label
5564 name "sub:Install-Trouble-shooting"
5569 \begin_inset LatexCommand index
5570 name "Install trouble-shooting"
5577 \begin_layout Subsection
5578 If SDCC does not build correctly
5581 \begin_layout Standard
5582 A thing to try is starting from scratch by unpacking the .tgz source package
5583 again in an empty directory.
5591 ./configure 2>&1 | tee configure.log
5605 make 2>&1 | tee make.log
5612 If anything goes wrong, you can review the log files to locate the problem.
5613 Or a relevant part of this can be attached to an email that could be helpful
5614 when requesting help from the mailing list.
5617 \begin_layout Subsection
5619 \begin_inset Quotes sld
5623 \begin_inset Quotes srd
5629 \begin_layout Standard
5631 \begin_inset Quotes sld
5635 \begin_inset Quotes srd
5638 command is a script that analyzes your system and performs some configuration
5639 to ensure the source package compiles on your system.
5640 It will take a few minutes to run, and will compile a few tests to determine
5641 what compiler features are installed.
5644 \begin_layout Subsection
5646 \begin_inset Quotes sld
5650 \begin_inset Quotes srd
5656 \begin_layout Standard
5657 This runs the GNU make tool, which automatically compiles all the source
5658 packages into the final installed binary executables.
5661 \begin_layout Subsection
5663 \begin_inset Quotes sld
5667 \begin_inset Quotes erd
5673 \begin_layout Standard
5674 This will install the compiler, other executables libraries and include
5675 files into the appropriate directories.
5677 \begin_inset LatexCommand ref
5678 reference "sub:Install-paths"
5684 \begin_inset LatexCommand ref
5685 reference "sub:Search-Paths"
5690 about install and search paths.
5692 On most systems you will need super-user privilege
5696 \begin_layout Section
5700 \begin_layout Standard
5701 SDCC is not just a compiler, but a collection of tools by various developers.
5702 These include linkers, assemblers, simulators and other components.
5703 Here is a summary of some of the components.
5704 Note that the included simulator and assembler have separate documentation
5705 which you can find in the source package in their respective directories.
5706 As SDCC grows to include support for other processors, other packages from
5707 various developers are included and may have their own sets of documentation.
5712 might want to look at the files which are installed in <installdir>.
5713 At the time of this writing, we find the following programs for gcc-builds:
5718 In <installdir>/bin:
5721 \begin_layout Itemize
5722 sdcc - The compiler.
5725 \begin_layout Itemize
5726 sdcpp - The C preprocessor.
5729 \begin_layout Itemize
5730 asx8051 - The assembler for 8051 type processors.
5733 \begin_layout Itemize
5738 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5741 \begin_layout Itemize
5742 aslink -The linker for 8051 type processors.
5745 \begin_layout Itemize
5750 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5753 \begin_layout Itemize
5754 s51 - The ucSim 8051 simulator.
5757 \begin_layout Itemize
5758 sdcdb - The source debugger.
5761 \begin_layout Itemize
5762 packihx - A tool to pack (compress) Intel hex files.
5765 \begin_layout Standard
5766 In <installdir>/share/sdcc/include
5769 \begin_layout Itemize
5773 \begin_layout Standard
5774 In <installdir>/share/sdcc/lib
5777 \begin_layout Itemize
5778 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5782 \begin_layout Standard
5783 In <installdir>/share/sdcc/doc
5786 \begin_layout Itemize
5790 \begin_layout Standard
5791 As development for other processors proceeds, this list will expand to include
5792 executables to support processors like AVR, PIC, etc.
5795 \begin_layout Subsection
5799 \begin_layout Standard
5800 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5801 the assembler and linkage editor.
5804 \begin_layout Subsection
5805 sdcpp - The C-Preprocessor
5808 \begin_layout Standard
5810 \begin_inset LatexCommand index
5811 name "sdcpp (preprocessor)"
5815 is a modified version of the GNU cpp
5816 \begin_inset LatexCommand index
5817 name "cpp|see{sdcpp}"
5822 \begin_inset LatexCommand url
5823 target "http://gcc.gnu.org/"
5828 The C preprocessor is used to pull in #include sources, process #ifdef
5829 statements, #defines and so on.
5832 \begin_layout Subsection
5841 - The Assemblers and Linkage Editors
5844 \begin_layout Standard
5845 This is retargettable assembler & linkage editor, it was developed by Alan
5847 John Hartman created the version for 8051, and I (Sandeep) have made some
5848 enhancements and bug fixes for it to work properly with SDCC.
5851 \begin_layout Subsection
5855 \begin_layout Standard
5857 \begin_inset LatexCommand index
5862 is a free open source simulator developed by Daniel Drotos.
5863 The simulator is built as part of the build process.
5864 For more information visit Daniel's web site at:
5865 \begin_inset LatexCommand url
5866 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5871 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5875 \begin_layout Subsection
5876 sdcdb - Source Level Debugger
5879 \begin_layout Standard
5881 \begin_inset LatexCommand index
5882 name "SDCDB (debugger)"
5886 is the companion source level debugger.
5887 More about SDCDB in section
5888 \begin_inset LatexCommand ref
5889 reference "cha:Debugging-with-SDCDB"
5894 The current version of the debugger uses Daniel's Simulator S51
5895 \begin_inset LatexCommand index
5900 , but can be easily changed to use other simulators.
5903 \begin_layout Chapter
5907 \begin_layout Section
5911 \begin_layout Subsection
5912 Single Source File Projects
5915 \begin_layout Standard
5916 For single source file 8051 projects the process is very simple.
5917 Compile your programs with the following command
5920 "sdcc sourcefile.c".
5924 This will compile, assemble and link your source file.
5925 Output files are as follows:
5928 \begin_layout Itemize
5930 \begin_inset LatexCommand index
5936 \begin_inset LatexCommand index
5937 name "Assembler source"
5941 file created by the compiler
5944 \begin_layout Itemize
5946 \begin_inset LatexCommand index
5952 \begin_inset LatexCommand index
5953 name "Assembler listing"
5957 file created by the Assembler
5960 \begin_layout Itemize
5962 \begin_inset LatexCommand index
5968 \begin_inset LatexCommand index
5969 name "Assembler listing"
5973 file updated with linkedit information, created by linkage editor
5976 \begin_layout Itemize
5978 \begin_inset LatexCommand index
5984 \begin_inset LatexCommand index
5985 name "Symbol listing"
5989 for the sourcefile, created by the assembler
5992 \begin_layout Itemize
5994 \begin_inset LatexCommand index
6000 \begin_inset LatexCommand index
6006 \begin_inset LatexCommand index
6011 created by the assembler, input to Linkage editor
6014 \begin_layout Itemize
6016 \begin_inset LatexCommand index
6022 \begin_inset LatexCommand index
6027 for the load module, created by the Linker
6030 \begin_layout Itemize
6032 \begin_inset LatexCommand index
6037 - A file with a summary of the memory usage
6040 \begin_layout Itemize
6042 \begin_inset LatexCommand index
6047 - The load module in Intel hex format
6048 \begin_inset LatexCommand index
6049 name "Intel hex format"
6053 (you can select the Motorola S19 format
6054 \begin_inset LatexCommand index
6055 name "Motorola S19 format"
6063 \begin_layout Standard
6073 \begin_inset LatexCommand index
6074 name "-\\/-out-fmt-s19"
6079 If you need another format you might want to use
6086 \begin_inset LatexCommand index
6087 name "objdump (tool)"
6098 \begin_inset LatexCommand index
6099 name "srecord (bin, hex, ... tool)"
6104 \begin_inset Note Note
6107 \begin_layout Standard
6114 \begin_inset LatexCommand vref
6115 reference "sub:Postprocessing-the-Intel"
6120 Both formats are documented in the documentation of srecord
6121 \begin_inset LatexCommand index
6122 name "srecord (bin, hex, ... tool)"
6129 \begin_layout Itemize
6131 \begin_inset LatexCommand index
6136 - An intermediate file containing debug information needed to create the
6141 \begin_layout Standard
6151 \begin_inset LatexCommand index
6159 \begin_layout Itemize
6161 \begin_inset LatexCommand index
6166 - An optional file (with -
6170 \begin_layout Standard
6179 -debug) containing debug information.
6180 The format is documented in cdbfileformat.pdf
6183 \begin_layout Itemize
6186 \begin_inset LatexCommand index
6187 name "<file> (no extension)"
6191 An optional AOMF or AOMF51
6192 \begin_inset LatexCommand index
6198 \begin_inset LatexCommand label
6203 file containing debug information (generated with option -
6207 \begin_layout Standard
6233 ormat is a subformat of the OMF51 format and is commonly used by third party
6235 \begin_inset LatexCommand index
6240 , simulators, emulators).
6243 \begin_layout Itemize
6245 \begin_inset LatexCommand index
6250 - Dump file to debug the compiler it self (generated with option -
6254 \begin_layout Standard
6263 -dumpall) (see section
6264 \begin_inset LatexCommand ref
6265 reference "sub:Intermediate-Dump-Options"
6271 \begin_inset LatexCommand ref
6272 reference "sub:The-anatomy-of"
6278 \begin_inset Quotes sld
6281 Anatomy of the compiler
6282 \begin_inset Quotes srd
6288 \begin_layout Subsection
6289 Postprocessing the Intel Hex
6290 \begin_inset LatexCommand index
6291 name "Intel hex format"
6296 \begin_inset LatexCommand label
6297 name "sub:Postprocessing-the-Intel"
6304 \begin_layout Standard
6305 In most cases this won't be needed but the Intel Hex file
6306 \begin_inset LatexCommand index
6311 which is generated by SDCC might include lines of varying length and the
6312 addresses within the file are not guaranteed to be strictly ascending.
6313 If your toolchain or a bootloader does not like this you can use the tool
6319 \begin_inset LatexCommand index
6320 name "packihx (tool)"
6324 which is part of the SDCC distribution:
6331 packihx sourcefile.ihx >sourcefile.hex
6338 The separately available
6343 \begin_inset LatexCommand index
6344 name "srecord (bin, hex, ... tool)"
6348 package additionally allows to set undefined locations to a predefined
6349 value, to insert checksums
6350 \begin_inset LatexCommand index
6355 of various flavours (crc, add, xor) and to perform other manipulations
6356 (convert, split, crop, offset, ...).
6364 srec_cat\InsetSpace ~
6366 sourcefile.ihx -intel\InsetSpace ~
6368 -o sourcefile.hex -intel
6375 An example for a more complex command line
6379 \begin_layout Standard
6380 the command backfills
6381 \begin_inset LatexCommand index
6382 name "backfill unused memory"
6386 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6388 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6389 will be interpreted as an
6397 (where an emergency routine could sit).
6410 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6413 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6414 -little-endian-checksum-nega
6415 tive 0xfffe 0x02 0x02\InsetSpace ~
6417 -o sourcefile.hex -intel
6426 The srecord package is available at
6427 \begin_inset LatexCommand url
6428 target "http://sf.net/projects/srecord"
6435 \begin_layout Subsection
6436 Projects with Multiple Source Files
6439 \begin_layout Standard
6440 SDCC can compile only ONE file at a time.
6441 Let us for example assume that you have a project containing the following
6446 foo1.c (contains some functions)
6448 foo2.c (contains some more functions)
6451 n.c (contains more functions and the function main)
6459 The first two files will need to be compiled separately with the commands:
6491 Then compile the source file containing the
6496 \begin_inset LatexCommand index
6501 the files together with the following command:
6509 foomain.c\InsetSpace ~
6510 foo1.rel\InsetSpace ~
6515 \begin_inset LatexCommand index
6528 can be separately compiled as well:
6539 sdcc foomain.rel foo1.rel foo2.rel
6546 The file containing the
6558 file specified in the command line, since the linkage editor processes
6559 file in the order they are presented to it.
6560 The linker is invoked from SDCC using a script file with extension .lnk
6561 \begin_inset LatexCommand index
6567 You can view this file to troubleshoot linking problems such as those arising
6568 from missing libraries.
6571 \begin_layout Subsection
6572 Projects with Additional Libraries
6573 \begin_inset LatexCommand index
6581 \begin_layout Standard
6582 Some reusable routines may be compiled into a library, see the documentation
6583 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6587 \begin_inset LatexCommand index
6595 Libraries created in this manner can be included in the command line.
6596 Make sure you include the -L <library-path> option to tell the linker where
6597 to look for these files if they are not in the current directory.
6598 Here is an example, assuming you have the source file
6610 (if that is not the same as your current project):
6617 sdcc foomain.c foolib.lib -L mylib
6628 must be an absolute path name.
6632 The most efficient way to use libraries is
6633 to keep separate modules in separate source files.
6634 The lib file now should name all the modules.rel
6635 \begin_inset LatexCommand index
6641 For an example see the standard library file
6645 in the directory <installdir>/share/lib/small.
6648 \begin_layout Subsection
6649 Using sdcclib to Create and Manage Libraries
6650 \begin_inset LatexCommand index
6658 \begin_layout Standard
6659 Alternatively, instead of having a .rel file for each entry on the library
6660 file as described in the preceding section, sdcclib can be used to embed
6661 all the modules belonging to such library in the library file itself.
6662 This results in a larger library file, but it greatly reduces the number
6663 of disk files accessed by the linker.
6664 Additionally, the packed library file contains an index of all include
6665 modules and symbols that significantly speeds up the linking process.
6666 To display a list of options supported by sdcclib type:
6671 \begin_layout Standard
6676 \begin_inset LatexCommand index
6688 To create a new library file, start by compiling all the required modules.
6694 \begin_layout Standard
6701 \begin_layout Standard
6708 \begin_layout Standard
6715 \begin_layout Standard
6722 \begin_layout Standard
6731 \begin_layout Standard
6732 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6734 The next step is to add the .rel files to the library file:
6739 \begin_layout Standard
6743 sdcclib libint.lib _divsint.rel
6746 \begin_inset LatexCommand index
6754 \begin_layout Standard
6758 sdcclib libint.lib _divuint.rel
6761 \begin_layout Standard
6765 sdcclib libint.lib _modsint.rel
6768 \begin_layout Standard
6772 sdcclib libint.lib _moduint.rel
6775 \begin_layout Standard
6779 sdcclib libint.lib _mulint.rel
6787 \begin_layout Standard
6796 \begin_layout Standard
6800 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6808 \begin_layout Standard
6809 If the file already exists in the library, it will be replaced.
6810 If a list of .rel files is available, you can tell sdcclib to add those
6812 For example, if the file 'myliblist.txt' contains
6820 \begin_layout Standard
6827 \begin_layout Standard
6834 \begin_layout Standard
6841 \begin_layout Standard
6848 \begin_layout Standard
6860 \begin_layout Standard
6869 \begin_layout Standard
6873 sdcclib -l libint.lib myliblist.txt
6881 \begin_layout Standard
6882 Additionally, you can instruct sdcclib to compiles the files before adding
6883 them to the library.
6884 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6893 \begin_layout Standard
6897 set SDCCLIB_CC=sdcc -c
6900 \begin_layout Standard
6904 sdcclib -l libint.lib myliblist.txt
6912 \begin_layout Standard
6913 To see what modules and symbols are included in the library, options -s
6914 and -m are available.
6922 sdcclib -s libint.lib
6925 \begin_inset LatexCommand index
6938 \begin_layout Standard
6944 \begin_layout Standard
6950 \begin_layout Standard
6958 \begin_layout Standard
6964 \begin_layout Standard
6970 \begin_layout Standard
6976 \begin_layout Standard
6982 \begin_layout Standard
6990 \begin_layout Standard
6996 \begin_layout Standard
7002 \begin_layout Standard
7010 \begin_layout Standard
7016 \begin_layout Standard
7022 \begin_layout Standard
7028 \begin_layout Standard
7036 \begin_layout Standard
7042 \begin_layout Standard
7053 \begin_layout Standard
7054 If the source files are compiled using -
7058 \begin_layout Standard
7068 \begin_inset LatexCommand index
7073 , the corresponding debug information file .adb will be include in the library
7075 The library files created with sdcclib are plain text files, so they can
7076 be viewed with a text editor.
7077 It is not recommended to modify a library file created with sdcclib using
7078 a text editor, as there are file indexes numbers located across the file
7079 used by the linker to quickly locate the required module to link.
7080 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7081 it can be safely deleted, since all the information required for linking
7082 is embedded in the library file itself.
7083 Library files created using sdcclib are used as described in the preceding
7087 \begin_layout Subsection
7088 Using ar to Create and Manage Libraries
7089 \begin_inset LatexCommand index
7097 \begin_layout Standard
7098 Support for ar format libraries was introduced in sdcc 2.9.0.
7099 Ar is a standard archive managing utility on unices (Linux, Mac OS X, several
7100 unix flavors) so it is not included in the sdcc package.
7108 For Windows platform you can find ar utility in GNU binutils package included
7109 in several projects: Cygwin at
7110 \begin_inset LatexCommand url
7111 target "http://www.cygwin.com/"
7116 \begin_inset LatexCommand url
7117 target "http://www.mingw.org/"
7129 Both the GNU and BSD ar format variants are suppurated by asxxxx linkers.
7130 Ar doesn't understand the asxxxx object file format, so there is a special
7131 version of ranlib distributed with sdcc, called asranlib, which produces
7132 the ar symbol lookup table.
7140 To create a library containing asxxxx object files, you should use the following
7148 \begin_layout Standard
7152 ar -Sq <library name>.lib <list of .rel files>
7155 \begin_layout Standard
7159 asranlib <library name>.lib
7162 \begin_layout Standard
7163 \begin_inset VSpace bigskip
7169 \begin_layout Section
7170 Command Line Options
7171 \begin_inset LatexCommand index
7172 name "Command Line Options"
7177 \begin_inset LatexCommand label
7178 name "sec:Command-Line-Options"
7185 \begin_layout Subsection
7186 Processor Selection Options
7187 \begin_inset LatexCommand index
7188 name "Options processor selection"
7193 \begin_inset LatexCommand index
7194 name "Processor selection options"
7202 \labelwidthstring 00.00.0000
7206 \begin_inset LatexCommand index
7213 Generate code for the Intel MCS51
7214 \begin_inset LatexCommand index
7219 family of processors.
7220 This is the default processor target.
7224 \labelwidthstring 00.00.0000
7228 \begin_inset LatexCommand index
7235 Generate code for the Dallas DS80C390
7236 \begin_inset LatexCommand index
7245 \labelwidthstring 00.00.0000
7249 \begin_inset LatexCommand index
7256 Generate code for the Dallas DS80C400
7257 \begin_inset LatexCommand index
7266 \labelwidthstring 00.00.0000
7270 \begin_inset LatexCommand index
7277 Generate code for the Freescale/Motorola HC08
7278 \begin_inset LatexCommand index
7283 family of processors.
7287 \labelwidthstring 00.00.0000
7291 \begin_inset LatexCommand index
7298 Generate code for the Zilog Z80
7299 \begin_inset LatexCommand index
7304 family of processors.
7308 \labelwidthstring 00.00.0000
7312 \begin_inset LatexCommand index
7319 Generate code for the GameBoy Z80
7320 \begin_inset LatexCommand index
7321 name "gbz80 (GameBoy Z80)"
7325 processor (Not actively maintained).
7329 \labelwidthstring 00.00.0000
7333 \begin_inset LatexCommand index
7340 Generate code for the Atmel AVR
7341 \begin_inset LatexCommand index
7346 processor (Not maintained, not complete).
7347 AVR users should probably have a look at winavr
7348 \begin_inset LatexCommand url
7349 target "http://sourceforge.net/projects/winavr"
7354 \begin_inset LatexCommand url
7355 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7359 , which is based on AVR-port of the gcc compiler.
7362 \begin_layout Standard
7363 \begin_inset Note Note
7366 \begin_layout Standard
7367 I think it is fair to direct users there for now.
7368 Open source is also about avoiding unnecessary work .
7369 But I didn't find the 'official' link.
7378 \labelwidthstring 00.00.0000
7382 \begin_inset LatexCommand index
7389 Generate code for the Microchip PIC 14
7390 \begin_inset LatexCommand index
7395 -bit processors (p16f84 and variants.
7396 In development, not complete).
7399 \begin_layout Standard
7400 \begin_inset Note Note
7403 \begin_layout Standard
7404 p16f627 p16f628 p16f84 p16f873 p16f877?
7413 \labelwidthstring 00.00.0000
7417 \begin_inset LatexCommand index
7424 Generate code for the Microchip PIC 16
7425 \begin_inset LatexCommand index
7430 -bit processors (p18f452 and variants.
7431 In development, not complete).
7435 \labelwidthstring 00.00.0000
7440 Generate code for the Toshiba TLCS-900H
7441 \begin_inset LatexCommand index
7446 processor (Not maintained, not complete).
7450 \labelwidthstring 00.00.0000
7454 \begin_inset LatexCommand index
7461 Generate code for the Phillips XA51
7462 \begin_inset LatexCommand index
7467 processor (Not maintained, not complete).
7470 \begin_layout Standard
7471 \begin_inset VSpace bigskip
7477 \begin_layout Subsection
7478 Preprocessor Options
7479 \begin_inset LatexCommand index
7480 name "Options preprocessor"
7485 \begin_inset LatexCommand index
7486 name "Preprocessor options"
7491 \begin_inset LatexCommand index
7492 name "sdcpp (preprocessor)"
7500 \labelwidthstring 00.00.0000
7504 \begin_inset LatexCommand index
7511 The additional location where the preprocessor will look for <..h> or
7512 \begin_inset Quotes eld
7516 \begin_inset Quotes erd
7523 \labelwidthstring 00.00.0000
7527 \begin_inset LatexCommand index
7528 name "-D<macro[=value]>"
7534 Command line definition of macros.
7535 Passed to the preprocessor.
7539 \labelwidthstring 00.00.0000
7543 \begin_inset LatexCommand index
7550 Tell the preprocessor to output a rule suitable for make describing the
7551 dependencies of each object file.
7552 For each source file, the preprocessor outputs one make-rule whose target
7553 is the object file name for that source file and whose dependencies are
7554 all the files `#include'd in it.
7555 This rule may be a single line or may be continued with `
7557 '-newline if it is long.
7558 The list of rules is printed on standard output instead of the preprocessed
7561 \begin_inset LatexCommand index
7570 \labelwidthstring 00.00.0000
7574 \begin_inset LatexCommand index
7581 Tell the preprocessor not to discard comments.
7582 Used with the `-E' option.
7586 \labelwidthstring 00.00.0000
7590 \begin_inset LatexCommand index
7600 Like `-M' but the output mentions only the user header files included with
7602 \begin_inset Quotes eld
7606 System header files included with `#include <file>' are omitted.
7610 \labelwidthstring 00.00.0000
7614 \begin_inset LatexCommand index
7615 name "-Aquestion(answer)"
7621 Assert the answer answer for question, in case it is tested with a preprocessor
7622 conditional such as `#if #question(answer)'.
7623 `-A-' disables the standard assertions that normally describe the target
7628 \labelwidthstring 00.00.0000
7632 \begin_inset LatexCommand index
7639 Undefine macro macro.
7640 `-U' options are evaluated after all `-D' options, but before any `-include'
7641 and `-imacros' options.
7645 \labelwidthstring 00.00.0000
7649 \begin_inset LatexCommand index
7656 Tell the preprocessor to output only a list of the macro definitions that
7657 are in effect at the end of preprocessing.
7658 Used with the `-E' option.
7662 \labelwidthstring 00.00.0000
7666 \begin_inset LatexCommand index
7673 Tell the preprocessor to pass all macro definitions into the output, in
7674 their proper sequence in the rest of the output.
7678 \labelwidthstring 00.00.0000
7682 \begin_inset LatexCommand index
7692 Like `-dD' except that the macro arguments and contents are omitted.
7693 Only `#define name' is included in the output.
7697 \labelwidthstring 00.00.0000
7700 -pedantic-parse-number
7701 \begin_inset LatexCommand index
7707 \begin_inset LatexCommand index
7708 name "-pedantic-parse-number"
7716 \begin_inset LatexCommand label
7717 name "lyx:-pedantic-parse-number"
7726 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7727 and the macro LO_B(3) gets expanded.
7728 See also #pragma pedantic_parse_number
7729 \begin_inset LatexCommand vpageref
7730 reference "ite:pedantic_parse_number"
7735 \begin_inset LatexCommand ref
7736 reference "sec:Pragmas"
7742 Note: this functionality is not in conformance with C99 standard!
7746 \labelwidthstring 00.00.0000
7750 preprocessorOption[,preprocessorOption]
7753 \begin_inset LatexCommand index
7754 name "-Wp preprocessorOption[,preprocessorOption]"
7759 Pass the preprocessorOption to the preprocessor
7764 \begin_inset LatexCommand index
7765 name "sdcpp (preprocessor)"
7770 SDCC uses an adapted version of the preprocessor
7774 of the GNU Compiler Collection
7775 \begin_inset LatexCommand index
7776 name "gcc (GNU Compiler Collection)"
7785 \begin_inset LatexCommand url
7786 target "http://gcc.gnu.org/"
7790 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7795 \begin_inset LatexCommand htmlurl
7796 target "http://www.gnu.org/software/gcc/onlinedocs/"
7803 \begin_layout Standard
7804 \begin_inset VSpace bigskip
7810 \begin_layout Subsection
7812 \begin_inset LatexCommand index
7813 name "Options linker"
7818 \begin_inset LatexCommand index
7819 name "Linker options"
7827 \labelwidthstring 00.00.0000
7837 \begin_layout Standard
7849 \begin_inset LatexCommand index
7850 name "-\\/-lib-path <path>"
7855 \begin_inset LatexCommand index
7856 name "-L -\\/-lib-path"
7863 <absolute path to additional libraries> This option is passed to the linkage
7864 editor's additional libraries
7865 \begin_inset LatexCommand index
7871 The path name must be absolute.
7872 Additional library files may be specified in the command line.
7873 See section Compiling programs for more details.
7877 \labelwidthstring 00.00.0000
7884 \begin_layout Standard
7896 \begin_inset LatexCommand index
7897 name "-\\/-xram-loc <Value>"
7902 <Value> The start location of the external ram
7903 \begin_inset LatexCommand index
7904 name "xdata (mcs51, ds390 storage class)"
7908 , default value is 0.
7909 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7913 \begin_layout Standard
7922 -xram-loc 0x8000 or -
7926 \begin_layout Standard
7939 \labelwidthstring 00.00.0000
7946 \begin_layout Standard
7958 \begin_inset LatexCommand index
7959 name "-\\/-code-loc <Value>"
7964 <Value> The start location of the code
7965 \begin_inset LatexCommand index
7970 segment, default value 0.
7971 Note when this option is used the interrupt vector table
7972 \begin_inset LatexCommand index
7973 name "interrupt vector table"
7977 is also relocated to the given address.
7978 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7982 \begin_layout Standard
7991 -code-loc 0x8000 or -
7995 \begin_layout Standard
8008 \labelwidthstring 00.00.0000
8015 \begin_layout Standard
8027 \begin_inset LatexCommand index
8028 name "-\\/-stack-loc <Value>"
8033 <Value> By default the stack
8034 \begin_inset LatexCommand index
8039 is placed after the data segment.
8040 Using this option the stack can be placed anywhere in the internal memory
8042 The value entered can be in Hexadecimal or Decimal format, e.g.
8047 \begin_layout Standard
8056 -stack-loc 0x20 or -
8060 \begin_layout Standard
8070 Since the sp register is incremented before a push or call, the initial
8071 sp will be set to one byte prior the provided value.
8072 The provided value should not overlap any other memory areas such as used
8073 register banks or the data segment and with enough space for the current
8081 \begin_layout Standard
8094 \begin_inset LatexCommand index
8095 name "-\\/-pack-iram"
8099 option (which is now a default setting) will override this setting, so
8100 you should also specify the
8106 \begin_layout Standard
8119 \begin_inset LatexCommand index
8120 name "-\\/-no-pack-iram"
8124 option if you need to manually place the stack.
8128 \labelwidthstring 00.00.0000
8135 \begin_layout Standard
8147 \begin_inset LatexCommand index
8148 name "-\\/-xstack-loc <Value>"
8153 <Value> By default the external stack
8154 \begin_inset LatexCommand index
8159 is placed after the pdata
8160 \begin_inset LatexCommand index
8161 name "pdata (mcs51, ds390 storage class)"
8166 Using this option the xstack can be placed anywhere in the external memory
8168 The value entered can be in Hexadecimal or Decimal format, e.g.
8173 \begin_layout Standard
8182 -xstack-loc 0x8000 or -
8186 \begin_layout Standard
8196 The provided value should not overlap any other memory areas such as the
8197 pdata or xdata segment and with enough space for the current application.
8201 \labelwidthstring 00.00.0000
8208 \begin_layout Standard
8220 \begin_inset LatexCommand index
8221 name "-\\/-data-loc <Value>"
8226 <Value> The start location of the internal ram data
8227 \begin_inset LatexCommand index
8228 name "data (mcs51, ds390 storage class)"
8233 The value entered can be in Hexadecimal or Decimal format, eg.
8238 \begin_layout Standard
8251 \begin_layout Standard
8261 (By default, the start location of the internal ram data segment is set
8262 as low as possible in memory, taking into account the used register banks
8263 and the bit segment at address 0x20.
8264 For example if register banks 0 and 1 are used without bit variables, the
8265 data segment will be set, if -
8269 \begin_layout Standard
8278 -data-loc is not used, to location 0x10.)
8282 \labelwidthstring 00.00.0000
8289 \begin_layout Standard
8301 \begin_inset LatexCommand index
8302 name "-\\/-idata-loc <Value>"
8307 <Value> The start location of the indirectly addressable internal ram
8308 \begin_inset LatexCommand index
8309 name "idata (mcs51, ds390 storage class)"
8313 of the 8051, default value is 0x80.
8314 The value entered can be in Hexadecimal or Decimal format, eg.
8319 \begin_layout Standard
8328 -idata-loc 0x88 or -
8332 \begin_layout Standard
8345 \labelwidthstring 00.00.0000
8352 \begin_layout Standard
8364 <Value> The start location of the bit
8365 \begin_inset LatexCommand index
8370 addressable internal ram of the 8051.
8376 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8381 \labelwidthstring 00.00.0000
8388 \begin_layout Standard
8398 \begin_inset LatexCommand index
8399 name "-\\/-out-fmt-ihx"
8405 The linker output (final object code) is in Intel Hex format.
8406 \begin_inset LatexCommand index
8407 name "Intel hex format"
8411 This is the default option.
8412 The format itself is documented in the documentation of srecord
8413 \begin_inset LatexCommand index
8414 name "srecord (bin, hex, ... tool)"
8422 \labelwidthstring 00.00.0000
8429 \begin_layout Standard
8439 \begin_inset LatexCommand index
8440 name "-\\/-out-fmt-s19"
8446 The linker output (final object code) is in Motorola S19 format
8447 \begin_inset LatexCommand index
8448 name "Motorola S19 format"
8453 The format itself is documented in the documentation of srecord.
8457 \labelwidthstring 00.00.0000
8464 \begin_layout Standard
8474 \begin_inset LatexCommand index
8475 name "-\\/-out-fmt-s19"
8480 \begin_inset LatexCommand index
8481 name "HC08!Options!-\\/-out-fmt-elf"
8487 The linker output (final object code) is in ELF format
8488 \begin_inset LatexCommand index
8494 (Currently only supported for the HC08
8495 \begin_inset LatexCommand index
8504 \labelwidthstring 00.00.0000
8508 linkOption[,linkOption]
8511 \begin_inset LatexCommand index
8512 name "-Wl linkOption[,linkOption]"
8517 \begin_inset LatexCommand label
8518 name "lyx:-Wl option"
8523 Pass the linkOption to the linker.
8524 If a bootloader is used an option like
8525 \begin_inset Quotes sld
8530 \begin_inset Quotes srd
8533 would be typical to set the start of the code segment.
8534 Either use the double quotes around this option or use no space (e.g.
8536 See also #pragma constseg and #pragma codeseg in section
8537 \begin_inset LatexCommand ref
8538 reference "sec:Pragmas"
8543 File sdcc/as/doc/asxhtm.html has more on linker options.
8546 \begin_layout Standard
8547 \begin_inset VSpace bigskip
8553 \begin_layout Subsection
8555 \begin_inset LatexCommand index
8556 name "Options MCS51"
8561 \begin_inset LatexCommand index
8562 name "MCS51 options"
8570 \labelwidthstring 00.00.0000
8577 \begin_layout Standard
8587 \begin_inset LatexCommand index
8588 name "-\\/-model-small"
8597 Generate code for Small Model programs, see section Memory Models for more
8599 This is the default model.
8603 \labelwidthstring 00.00.0000
8610 \begin_layout Standard
8620 \begin_inset LatexCommand index
8621 name "-\\/-model-medium"
8627 Generate code for Medium model programs, see section Memory Models for
8629 If this option is used all source files in the project have to be compiled
8631 It must also be used when invoking the linker.
8635 \labelwidthstring 00.00.0000
8642 \begin_layout Standard
8652 \begin_inset LatexCommand index
8653 name "-\\/-model-large"
8659 Generate code for Large model programs, see section Memory Models for more
8661 If this option is used all source files in the project have to be compiled
8663 It must also be used when invoking the linker.
8667 \labelwidthstring 00.00.0000
8674 \begin_layout Standard
8684 \begin_inset LatexCommand index
8691 Uses a pseudo stack in the pdata
8692 \begin_inset LatexCommand index
8693 name "pdata (mcs51, ds390 storage class)"
8697 area (usually the first 256 bytes in the external ram) for allocating variables
8698 and passing parameters.
8700 \begin_inset LatexCommand ref
8701 reference "sub:External-Stack"
8706 External Stack for more details.
8710 \labelwidthstring 00.00.0000
8717 \begin_layout Standard
8730 \begin_inset LatexCommand index
8731 name "-\\/-iram-size <Value>"
8735 Causes the linker to check if the internal ram usage is within limits of
8740 \labelwidthstring 00.00.0000
8747 \begin_layout Standard
8760 \begin_inset LatexCommand index
8761 name "-\\/-xram-size <Value>"
8765 Causes the linker to check if the external ram usage is within limits of
8770 \labelwidthstring 00.00.0000
8777 \begin_layout Standard
8790 \begin_inset LatexCommand index
8791 name "-\\/-code-size <Value>"
8795 Causes the linker to check if the code memory usage is within limits of
8800 \labelwidthstring 00.00.0000
8807 \begin_layout Standard
8820 \begin_inset LatexCommand index
8821 name "-\\/-stack-size <Value>"
8825 Causes the linker to check if there is at minimum <Value> bytes for stack.
8829 \labelwidthstring 00.00.0000
8836 \begin_layout Standard
8849 \begin_inset LatexCommand index
8850 name "-\\/-pack-iram"
8854 Causes the linker to use unused register banks for data variables and pack
8855 data, idata and stack together.
8856 This is the default now.
8860 \labelwidthstring 00.00.0000
8867 \begin_layout Standard
8880 \begin_inset LatexCommand index
8881 name "-\\/-no-pack-iram"
8885 Causes the linker to use old style for allocating memory areas.
8889 \labelwidthstring 00.00.0000
8896 \begin_layout Standard
8909 \begin_inset LatexCommand index
8910 name "-\\/-acall-ajmp"
8914 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8916 Only use this option if your code is in the same 2k block of memory.
8917 You may need to use this option for some 8051 derivatives which lack the
8918 lcall/ljmp instructions..
8921 \begin_layout Standard
8922 \begin_inset VSpace bigskip
8928 \begin_layout Subsection
8929 DS390 / DS400 Options
8930 \begin_inset LatexCommand index
8931 name "Options DS390"
8936 \begin_inset LatexCommand index
8945 \labelwidthstring 00.00.0000
8952 \begin_layout Standard
8964 \begin_inset LatexCommand index
8965 name "DS390!Options!-\\/-model-flat24"
8973 Generate 24-bit flat mode code.
8974 This is the one and only that the ds390 code generator supports right now
8975 and is default when using
8980 See section Memory Models for more details.
8984 \labelwidthstring 00.00.0000
8991 \begin_layout Standard
9001 \begin_inset LatexCommand index
9002 name "DS390!Options!-\\/-protect-sp-update"
9008 disable interrupts during ESP:SP updates.
9012 \labelwidthstring 00.00.0000
9019 \begin_layout Standard
9031 \begin_inset LatexCommand index
9032 name "DS390!Options!-\\/-stack-10bit"
9036 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
9037 This is the one and only that the ds390 code generator supports right now
9038 and is default when using
9043 In this mode, the stack is located in the lower 1K of the internal RAM,
9044 which is mapped to 0x400000.
9045 Note that the support is incomplete, since it still uses a single byte
9046 as the stack pointer.
9047 This means that only the lower 256 bytes of the potential 1K stack space
9048 will actually be used.
9049 However, this does allow you to reclaim the precious 256 bytes of low RAM
9050 for use for the DATA and IDATA segments.
9051 The compiler will not generate any code to put the processor into 10 bit
9053 It is important to ensure that the processor is in this mode before calling
9054 any re-entrant functions compiled with this option.
9055 In principle, this should work with the
9061 \begin_layout Standard
9071 \begin_inset LatexCommand index
9072 name "-\\/-stack-auto"
9078 option, but that has not been tested.
9079 It is incompatible with the
9085 \begin_layout Standard
9095 \begin_inset LatexCommand index
9103 It also only makes sense if the processor is in 24 bit contiguous addressing
9110 \begin_layout Standard
9119 -model-flat24 option
9124 \begin_inset Note Note
9128 \labelwidthstring 00.00.0000
9135 \begin_layout Standard
9144 -stack-8-bit - switches off the 10-bit mode
9153 \labelwidthstring 00.00.0000
9160 \begin_layout Standard
9170 \begin_inset LatexCommand index
9171 name "DS390!Options!-\\/-stack-probe"
9177 insert call to function __stack_probe at each function prologue.
9181 \labelwidthstring 00.00.0000
9188 \begin_layout Standard
9198 \begin_inset LatexCommand index
9199 name "DS390!Options!-\\/-tini-libid"
9205 <nnnn> LibraryID used in -mTININative.
9210 \labelwidthstring 00.00.0000
9217 \begin_layout Standard
9227 \begin_inset LatexCommand index
9228 name "DS390!Options!-\\/-use-accelerator"
9234 generate code for DS390 Arithmetic Accelerator.
9238 \begin_layout Standard
9239 \begin_inset VSpace bigskip
9245 \begin_layout Subsection
9247 \begin_inset LatexCommand index
9253 \begin_inset LatexCommand index
9262 \labelwidthstring 00.00.0000
9269 \begin_layout Standard
9281 \begin_inset LatexCommand index
9282 name "Z80!Options!-\\/-callee-saves-bc"
9290 Force a called function to always save BC.
9294 \labelwidthstring 00.00.0000
9301 \begin_layout Standard
9313 \begin_inset LatexCommand index
9314 name "Z80!Options!-\\/-no-std-crt0"
9318 When linking, skip the standard crt0.o object file.
9319 You must provide your own crt0.o for your system when linking.
9323 \labelwidthstring 00.00.0000
9330 \begin_layout Standard
9342 \begin_inset LatexCommand index
9343 name "Z80!Options!-\\/-portmode=<Value>"
9347 Determinate PORT I/O mode (<Value> is z80 or z180).
9351 \labelwidthstring 00.00.0000
9358 \begin_layout Standard
9370 \begin_inset LatexCommand index
9371 name "Z80!Options!-\\/-asm=<Value>"
9375 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9379 \labelwidthstring 00.00.0000
9386 \begin_layout Standard
9399 \begin_inset LatexCommand index
9400 name "Z80!Options!-\\/-codeseg <Value>"
9404 Use <Value> for the code segment name.
9408 \labelwidthstring 00.00.0000
9415 \begin_layout Standard
9428 \begin_inset LatexCommand index
9429 name "Z80!Options!-\\/-constseg <Value>"
9433 Use <Value> for the const segment name.
9437 \labelwidthstring 00.00.0000
9438 \begin_inset VSpace bigskip
9444 \begin_layout Subsection
9446 \begin_inset LatexCommand index
9447 name "Options GBZ80"
9452 \begin_inset LatexCommand index
9461 \labelwidthstring 00.00.0000
9468 \begin_layout Standard
9480 \begin_inset LatexCommand index
9481 name "GBZ80!Options!-\\/-callee-saves-bc"
9489 Force a called function to always save BC.
9493 \labelwidthstring 00.00.0000
9500 \begin_layout Standard
9512 \begin_inset LatexCommand index
9513 name "Z80!Options!-\\/-no-std-crt0"
9517 When linking, skip the standard crt0.o object file.
9518 You must provide your own crt0.o for your system when linking.
9522 \labelwidthstring 00.00.0000
9529 \begin_inset LatexCommand index
9530 name "GBZ80!Options!-bo <Num>"
9534 Use code bank <Num>.
9538 \labelwidthstring 00.00.0000
9545 \begin_inset LatexCommand index
9546 name "GBZ80!Options!-ba <Num>"
9550 Use data bank <Num>.
9554 \labelwidthstring 00.00.0000
9561 \begin_layout Standard
9574 \begin_inset LatexCommand index
9575 name "GBZ80!Options!-\\/-codeseg <Value>"
9579 Use <Value> for the code segment name.
9583 \labelwidthstring 00.00.0000
9590 \begin_layout Standard
9603 \begin_inset LatexCommand index
9604 name "GBZ80!Options!-\\/-constseg <Value>"
9608 Use <Value> for the const segment name.
9611 \begin_layout Standard
9612 \begin_inset VSpace bigskip
9618 \begin_layout Subsection
9619 Optimization Options
9620 \begin_inset LatexCommand index
9621 name "Options optimization"
9626 \begin_inset LatexCommand index
9627 name "Optimization options"
9635 \labelwidthstring 00.00.0000
9642 \begin_layout Standard
9652 \begin_inset LatexCommand index
9659 Will not do global subexpression elimination, this option may be used when
9660 the compiler creates undesirably large stack/data spaces to store compiler
9670 \begin_inset LatexCommand index
9671 name "sloc (spill location)"
9676 A warning message will be generated when this happens and the compiler
9677 will indicate the number of extra bytes it allocated.
9678 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9680 \begin_inset LatexCommand index
9681 name "\\#pragma nogcse"
9685 can be used to turn off global subexpression elimination
9686 \begin_inset LatexCommand index
9687 name "Subexpression elimination"
9691 for a given function only.
9695 \labelwidthstring 00.00.0000
9702 \begin_layout Standard
9712 \begin_inset LatexCommand index
9713 name "-\\/-noinvariant"
9719 Will not do loop invariant optimizations, this may be turned off for reasons
9720 explained for the previous option.
9721 For more details of loop optimizations performed see Loop Invariants in
9723 \begin_inset LatexCommand ref
9724 reference "sub:Loop-Optimizations"
9729 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9731 \begin_inset LatexCommand index
9732 name "\\#pragma noinvariant"
9736 can be used to turn off invariant optimizations for a given function only.
9740 \labelwidthstring 00.00.0000
9747 \begin_layout Standard
9757 \begin_inset LatexCommand index
9758 name "-\\/-noinduction"
9764 Will not do loop induction optimizations, see section strength reduction
9766 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9768 \begin_inset LatexCommand index
9769 name "\\#pragma noinduction"
9773 can be used to turn off induction optimizations for a given function only.
9777 \labelwidthstring 00.00.0000
9784 \begin_layout Standard
9794 \begin_inset LatexCommand index
9795 name "-\\/-nojtbound"
9804 Will not generate boundary condition check when switch statements
9805 \begin_inset LatexCommand index
9806 name "switch statement"
9810 are implemented using jump-tables.
9812 \begin_inset LatexCommand ref
9813 reference "sub:'switch'-Statements"
9818 Switch Statements for more details.
9819 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9821 \begin_inset LatexCommand index
9822 name "\\#pragma nojtbound"
9826 can be used to turn off boundary checking for jump tables for a given function
9831 \labelwidthstring 00.00.0000
9838 \begin_layout Standard
9848 \begin_inset LatexCommand index
9849 name "-\\/-noloopreverse"
9858 Will not do loop reversal
9859 \begin_inset LatexCommand index
9860 name "Loop reversing"
9868 \labelwidthstring 00.00.0000
9873 \begin_layout Standard
9887 \begin_inset LatexCommand index
9888 name "-\\/-nolabelopt "
9892 Will not optimize labels (makes the dumpfiles more readable).
9896 \labelwidthstring 00.00.0000
9903 \begin_layout Standard
9913 \begin_inset LatexCommand index
9914 name "-\\/-no-xinit-opt"
9920 Will not memcpy initialized data from code space into xdata space.
9921 This saves a few bytes in code space if you don't have initialized data
9922 \begin_inset LatexCommand index
9923 name "Variable initialization"
9931 \labelwidthstring 00.00.0000
9938 \begin_layout Standard
9948 \begin_inset LatexCommand index
9949 name "-\\/-nooverlay"
9955 The compiler will not overlay parameters and local variables of any function,
9956 see section Parameters and local variables for more details.
9960 \labelwidthstring 00.00.0000
9967 \begin_layout Standard
9977 \begin_inset LatexCommand index
9984 Disable peep-hole optimization with built-in rules.
9988 \labelwidthstring 00.00.0000
9995 \begin_layout Standard
10007 \begin_inset LatexCommand index
10008 name "-\\/-peep-file"
10013 <filename> This option can be used to use additional rules to be used by
10014 the peep hole optimizer.
10016 \begin_inset LatexCommand ref
10017 reference "sub:Peephole-Optimizer"
10022 Peep Hole optimizations for details on how to write these rules.
10026 \labelwidthstring 00.00.0000
10033 \begin_layout Standard
10043 \begin_inset LatexCommand index
10044 name "-\\/-peep-asm"
10050 Pass the inline assembler code through the peep hole optimizer.
10051 This can cause unexpected changes to inline assembler code, please go through
10052 the peephole optimizer
10053 \begin_inset LatexCommand index
10054 name "Peephole optimizer"
10058 rules defined in the source file tree '<target>/peeph.def' before using
10063 \labelwidthstring 00.00.0000
10070 \begin_layout Standard
10080 \begin_inset LatexCommand index
10081 name "-\\/-opt-code-speed"
10087 The compiler will optimize code generation towards fast code, possibly
10088 at the expense of code size.
10092 \labelwidthstring 00.00.0000
10099 \begin_layout Standard
10109 \begin_inset LatexCommand index
10110 name "-\\/-opt-code-size"
10116 The compiler will optimize code generation towards compact code, possibly
10117 at the expense of code speed.
10120 \begin_layout Standard
10121 \begin_inset VSpace bigskip
10127 \begin_layout Subsection
10129 \begin_inset LatexCommand index
10130 name "Options other"
10138 \labelwidthstring 00.00.0000
10146 \begin_layout Standard
10156 \begin_inset LatexCommand index
10157 name "-\\/-compile-only"
10162 \begin_inset LatexCommand index
10163 name "-c -\\/-compile-only"
10169 will compile and assemble the source, but will not call the linkage editor.
10173 \labelwidthstring 00.00.0000
10182 \begin_layout Standard
10194 \begin_inset LatexCommand index
10201 reads the preprocessed source from standard input and compiles it.
10202 The file name for the assembler output must be specified using the -o option.
10206 \labelwidthstring 00.00.0000
10210 \begin_inset LatexCommand index
10217 Run only the C preprocessor.
10218 Preprocess all the C source files specified and output the results to standard
10223 \labelwidthstring 00.00.0000
10228 \begin_inset LatexCommand index
10229 name "-o <path/file>"
10235 The output path where everything will be placed or the file name used for
10236 all generated output files.
10237 If the parameter is a path, it must have a trailing slash (or backslash
10238 for the Windows binaries) to be recognized as a path.
10239 Note for Windows users: if the path contains spaces, it should be surrounded
10241 The trailing backslash should be doubled in order to prevent escaping the
10242 final quote, for example:
10245 \begin_inset Quotes sld
10259 \begin_inset Quotes srd
10264 or put after the final quote, for example:
10267 \begin_inset Quotes sld
10277 \begin_inset Quotes srd
10285 The path using slashes for directory delimiters can be used too, for example:
10289 \begin_inset Quotes sld
10292 F:/Projects/test3/output 1/
10293 \begin_inset Quotes srd
10302 \labelwidthstring 00.00.0000
10309 \begin_layout Standard
10319 \begin_inset LatexCommand index
10320 name "-\\/-stack-auto"
10329 All functions in the source file will be compiled as
10334 \begin_inset LatexCommand index
10340 the parameters and local variables will be allocated on the stack
10341 \begin_inset LatexCommand index
10348 \begin_inset LatexCommand ref
10349 reference "sec:Parameters-and-Local-Variables"
10353 Parameters and Local Variables for more details.
10354 If this option is used all source files in the project should be compiled
10356 It automatically implies -
10362 \begin_layout Standard
10373 -int-long-reent and -
10379 \begin_layout Standard
10395 \labelwidthstring 00.00.0000
10402 \begin_layout Standard
10412 \begin_inset LatexCommand index
10413 name "-\\/-callee-saves"
10418 \begin_inset LatexCommand label
10419 name "lyx:--callee-saves-function1[,function2][,function3]..."
10423 function1[,function2][,function3]....
10426 The compiler by default uses a caller saves convention for register saving
10427 across function calls, however this can cause unnecessary register pushing
10428 and popping when calling small functions from larger functions.
10429 This option can be used to switch the register saving convention for the
10430 function names specified.
10431 The compiler will not save registers when calling these functions, no extra
10432 code will be generated at the entry and exit (function prologue
10435 \begin_inset LatexCommand index
10436 name "function prologue"
10445 \begin_inset LatexCommand index
10446 name "function epilogue"
10452 ) for these functions to save and restore the registers used by these functions,
10453 this can SUBSTANTIALLY reduce code and improve run time performance of
10454 the generated code.
10455 In the future the compiler (with inter procedural analysis) will be able
10456 to determine the appropriate scheme to use for each function call.
10457 DO NOT use this option for built-in functions such as _mulint..., if this
10458 option is used for a library function the appropriate library function
10459 needs to be recompiled with the same option.
10460 If the project consists of multiple source files then all the source file
10461 should be compiled with the same -
10465 \begin_layout Standard
10474 -callee-saves option string.
10475 Also see #pragma\InsetSpace ~
10477 \begin_inset LatexCommand index
10478 name "\\#pragma callee\\_saves"
10483 \begin_inset LatexCommand vpageref
10484 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10492 \labelwidthstring 00.00.0000
10499 \begin_layout Standard
10509 \begin_inset LatexCommand index
10510 name "-\\/-all-callee-saves"
10520 \begin_layout Standard
10529 -callee-saves will be applied to all functions by default.
10533 \labelwidthstring 00.00.0000
10540 \begin_layout Standard
10550 \begin_inset LatexCommand index
10557 When this option is used the compiler will generate debug information.
10558 The debug information collected in a file with .cdb extension can be used
10560 For more information see documentation for SDCDB.
10561 Another file with no extension contains debug information in AOMF or AOMF51
10562 \begin_inset LatexCommand index
10563 name "AOMF, AOMF51"
10567 format which is commonly used by third party tools.
10571 \labelwidthstring 00.00.0000
10575 \begin_inset LatexCommand index
10585 Stop after the stage of compilation proper; do not assemble.
10586 The output is an assembler code file for the input file specified.
10590 \labelwidthstring 00.00.0000
10597 \begin_layout Standard
10607 \begin_inset LatexCommand index
10608 name "-\\/-int-long-reent"
10614 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10615 Note by default these libraries are compiled as non-reentrant.
10616 See section Installation for more details.
10620 \labelwidthstring 00.00.0000
10627 \begin_layout Standard
10637 \begin_inset LatexCommand index
10638 name "-\\/-cyclomatic"
10644 This option will cause the compiler to generate an information message for
10645 each function in the source file.
10646 The message contains some
10650 information about the function.
10651 The number of edges and nodes the compiler detected in the control flow
10652 graph of the function, and most importantly the
10654 cyclomatic complexity
10655 \begin_inset LatexCommand index
10656 name "Cyclomatic complexity"
10662 see section on Cyclomatic Complexity for more details.
10666 \labelwidthstring 00.00.0000
10673 \begin_layout Standard
10683 \begin_inset LatexCommand index
10684 name "-\\/-float-reent"
10690 Floating point library is compiled as reentrant
10691 \begin_inset LatexCommand index
10697 See section Installation for more details.
10701 \labelwidthstring 00.00.0000
10708 \begin_layout Standard
10718 \begin_inset LatexCommand index
10719 name "-\\/-funsigned-char"
10725 The default signedness for every type is
10730 In some embedded environments the default signedness of
10739 To set the signess for characters to unsigned, use the option -
10745 \begin_layout Standard
10757 If this option is set and no signedness keyword (unsigned/signed) is given,
10758 a char will be signed.
10759 All other types are unaffected.
10763 \labelwidthstring 00.00.0000
10770 \begin_layout Standard
10780 \begin_inset LatexCommand index
10781 name "-\\/-main-return"
10787 This option can be used if the code generated is called by a monitor program
10788 or if the main routine includes an endless loop.
10789 This option results in slightly smaller code and saves two bytes of stack
10791 The return from the 'main'
10792 \begin_inset LatexCommand index
10797 function will return to the function calling main.
10798 The default setting is to lock up i.e.
10807 \labelwidthstring 00.00.0000
10814 \begin_layout Standard
10824 \begin_inset LatexCommand index
10825 name "-\\/-nostdinc"
10831 This will prevent the compiler from passing on the default include path
10832 to the preprocessor.
10836 \labelwidthstring 00.00.0000
10843 \begin_layout Standard
10853 \begin_inset LatexCommand index
10854 name "-\\/-nostdlib"
10860 This will prevent the compiler from passing on the default library
10861 \begin_inset LatexCommand index
10866 path to the linker.
10870 \labelwidthstring 00.00.0000
10877 \begin_layout Standard
10887 \begin_inset LatexCommand index
10888 name "-\\/-verbose"
10894 Shows the various actions the compiler is performing.
10898 \labelwidthstring 00.00.0000
10902 \begin_inset LatexCommand index
10909 Shows the actual commands the compiler is executing.
10913 \labelwidthstring 00.00.0000
10920 \begin_layout Standard
10930 \begin_inset LatexCommand index
10931 name "-\\/-no-c-code-in-asm"
10937 Hides your ugly and inefficient c-code from the asm file, so you can always
10938 blame the compiler :)
10942 \labelwidthstring 00.00.0000
10949 \begin_layout Standard
10959 \begin_inset LatexCommand index
10960 name "-\\/-no-gen-comments"
10966 Include code generator and peep-hole comments in the generated asm files.
10970 \labelwidthstring 00.00.0000
10977 \begin_layout Standard
10987 \begin_inset LatexCommand index
10988 name "-\\/-no-peep-comments"
10994 Don't include peep-hole comments in the generated asm files even if -
11000 \begin_layout Standard
11011 -fverbose-asm option is specified.
11015 \labelwidthstring 00.00.0000
11022 \begin_layout Standard
11032 \begin_inset LatexCommand index
11033 name "-\\/-i-code-in-asm"
11039 Include i-codes in the asm file.
11040 Sounds like noise but is most helpful for debugging the compiler itself.
11044 \labelwidthstring 00.00.0000
11051 \begin_layout Standard
11061 \begin_inset LatexCommand index
11067 \begin_inset LatexCommand index
11068 name "-\\/-less-pedantic"
11075 \begin_inset LatexCommand label
11076 name "lyx:--less-pedantic"
11080 Disable some of the more pedantic warnings
11081 \begin_inset LatexCommand index
11087 For more details, see the less_pedantic pragma
11088 \begin_inset LatexCommand vpageref
11089 reference "ite:less_pedantic"
11097 \labelwidthstring 00.00.0000
11104 \begin_layout Standard
11113 -disable-warning\InsetSpace ~
11115 \begin_inset LatexCommand index
11116 name "-\\/-disable-warning"
11122 Disable specific warning with number <nnnn>.
11126 \labelwidthstring 00.00.0000
11133 \begin_layout Standard
11143 \begin_inset LatexCommand index
11150 Treat all warnings as errors.
11154 \labelwidthstring 00.00.0000
11161 \begin_layout Standard
11171 \begin_inset LatexCommand index
11172 name "-\\/-print-search-dirs"
11178 Display the directories in the compiler's search path
11182 \labelwidthstring 00.00.0000
11189 \begin_layout Standard
11199 \begin_inset LatexCommand index
11206 Display errors and warnings using MSVC style, so you can use SDCC with
11207 the visual studio IDE
11208 \begin_inset LatexCommand index
11214 With SDCC both offering a GCC-like (the default) and a MSVC-like
11215 \begin_inset LatexCommand index
11216 name "MSVC output style"
11220 output style, integration into most programming editors should be straightforwa
11225 \labelwidthstring 00.00.0000
11232 \begin_layout Standard
11242 \begin_inset LatexCommand index
11243 name "-\\/-use-stdout"
11249 Send errors and warnings to stdout instead of stderr.
11253 \labelwidthstring 00.00.0000
11257 asmOption[,asmOption]
11260 \begin_inset LatexCommand index
11261 name "-Wa asmOption[,asmOption]"
11266 Pass the asmOption to the assembler
11267 \begin_inset LatexCommand index
11268 name "Options assembler"
11273 \begin_inset LatexCommand index
11274 name "Assembler options"
11279 See file sdcc/as/doc/asxhtm.html for assembler options.cd
11283 \labelwidthstring 00.00.0000
11290 \begin_layout Standard
11300 \begin_inset LatexCommand index
11301 name "-\\/-std-sdcc89"
11307 Generally follow the C89 standard, but allow SDCC features that conflict
11308 with the standard (default).
11312 \labelwidthstring 00.00.0000
11319 \begin_layout Standard
11329 \begin_inset LatexCommand index
11330 name "-\\/-std-c89"
11336 Follow the C89 standard and disable SDCC features that conflict with the
11341 \labelwidthstring 00.00.0000
11348 \begin_layout Standard
11358 \begin_inset LatexCommand index
11359 name "-\\/-std-sdcc99"
11365 Generally follow the C99 standard, but allow SDCC features that conflict
11366 with the standard (incomplete support).
11370 \labelwidthstring 00.00.0000
11377 \begin_layout Standard
11387 \begin_inset LatexCommand index
11388 name "-\\/-std-sdcc99"
11394 Follow the C99 standard and disable SDCC features that conflict with the
11395 standard (incomplete support).
11399 \labelwidthstring 00.00.0000
11406 \begin_layout Standard
11418 \begin_inset LatexCommand index
11419 name "-\\/-codeseg <Value>"
11424 \begin_inset LatexCommand label
11425 name "lyx:-codeseg"
11430 <Name> The name to be used for the code
11431 \begin_inset LatexCommand index
11436 segment, default CSEG.
11437 This is useful if you need to tell the compiler to put the code in a special
11438 segment so you can later on tell the linker to put this segment in a special
11440 Can be used for instance when using bank switching to put the code in a
11445 \labelwidthstring 00.00.0000
11452 \begin_layout Standard
11464 \begin_inset LatexCommand index
11465 name "-\\/-constseg <Value>"
11470 <Name> The name to be used for the const
11471 \begin_inset LatexCommand index
11476 segment, default CONST.
11477 This is useful if you need to tell the compiler to put the const data in
11478 a special segment so you can later on tell the linker to put this segment
11479 in a special place in memory.
11480 Can be used for instance when using bank switching to put the const data
11485 \labelwidthstring 00.00.0000
11492 \begin_layout Standard
11501 -fdollars-in-identifiers
11502 \begin_inset LatexCommand index
11503 name "-\\/-fdollars-in-identifiers"
11509 Permit '$' as an identifier character.
11513 \labelwidthstring 00.00.0000
11520 \begin_layout Standard
11532 \begin_inset LatexCommand index
11533 name "-\\/-more-pedantic"
11538 \begin_inset LatexCommand index
11549 a SDCC compiler option but if you want
11553 warnings you can use a separate tool dedicated to syntax checking like
11555 \begin_inset LatexCommand label
11556 name "lyx:more-pedantic-SPLINT"
11561 \begin_inset LatexCommand index
11562 name "lint (syntax checking tool)"
11567 \begin_inset LatexCommand url
11568 target "http://www.splint.org"
11573 To make your source files parseable by splint you will have to include
11579 \begin_inset LatexCommand index
11580 name "splint (syntax checking tool)"
11584 in your source file and add brackets around extended keywords (like
11587 \begin_inset Quotes sld
11600 \begin_inset Quotes srd
11608 \begin_inset Quotes sld
11611 __interrupt\InsetSpace ~
11613 \begin_inset Quotes srd
11621 Splint has an excellent on line manual at
11622 \begin_inset LatexCommand url
11623 target "http://www.splint.org/manual/"
11627 and it's capabilities go beyond pure syntax checking.
11628 You'll need to tell splint the location of SDCC's include files so a typical
11629 command line could look like this:
11633 splint\InsetSpace ~
11635 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11641 \labelwidthstring 00.00.0000
11648 \begin_layout Standard
11660 \begin_inset LatexCommand index
11661 name "-\\/-short-is-8bits"
11666 \begin_inset LatexCommand label
11667 name "lyx:--short-is-8bits"
11671 Treat short as 8-bit (for backward compatibility with older versions of
11672 compiler - see section
11673 \begin_inset LatexCommand ref
11674 reference "sec:Compatibility-with-previous"
11681 \begin_layout Standard
11682 \begin_inset VSpace bigskip
11688 \begin_layout Subsection
11689 Intermediate Dump Options
11690 \begin_inset LatexCommand label
11691 name "sub:Intermediate-Dump-Options"
11696 \begin_inset LatexCommand index
11697 name "Options intermediate dump"
11702 \begin_inset LatexCommand index
11703 name "Intermediate dump options"
11710 \begin_layout Standard
11711 The following options are provided for the purpose of retargetting and debugging
11713 They provide a means to dump the intermediate code (iCode
11714 \begin_inset LatexCommand index
11719 ) generated by the compiler in human readable form at various stages of
11720 the compilation process.
11721 More on iCodes see chapter
11722 \begin_inset LatexCommand ref
11723 reference "sub:The-anatomy-of"
11728 \begin_inset Quotes srd
11731 The anatomy of the compiler
11732 \begin_inset Quotes srd
11739 \labelwidthstring 00.00.0000
11746 \begin_layout Standard
11756 \begin_inset LatexCommand index
11757 name "-\\/-dumpraw"
11763 This option will cause the compiler to dump the intermediate code into
11766 <source filename>.dumpraw
11768 just after the intermediate code has been generated for a function, i.e.
11769 before any optimizations are done.
11771 \begin_inset LatexCommand index
11772 name "Basic blocks"
11776 at this stage ordered in the depth first number, so they may not be in
11777 sequence of execution.
11781 \labelwidthstring 00.00.0000
11788 \begin_layout Standard
11798 \begin_inset LatexCommand index
11799 name "-\\/-dumpgcse"
11805 Will create a dump of iCodes, after global subexpression elimination
11806 \begin_inset LatexCommand index
11807 name "Global subexpression elimination"
11811 , into a file named
11813 <source filename>.dumpgcse.
11817 \labelwidthstring 00.00.0000
11824 \begin_layout Standard
11834 \begin_inset LatexCommand index
11835 name "-\\/-dumpdeadcode"
11841 Will create a dump of iCodes, after deadcode elimination
11842 \begin_inset LatexCommand index
11843 name "Dead-code elimination"
11847 , into a file named
11849 <source filename>.dumpdeadcode.
11853 \labelwidthstring 00.00.0000
11860 \begin_layout Standard
11870 \begin_inset LatexCommand index
11871 name "-\\/-dumploop"
11880 Will create a dump of iCodes, after loop optimizations
11881 \begin_inset LatexCommand index
11882 name "Loop optimization"
11886 , into a file named
11888 <source filename>.dumploop.
11892 \labelwidthstring 00.00.0000
11899 \begin_layout Standard
11909 \begin_inset LatexCommand index
11910 name "-\\/-dumprange"
11919 Will create a dump of iCodes, after live range analysis
11920 \begin_inset LatexCommand index
11921 name "Live range analysis"
11925 , into a file named
11927 <source filename>.dumprange.
11931 \labelwidthstring 00.00.0000
11938 \begin_layout Standard
11948 \begin_inset LatexCommand index
11949 name "-\\/-dumlrange"
11955 Will dump the life ranges
11956 \begin_inset LatexCommand index
11957 name "Live range analysis"
11965 \labelwidthstring 00.00.0000
11972 \begin_layout Standard
11982 \begin_inset LatexCommand index
11983 name "-\\/-dumpregassign"
11989 Will create a dump of iCodes, after register assignment
11990 \begin_inset LatexCommand index
11991 name "Register assignment"
11995 , into a file named
11997 <source filename>.dumprassgn.
12001 \labelwidthstring 00.00.0000
12008 \begin_layout Standard
12018 \begin_inset LatexCommand index
12019 name "-\\/-dumplrange"
12025 Will create a dump of the live ranges of iTemp's
12029 \labelwidthstring 00.00.0000
12036 \begin_layout Standard
12046 \begin_inset LatexCommand index
12047 name "-\\/-dumpall"
12056 Will cause all the above mentioned dumps to be created.
12059 \begin_layout Standard
12060 \begin_inset VSpace bigskip
12066 \begin_layout Subsection
12067 Redirecting output on Windows Shells
12070 \begin_layout Standard
12071 By default SDCC writes its error messages to
12072 \begin_inset Quotes sld
12076 \begin_inset Quotes srd
12080 To force all messages to
12081 \begin_inset Quotes sld
12085 \begin_inset Quotes srd
12097 \begin_layout Standard
12112 \begin_inset LatexCommand index
12113 name "-\\/-use-stdout"
12118 Additionally, if you happen to have visual studio installed in your windows
12119 machine, you can use it to compile your sources using a custom build and
12126 \begin_layout Standard
12138 \begin_inset LatexCommand index
12144 Something like this should work:
12163 \begin_layout Standard
12182 \begin_layout Standard
12194 -model-large -c $(InputPath)
12197 \begin_inset VSpace bigskip
12203 \begin_layout Section
12204 Environment variables
12205 \begin_inset LatexCommand index
12206 name "Environment variables"
12213 \begin_layout Standard
12214 SDCC recognizes the following environment variables:
12218 \labelwidthstring 00.00.0000
12222 \begin_inset LatexCommand index
12223 name "SDCC\\_LEAVE\\_SIGNALS"
12229 SDCC installs a signal handler
12230 \begin_inset LatexCommand index
12231 name "signal handler"
12235 to be able to delete temporary files after an user break (^C) or an exception.
12236 If this environment variable is set, SDCC won't install the signal handler
12237 in order to be able to debug SDCC.
12241 \labelwidthstring 00.00.0000
12247 \begin_inset LatexCommand index
12248 name "TMP, TEMP, TMPDIR"
12254 Path, where temporary files will be created.
12255 The order of the variables is the search order.
12256 In a standard *nix environment these variables are not set, and there's
12257 no need to set them.
12258 On Windows it's recommended to set one of them.
12262 \labelwidthstring 00.00.0000
12266 \begin_inset LatexCommand index
12274 \begin_inset LatexCommand ref
12275 reference "sub:Install-paths"
12281 \begin_inset Quotes sld
12285 \begin_inset Quotes srd
12292 \labelwidthstring 00.00.0000
12296 \begin_inset LatexCommand index
12297 name "SDCC\\_INCLUDE"
12304 \begin_inset LatexCommand ref
12305 reference "sub:Search-Paths"
12311 \begin_inset Quotes sld
12315 \begin_inset Quotes srd
12322 \labelwidthstring 00.00.0000
12326 \begin_inset LatexCommand index
12334 \begin_inset LatexCommand ref
12335 reference "sub:Search-Paths"
12341 \begin_inset Quotes sld
12345 \begin_inset Quotes srd
12351 \begin_layout Standard
12352 There are some more environment variables recognized by SDCC, but these
12353 are solely used for debugging purposes.
12354 They can change or disappear very quickly, and will never be documented.
12355 \begin_inset VSpace bigskip
12361 \begin_layout Section
12362 Storage Class Language Extensions
12365 \begin_layout Subsection
12366 MCS51/DS390 Storage Class
12367 \begin_inset LatexCommand index
12368 name "Storage class"
12372 Language Extensions
12375 \begin_layout Standard
12376 In addition to the ANSI storage classes SDCC allows the following MCS51
12377 specific storage classes:
12380 \begin_layout Subsubsection
12382 \begin_inset LatexCommand index
12383 name "data (mcs51, ds390 storage class)"
12388 \begin_inset LatexCommand index
12389 name "\\_\\_data (mcs51, ds390 storage class)"
12394 \begin_inset LatexCommand index
12395 name "near (storage class)"
12400 \begin_inset LatexCommand index
12401 name "\\_\\_near (storage class)"
12408 \begin_layout Standard
12413 storage class for the Small Memory model (
12421 or the more ANSI-C compliant forms
12429 can be used synonymously).
12430 Variables declared with this storage class will be allocated in the directly
12431 addressable portion of the internal RAM of a 8051, e.g.:
12434 \begin_layout Verse
12437 __data unsigned char test_data;
12440 \begin_layout Standard
12441 Writing 0x01 to this variable generates the assembly code:
12444 \begin_layout Verse
12447 75*00 01\InsetSpace ~
12455 \begin_layout Subsubsection
12457 \begin_inset LatexCommand index
12458 name "xdata (mcs51, ds390 storage class)"
12463 \begin_inset LatexCommand index
12464 name "\\_\\_xdata (mcs51, ds390 storage class)"
12469 \begin_inset LatexCommand index
12470 name "far (storage class)"
12475 \begin_inset LatexCommand index
12476 name "\\_\\_far (storage class)"
12483 \begin_layout Standard
12484 Variables declared with this storage class will be placed in the external
12490 storage class for the Large Memory model, e.g.:
12493 \begin_layout Verse
12496 __xdata unsigned char test_xdata;
12499 \begin_layout Standard
12500 Writing 0x01 to this variable generates the assembly code:
12503 \begin_layout Verse
12506 90s00r00\InsetSpace ~
12537 \begin_layout Subsubsection
12539 \begin_inset LatexCommand index
12540 name "idata (mcs51, ds390 storage class)"
12545 \begin_inset LatexCommand index
12546 name "\\_\\_idata (mcs51, ds390 storage class)"
12553 \begin_layout Standard
12554 Variables declared with this storage class will be allocated into the indirectly
12555 addressable portion of the internal ram of a 8051, e.g.:
12558 \begin_layout Verse
12561 __idata unsigned char test_idata;
12564 \begin_layout Standard
12565 Writing 0x01 to this variable generates the assembly code:
12568 \begin_layout Verse
12595 \begin_layout Standard
12596 Please note, the first 128 byte of idata physically access the same RAM
12597 as the data memory.
12598 The original 8051 had 128 byte idata memory, nowadays most devices have
12599 256 byte idata memory.
12601 \begin_inset LatexCommand index
12606 is located in idata memory.
12609 \begin_layout Subsubsection
12611 \begin_inset LatexCommand index
12612 name "pdata (mcs51, ds390 storage class)"
12617 \begin_inset LatexCommand index
12618 name "\\_\\_pdata (mcs51, ds390 storage class)"
12625 \begin_layout Standard
12626 Paged xdata access is just as straightforward as using the other addressing
12628 It is typically located at the start of xdata and has a maximum size of
12630 The following example writes 0x01 to the pdata variable.
12631 Please note, pdata access physically accesses xdata memory.
12632 The high byte of the address is determined by port P2
12633 \begin_inset LatexCommand index
12634 name "P2 (mcs51 sfr)"
12638 (or in case of some 8051 variants by a separate Special Function Register,
12640 \begin_inset LatexCommand ref
12641 reference "sub:MCS51-variants"
12650 storage class for the Medium Memory model, e.g.:
12653 \begin_layout Verse
12656 __pdata unsigned char test_pdata;
12659 \begin_layout Standard
12660 Writing 0x01 to this variable generates the assembly code:
12663 \begin_layout Verse
12672 mov r0,#_test_pdata
12694 \begin_layout Standard
12699 \begin_layout Standard
12709 \begin_inset LatexCommand index
12714 option is used the pdata memory area is followed by the xstack memory area
12715 and the sum of their sizes is limited to 256 bytes.
12718 \begin_layout Subsubsection
12720 \begin_inset LatexCommand index
12726 \begin_inset LatexCommand index
12734 \begin_layout Standard
12735 'Variables' declared with this storage class will be placed in the code
12739 \begin_layout Verse
12742 __code unsigned char test_code;
12745 \begin_layout Standard
12746 Read access to this variable generates the assembly code:
12749 \begin_layout Verse
12752 90s00r6F\InsetSpace ~
12755 mov dptr,#_test_code
12780 \begin_layout Standard
12785 indexed arrays of characters in code memory can be accessed efficiently:
12788 \begin_layout Verse
12791 __code char test_array[] = {'c','h','e','a','p'};
12794 \begin_layout Standard
12795 Read access to this array using an 8-bit unsigned index generates the assembly
12799 \begin_layout Verse
12811 \begin_layout Verse
12814 90s00r41\InsetSpace ~
12817 mov dptr,#_test_array
12820 \begin_layout Verse
12835 \begin_layout Subsubsection
12837 \begin_inset LatexCommand index
12843 \begin_inset LatexCommand index
12851 \begin_layout Standard
12852 This is a data-type and a storage class specifier.
12853 When a variable is declared as a bit, it is allocated into the bit addressable
12854 memory of 8051, e.g.:
12857 \begin_layout Verse
12863 \begin_layout Standard
12864 Writing 1 to this variable generates the assembly code:
12867 \begin_layout Verse
12881 \begin_layout Standard
12882 The bit addressable memory consists of 128 bits which are located from 0x20
12883 to 0x2f in data memory.
12886 Apart from this 8051 specific storage class most architectures support
12888 \begin_inset LatexCommand index
12897 \begin_layout Standard
12898 Not really meant as examples, but nevertheless showing what bitfields are
12899 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12905 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12906 signed modifier are implemented as unsigned.
12909 \begin_layout Subsubsection
12911 \begin_inset LatexCommand index
12917 \begin_inset LatexCommand index
12923 \begin_inset LatexCommand index
12929 \begin_inset LatexCommand index
12935 \begin_inset LatexCommand index
12941 \begin_inset LatexCommand index
12947 \begin_inset LatexCommand index
12953 \begin_inset LatexCommand index
12961 \begin_layout Standard
12962 Like the bit keyword,
12964 sfr / sfr16 / sfr32 / sbit
12966 signify both a data-type and storage class, they are used to describe the
12987 variables of a 8051, eg:
12990 \begin_layout Verse
12994 \begin_inset LatexCommand index
13000 \begin_inset LatexCommand index
13005 (0x80) P0;\InsetSpace ~
13006 /* special function register P0 at location 0x80 */
13011 special function register combination for timer 0
13015 with the high byte at
13016 location 0x8C and the low byte at location 0x8A */
13018 __sfr16 __at (0x8C8A)
13024 \begin_inset LatexCommand index
13030 \begin_inset LatexCommand index
13035 (0xd7) CY;\InsetSpace ~
13037 \begin_inset LatexCommand index
13043 \begin_inset LatexCommand index
13051 \begin_layout Standard
13052 Special function registers which are located on an address dividable by
13053 8 are bit-addressable, an
13057 addresses a specific bit within these sfr.
13059 16 Bit and 32 bit special function
13060 register combinations which require a certain access order are better not
13070 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
13071 this is not guaranteed.
13076 \begin_layout Standard
13077 Please note, if you use a header file which was written for another compiler
13078 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13084 Specifically the syntax
13087 sfr P0 = 0x80;\InsetSpace ~
13094 by SDCC to an assignment of 0x80 to a variable called P0
13097 \begin_inset Marginal
13100 \begin_layout Standard
13114 Nevertheless it is possible to write header files
13115 \begin_inset LatexCommand index
13116 name "Header files"
13121 \begin_inset LatexCommand index
13122 name "Include files"
13126 which can be shared among different compilers (see section
13127 \begin_inset LatexCommand ref
13128 reference "sec:Porting-code-to-other-compilers"
13136 \begin_layout Subsubsection
13138 \begin_inset LatexCommand index
13143 to MCS51/DS390 specific memory spaces
13146 \begin_layout Standard
13147 SDCC allows (via language extensions) pointers to explicitly point to any
13148 of the memory spaces
13149 \begin_inset LatexCommand index
13150 name "Memory model"
13155 In addition to the explicit pointers, the compiler uses (by default) generic
13156 pointers which can be used to point to any of the memory spaces.
13161 declaration examples:
13164 \begin_layout Verse
13167 /* pointer physically in internal ram pointing to object in external ram
13170 __xdata unsigned char * __data p;
13174 /* pointer physically in external ram
13175 pointing to object in internal ram */
13177 __data unsigned char * __xdata p;
13182 pointer physically in code rom pointing to data in xdata space */
13185 unsigned char * __code p;
13189 /* pointer physically in code space pointing to
13190 data in code space */
13192 __code unsigned char * __code p;
13197 physically located in xdata space */
13199 unsigned char * __xdata p;
13204 pointer physically located in default memory space */
13211 the following is a function pointer
13212 \begin_inset LatexCommand index
13213 name "function pointer"
13217 physically located in data space */
13219 char (* __data fp)(void);
13222 \begin_layout Standard
13223 Well you get the idea.
13228 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
13241 The highest order byte of the
13245 pointers contains the data space information.
13246 Assembler support routines are called whenever data is stored or retrieved
13252 These are useful for developing reusable library
13253 \begin_inset LatexCommand index
13259 Explicitly specifying the pointer
13260 \begin_inset LatexCommand index
13265 type will generate the most efficient code.
13268 \begin_layout Subsubsection
13269 Notes on MCS51 memory
13270 \begin_inset LatexCommand index
13271 name "MCS51 memory"
13278 \begin_layout Standard
13279 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13280 RAM memory which is structured as follows:
13284 - Bytes 00-1F - 32 bytes to hold
13285 up to 4 banks of the registers R0 to R7,
13287 - Bytes 20-2F - 16 bytes to hold
13289 \begin_inset LatexCommand index
13296 - Bytes 30-7F - 80 bytes for general purpose use.
13301 \begin_layout Standard
13302 Additionally some members of the MCS51 family may have up to 128 bytes of
13303 additional, indirectly addressable, internal RAM memory (
13308 \begin_inset LatexCommand index
13309 name "idata (mcs51, ds390 storage class)"
13314 \begin_inset LatexCommand index
13315 name "\\_\\_idata (mcs51, ds390 storage class)"
13320 Furthermore, some chips may have some built in external memory (
13325 \begin_inset LatexCommand index
13326 name "xdata (mcs51, ds390 storage class)"
13331 \begin_inset LatexCommand index
13332 name "\\_\\_xdata (mcs51, ds390 storage class)"
13336 ) which should not be confused with the internal, directly addressable RAM
13342 \begin_inset LatexCommand index
13343 name "data (mcs51, ds390 storage class)"
13348 \begin_inset LatexCommand index
13349 name "\\_\\_data (mcs51, ds390 storage class)"
13354 Sometimes this built in
13358 memory has to be activated before using it (you can probably find this
13359 information on the datasheet of the microcontroller your are using, see
13361 \begin_inset LatexCommand ref
13362 reference "sub:Startup-Code"
13370 \begin_layout Standard
13371 Normally SDCC will only use the first bank
13372 \begin_inset LatexCommand index
13373 name "register bank (mcs51, ds390)"
13377 of registers (register bank 0), but it is possible to specify that other
13378 banks of registers (keyword
13385 \begin_inset LatexCommand index
13386 name "using (mcs51, ds390 register bank)"
13391 \begin_inset LatexCommand index
13392 name "\\_\\_using (mcs51, ds390 register bank)"
13398 ) should be used for example in interrupt
13399 \begin_inset LatexCommand index
13405 \begin_inset LatexCommand index
13406 name "\\_\\_interrupt"
13411 By default, the compiler will place the stack after the last byte of allocated
13412 memory for variables.
13413 For example, if the first 2 banks of registers are used, and only four
13418 variables, it will position the base of the internal stack at address 20
13420 This implies that as the stack
13421 \begin_inset LatexCommand index
13426 grows, it will use up the remaining register banks, and the 16 bytes used
13427 by the 128 bit variables, and 80 bytes for general purpose use.
13428 If any bit variables are used, the data variables will be placed in unused
13429 register banks and after the byte holding the last bit variable.
13430 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13435 variables will be placed starting from address 0x10 to 0x20 and continue
13441 \begin_layout Standard
13451 \begin_inset LatexCommand index
13452 name "-\\/-data-loc <Value>"
13456 to specify the start address of the
13464 \begin_layout Standard
13474 \begin_inset LatexCommand index
13475 name "-\\/-iram-size <Value>"
13479 to specify the size of the total internal RAM (
13493 \begin_layout Standard
13494 By default the 8051 linker will place the stack after the last byte of (i)data
13500 \begin_layout Standard
13510 \begin_inset LatexCommand index
13511 name "-\\/-stack-loc <Value>"
13515 allows you to specify the start of the stack, i.e.
13516 you could start it after any data in the general purpose area.
13517 If your microcontroller has additional indirectly addressable internal
13522 ) you can place the stack on it.
13523 You may also need to use -
13527 \begin_layout Standard
13537 \begin_inset LatexCommand index
13538 name "-\\/-xdata-loc<Value>"
13542 to set the start address of the external RAM (
13550 \begin_layout Standard
13560 \begin_inset LatexCommand index
13561 name "-\\/-xram-size <Value>"
13565 to specify its size.
13566 Same goes for the code memory, using -
13570 \begin_layout Standard
13580 \begin_inset LatexCommand index
13581 name "-\\/-code-loc <Value>"
13589 \begin_layout Standard
13599 \begin_inset LatexCommand index
13600 name "-\\/-code-size <Value>"
13605 If in doubt, don't specify any options and see if the resulting memory
13606 layout is appropriate, then you can adjust it.
13609 \begin_layout Standard
13610 The linker generates two files with memory allocation information.
13611 The first, with extension .map
13612 \begin_inset LatexCommand index
13617 shows all the variables and segments.
13618 The second with extension .mem
13619 \begin_inset LatexCommand index
13624 shows the final memory layout.
13625 The linker will complain either if memory segments overlap, there is not
13626 enough memory, or there is not enough space for stack.
13627 If you get any linking warnings and/or errors related to stack or segments
13628 allocation, take a look at either the .map or .mem files to find out what
13630 The .mem file may even suggest a solution to the problem.
13631 \begin_inset VSpace bigskip
13637 \begin_layout Subsection
13638 Z80/Z180 Storage Class
13639 \begin_inset LatexCommand index
13640 name "Z80!Storage class"
13644 Language Extensions
13647 \begin_layout Subsubsection
13649 \begin_inset LatexCommand index
13655 \begin_inset LatexCommand index
13660 (in/out to 8-bit addresses)
13663 \begin_layout Standard
13665 \begin_inset LatexCommand index
13670 family has separate address spaces for memory and
13680 \begin_inset LatexCommand index
13681 name "I/O memory (Z80, Z180)"
13686 \begin_inset LatexCommand index
13687 name "Z80!I/O memory"
13692 \begin_inset LatexCommand index
13693 name "Z180!I/O memory"
13697 is accessed with special instructions, e.g.:
13700 \begin_layout Verse
13703 sfr at 0x78 IoPort;\InsetSpace ~
13705 /* define a var in I/O space at 78h called IoPort */
13709 \begin_layout Standard
13710 Writing 0x01 to this variable generates the assembly code:
13713 \begin_layout Verse
13733 \begin_layout Subsubsection
13735 \begin_inset LatexCommand index
13741 \begin_inset LatexCommand index
13746 (in/out to 16-bit addresses)
13749 \begin_layout Standard
13754 is used to support 16 bit addresses in I/O memory e.g.:
13757 \begin_layout Verse
13761 \begin_inset LatexCommand index
13767 \begin_inset LatexCommand index
13775 \begin_layout Standard
13776 Writing 0x01 to this variable generates the assembly code:
13779 \begin_layout Verse
13782 01 23 01\InsetSpace ~
13804 \begin_layout Subsubsection
13806 \begin_inset LatexCommand index
13812 \begin_inset LatexCommand index
13817 (in0/out0 to 8 bit addresses on Z180
13818 \begin_inset LatexCommand index
13824 \begin_inset LatexCommand index
13825 name "HD64180 (see Z180)"
13832 \begin_layout Standard
13833 The compiler option -
13837 \begin_layout Standard
13847 \begin_inset LatexCommand index
13848 name "Z180!Options!-\\/-portmode"
13852 =180 (80) and a compiler #pragma\InsetSpace ~
13854 \begin_inset LatexCommand index
13855 name "Z180!Pragmas!\\#pragma portmode"
13859 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13869 If you include the file z180.h this will be set automatically.
13870 \begin_inset VSpace bigskip
13876 \begin_layout Subsection
13878 \begin_inset LatexCommand index
13879 name "HC08!Storage class"
13883 Language Extensions
13886 \begin_layout Subsubsection
13888 \begin_inset LatexCommand index
13889 name "data (hc08 storage class)"
13894 \begin_inset LatexCommand index
13895 name "\\_\\_data (hc08 storage class)"
13902 \begin_layout Standard
13903 The data storage class declares a variable that resides in the first 256
13904 bytes of memory (the direct page).
13906 \begin_inset LatexCommand index
13911 is most efficient at accessing variables (especially pointers) stored here.
13914 \begin_layout Subsubsection
13916 \begin_inset LatexCommand index
13917 name "xdata (hc08 storage class)"
13922 \begin_inset LatexCommand index
13923 name "\\_\\_xdata (hc08 storage class)"
13930 \begin_layout Standard
13931 The xdata storage class declares a variable that can reside anywhere in
13933 This is the default if no storage class is specified.
13935 \begin_inset VSpace bigskip
13941 \begin_layout Section
13942 Other SDCC language extensions
13943 \begin_inset LatexCommand index
13944 name "Other SDCC language extensions"
13951 \begin_layout Subsection
13955 \begin_layout Standard
13956 SDCC supports the use of binary constants, such as 0b01100010.
13957 This feature is only enabled when the compiler is invoked using --std-sdccxx.
13960 \begin_layout Standard
13961 \begin_inset VSpace bigskip
13967 \begin_layout Section
13968 Absolute Addressing
13969 \begin_inset LatexCommand index
13970 name "Absolute addressing"
13977 \begin_layout Standard
13978 Data items can be assigned an absolute address with the
13981 \begin_inset LatexCommand index
13987 \begin_inset LatexCommand index
13994 keyword, in addition to a storage class, e.g.:
13997 \begin_layout Verse
14001 \begin_inset LatexCommand index
14002 name "xdata (mcs51, ds390 storage class)"
14007 \begin_inset LatexCommand index
14008 name "\\_\\_xdata (mcs51, ds390 storage class)"
14013 \begin_inset LatexCommand index
14019 \begin_inset LatexCommand index
14024 0x7ffe unsigned int chksum;
14027 \begin_layout Standard
14028 or, better conforming to ISO/IEC 9899 C:
14031 \begin_layout Verse
14034 __xdata __at (0x7ffe) unsigned int chksum;
14037 \begin_layout Standard
14038 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
14039 of the external ram.
14044 reserve any space for variables declared in this way
14045 \begin_inset Marginal
14048 \begin_layout Standard
14057 (they are implemented with an equate in the assembler).
14058 Thus it is left to the programmer to make sure there are no overlaps with
14059 other variables that are declared without the absolute address.
14060 The assembler listing file (.lst
14061 \begin_inset LatexCommand index
14066 ) and the linker output files (.rst
14067 \begin_inset LatexCommand index
14073 \begin_inset LatexCommand index
14078 ) are good places to look for such overlaps.
14081 \begin_layout Standard
14082 If however you provide an initializer
14083 \begin_inset LatexCommand index
14084 name "Variable initialization"
14088 actual memory allocation will take place and overlaps will be detected
14093 \begin_layout Verse
14096 __code __at (0x7ff0) char Id[5] =
14097 \begin_inset Quotes sld
14101 \begin_inset Quotes srd
14107 \begin_layout Standard
14108 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14112 \begin_layout Standard
14113 In case of memory mapped I/O devices the keyword
14117 has to be used to tell the compiler that accesses might not be removed:
14120 \begin_layout Verse
14124 \begin_inset LatexCommand index
14130 \begin_inset LatexCommand index
14131 name "xdata (mcs51, ds390 storage class)"
14136 \begin_inset LatexCommand index
14141 (0x8000) unsigned char PORTA_8255;
14144 \begin_layout Standard
14145 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14150 \begin_inset LatexCommand index
14151 name "Aligned array"
14158 starts at a block (256 byte) boundary
14159 \begin_inset LatexCommand index
14160 name "block boundary"
14165 \begin_inset LatexCommand ref
14166 reference "sub:A-Step-by Assembler Introduction"
14172 Absolute addresses can be specified for variables in all
14173 storage classes, e.g.:
14176 \begin_layout Verse
14180 \begin_inset LatexCommand index
14186 \begin_inset LatexCommand index
14194 \begin_layout Standard
14195 The above example will allocate the variable at offset 0x02 in the bit-addressab
14197 There is no real advantage to assigning absolute addresses to variables
14198 in this manner, unless you want strict control over all the variables allocated.
14199 One possible use would be to write hardware portable code.
14200 For example, if you have a routine that uses one or more of the microcontroller
14201 I/O pins, and such pins are different for two different hardwares, you
14202 can declare the I/O pins in your routine using:
14205 \begin_layout Verse
14209 \begin_inset LatexCommand index
14214 __bit MOSI;\InsetSpace ~
14218 /* master out, slave in */
14220 extern volatile __bit MISO;\InsetSpace ~
14227 extern volatile __bit MCLK;\InsetSpace ~
14236 Output of a byte on a 3-wire serial bus.
14241 If needed adapt polarity of clock,
14242 polarity of data and bit order
14247 unsigned char spi_io(unsigned char out_byte)
14272 MOSI = out_byte & 0x80;
14303 /* _asm nop _endasm; */\InsetSpace ~
14311 /* for slow peripherals */
14363 \begin_layout Standard
14364 Then, someplace in the code for the first hardware you would use
14367 \begin_layout Verse
14371 \begin_inset LatexCommand index
14377 \begin_inset LatexCommand index
14382 (0x80) MOSI;\InsetSpace ~
14386 /* I/O port 0, bit 0 */
14388 __bit __at (0x81) MISO;\InsetSpace ~
14395 __bit __at (0x82) MCLK;\InsetSpace ~
14399 /* I/O port 0, bit 2 */
14402 \begin_layout Standard
14403 Similarly, for the second hardware you would use
14406 \begin_layout Verse
14409 __bit __at (0x83) MOSI;\InsetSpace ~
14413 /* I/O port 0, bit 3 */
14415 __bit __at (0x91) MISO;\InsetSpace ~
14420 I/O port 1, bit 1 */
14423 \begin_inset LatexCommand index
14428 __at (0x92) MCLK;\InsetSpace ~
14432 /* I/O port 1, bit 2 */
14435 \begin_layout Standard
14436 and you can use the same hardware dependent routine without changes, as
14437 for example in a library.
14438 This is somehow similar to sbit, but only one absolute address has to be
14439 specified in the whole project.
14440 \begin_inset VSpace bigskip
14446 \begin_layout Section
14448 \begin_inset LatexCommand index
14454 \begin_inset LatexCommand index
14455 name "function parameter"
14460 \begin_inset LatexCommand index
14461 name "local variables"
14466 \begin_inset LatexCommand label
14467 name "sec:Parameters-and-Local-Variables"
14474 \begin_layout Standard
14475 Automatic (local) variables and parameters to functions can either be placed
14476 on the stack or in data-space.
14477 The default action of the compiler is to place these variables in the internal
14478 RAM (for small model) or external RAM (for medium or large model).
14479 This in fact makes them similar to
14482 \begin_inset LatexCommand index
14489 so by default functions are non-reentrant
14490 \begin_inset LatexCommand index
14500 They can be placed on the stack
14501 \begin_inset LatexCommand index
14512 \begin_layout Standard
14522 \begin_inset LatexCommand index
14523 name "-\\/-stack-auto"
14531 #pragma\InsetSpace ~
14535 \begin_inset LatexCommand index
14536 name "\\#pragma stackauto"
14543 \begin_inset LatexCommand index
14550 keyword in the function declaration, e.g.:
14553 \begin_layout Verse
14556 unsigned char foo(char i) __reentrant
14570 \begin_layout Standard
14571 Since stack space on 8051 is limited, the
14581 \begin_layout Standard
14592 option should be used sparingly.
14593 Note that the reentrant keyword just means that the parameters & local
14594 variables will be allocated to the stack, it
14598 mean that the function is register bank
14599 \begin_inset LatexCommand index
14600 name "register bank (mcs51, ds390)"
14609 \begin_inset LatexCommand index
14610 name "local variables"
14614 can be assigned storage classes and absolute
14615 \begin_inset LatexCommand index
14616 name "Absolute addressing"
14623 \begin_layout Verse
14626 unsigned char foo()
14634 __xdata unsigned char i;
14647 \begin_inset LatexCommand index
14652 (0x31) unsigned char j;
14664 \begin_layout Standard
14665 In the above example the variable
14669 will be allocated in the external ram,
14673 in bit addressable space and
14684 \begin_layout Standard
14695 or when a function is declared as
14699 this should only be done for static variables.
14702 \begin_layout Standard
14704 \begin_inset LatexCommand index
14705 name "function parameter"
14709 however are not allowed any storage class
14710 \begin_inset LatexCommand index
14711 name "Storage class"
14715 , (storage classes for parameters will be ignored), their allocation is
14716 governed by the memory model in use, and the reentrancy options.
14719 \begin_layout Standard
14720 It is however allowed to use bit parameters in reentrant functions and also
14721 non-static local bit variables are supported.
14722 Efficient use is limited to 8 semi-bitregisters in bit space.
14723 They are pushed and popped to stack
14724 \begin_inset LatexCommand index
14729 as a single byte just like the normal registers.
14732 \begin_layout Section
14734 \begin_inset LatexCommand label
14735 name "sub:Overlaying"
14740 \begin_inset LatexCommand index
14748 \begin_layout Standard
14750 \begin_inset LatexCommand index
14755 functions SDCC will try to reduce internal ram space usage by overlaying
14756 parameters and local variables of a function (if possible).
14757 Parameters and local variables
14758 \begin_inset LatexCommand index
14759 name "local variables"
14763 of a function will be allocated to an overlayable segment if the function
14766 no other function calls and the function is non-reentrant and the memory
14768 \begin_inset LatexCommand index
14769 name "Memory model"
14776 If an explicit storage class
14777 \begin_inset LatexCommand index
14778 name "Storage class"
14782 is specified for a local variable, it will NOT be overlaid.
14785 \begin_layout Standard
14786 Note that the compiler (not the linkage editor) makes the decision for overlayin
14788 Functions that are called from an interrupt service routine
14789 \begin_inset Marginal
14792 \begin_layout Standard
14800 should be preceded by a #pragma\InsetSpace ~
14802 \begin_inset LatexCommand index
14803 name "\\#pragma nooverlay"
14807 if they are not reentrant.
14810 \begin_layout Standard
14811 Also note that the compiler does not do any processing of inline assembler
14812 code, so the compiler might incorrectly assign local variables and parameters
14813 of a function into the overlay segment if the inline assembler code calls
14814 other c-functions that might use the overlay.
14815 In that case the #pragma\InsetSpace ~
14816 nooverlay should be used.
14819 \begin_layout Standard
14820 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14822 \begin_inset LatexCommand index
14823 name "Multiplication"
14828 \begin_inset LatexCommand index
14833 will NOT be overlaid since these are implemented using external functions,
14837 \begin_layout Verse
14843 \begin_inset LatexCommand index
14844 name "\\#pragma nooverlay"
14850 void set_error(unsigned char errcd)
14867 some_isr () __interrupt
14868 \begin_inset LatexCommand index
14899 \begin_layout Standard
14900 In the above example the parameter
14908 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14910 not present, this could cause unpredictable runtime behavior when called
14911 from an interrupt service routine.
14912 The #pragma\InsetSpace ~
14913 nooverlay ensures that the parameters and local variables for
14914 the function are NOT overlaid.
14915 \begin_inset VSpace bigskip
14921 \begin_layout Section
14922 Interrupt Service Routines
14923 \begin_inset LatexCommand label
14924 name "sub:Interrupt-Service-Routines"
14931 \begin_layout Subsection
14932 General Information
14935 \begin_layout Standard
14948 outines to be coded in C, with some extended keywords.
14951 \begin_layout Verse
14954 void timer_isr (void) __interrupt (1) __using (1)
14968 \begin_layout Standard
14969 The optional number following the
14972 \begin_inset LatexCommand index
14978 \begin_inset LatexCommand index
14979 name "\\_\\_interrupt"
14985 keyword is the interrupt number this routine will service.
14986 When present, the compiler will insert a call to this routine in the interrupt
14988 \begin_inset LatexCommand index
14989 name "interrupt vector table"
14993 for the interrupt number specified.
14994 If you have multiple source files in your project, interrupt service routines
14995 can be present in any of them, but a prototype of the isr MUST be present
14996 or included in the file that contains the function
15001 The optional (8051 specific) keyword
15004 \begin_inset LatexCommand index
15005 name "using (mcs51, ds390 register bank)"
15010 \begin_inset LatexCommand index
15011 name "\\_\\_using (mcs51, ds390 register bank)"
15017 can be used to tell the compiler to use the specified register bank when
15018 generating code for this function.
15021 Interrupt service routines open the door for some very interesting bugs:
15024 \begin_layout Subsubsection
15025 \begin_inset LatexCommand label
15026 name "sub:Common-interrupt-pitfall-volatile"
15030 Common interrupt pitfall: variable not declared
15035 \begin_layout Standard
15036 If an interrupt service routine changes variables which are accessed by
15037 other functions these variables have to be declared
15042 \begin_inset LatexCommand index
15049 \begin_inset LatexCommand url
15050 target "http://en.wikipedia.org/wiki/Volatile_variable"
15057 \begin_layout Subsubsection
15058 \begin_inset LatexCommand label
15059 name "sub:Common-interrupt-pitfall-non-atomic"
15063 Common interrupt pitfall:
15068 \begin_layout Standard
15069 If the access to these variables is not
15072 \begin_inset LatexCommand index
15080 the processor needs more than one instruction for the access and could
15081 be interrupted while accessing the variable) the interrupt must be disabled
15082 during the access to avoid inconsistent data.
15085 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15086 and should be protected by disabling interrupts.
15087 You're not automatically on the safe side if you use 8 bit variables though.
15088 We need an example here: f.e.
15089 on the 8051 the harmless looking
15090 \begin_inset Quotes srd
15100 \begin_inset Quotes sld
15109 \begin_inset Quotes srd
15119 \begin_inset Quotes sld
15122 from within an interrupt routine might get lost if the interrupt occurs
15125 \begin_inset Quotes sld
15130 counter\InsetSpace ~
15135 \begin_inset Quotes srd
15138 is not atomic on the 8051 even if
15142 is located in data memory.
15144 Bugs like these are hard to reproduce and can
15145 cause a lot of trouble.
15149 \begin_layout Subsubsection
15150 \begin_inset LatexCommand label
15151 name "sub:Common-interrupt-pitfall-stack-overflow"
15155 Common interrupt pitfall:
15160 \begin_layout Standard
15161 The return address and the registers used in the interrupt service routine
15162 are saved on the stack
15163 \begin_inset LatexCommand index
15168 so there must be sufficient stack space.
15169 If there isn't variables or registers (or even the return address itself)
15176 \begin_inset LatexCommand index
15177 name "stack overflow"
15181 is most likely to happen if the interrupt occurs during the
15182 \begin_inset Quotes sld
15186 \begin_inset Quotes srd
15189 subroutine when the stack is already in use for f.e.
15190 many return addresses.
15193 \begin_layout Subsubsection
15194 \begin_inset LatexCommand label
15195 name "sub:Common-interrupt-pitfall-non-reentrant"
15199 Common interrupt pitfall:
15201 use of non-reentrant functions
15204 \begin_layout Standard
15205 A special note here, int (16 bit) and long (32 bit) integer division
15206 \begin_inset LatexCommand index
15212 \begin_inset LatexCommand index
15213 name "Multiplication"
15218 \begin_inset LatexCommand index
15224 \begin_inset LatexCommand index
15225 name "Floating point support"
15229 operations are implemented using external support routines.
15230 If an interrupt service routine needs to do any of these operations then
15231 the support routines (as mentioned in a following section) will have to
15232 be recompiled using the
15238 \begin_layout Standard
15248 \begin_inset LatexCommand index
15249 name "-\\/-stack-auto"
15255 option and the source file will need to be compiled using the
15261 \begin_layout Standard
15273 \begin_inset LatexCommand index
15274 name "-\\/-int-long-reent"
15281 Note, the type promotion
15282 \begin_inset LatexCommand index
15283 name "type promotion"
15287 required by ANSI C can cause 16 bit routines to be used
15288 \begin_inset Marginal
15291 \begin_layout Standard
15300 without the programmer being aware of it.
15305 (unsigned char)(tail-1)
15310 within the if clause in section
15311 \begin_inset LatexCommand ref
15312 reference "sub:A-Step-by Assembler Introduction"
15319 \begin_layout Standard
15320 Calling other functions from an interrupt service routine is not recommended,
15321 avoid it if possible.
15322 Note that when some function is called from an interrupt service routine
15323 it should be preceded by a #pragma\InsetSpace ~
15325 \begin_inset LatexCommand index
15326 name "\\#pragma nooverlay"
15330 if it is not reentrant.
15331 Furthermore nonreentrant functions should not be called from the main program
15332 while the interrupt service routine might be active.
15333 They also must not be called from low priority interrupt service routines
15334 while a high priority interrupt service routine might be active.
15335 You could use semaphores or make the function
15339 if all parameters are passed in registers.
15342 \begin_inset LatexCommand ref
15343 reference "sub:Overlaying"
15348 about Overlaying and section
15349 \begin_inset LatexCommand ref
15350 reference "sub:Functions-using-private-banks"
15355 about Functions using private register banks.
15356 \begin_inset VSpace bigskip
15362 \begin_layout Subsection
15363 MCS51/DS390 Interrupt Service Routines
15366 \begin_layout Standard
15368 \begin_inset LatexCommand index
15373 numbers and the corresponding address & descriptions for the Standard 8051/8052
15375 SDCC will automatically adjust the
15376 \begin_inset LatexCommand index
15377 name "interrupt vector table"
15381 to the maximum interrupt number specified.
15386 \begin_layout Standard
15388 \begin_inset Tabular
15389 <lyxtabular version="3" rows="9" columns="3">
15391 <column alignment="center" valignment="top" leftline="true" width="0in">
15392 <column alignment="left" valignment="top" leftline="true" width="0in">
15393 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15394 <row topline="true" bottomline="true">
15395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15398 \begin_layout Standard
15404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15407 \begin_layout Standard
15413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15416 \begin_layout Standard
15423 <row topline="true">
15424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15427 \begin_layout Standard
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15436 \begin_layout Standard
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15445 \begin_layout Standard
15452 <row topline="true">
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15456 \begin_layout Standard
15462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15465 \begin_layout Standard
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15474 \begin_layout Standard
15481 <row topline="true">
15482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15485 \begin_layout Standard
15491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15494 \begin_layout Standard
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15503 \begin_layout Standard
15510 <row topline="true">
15511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15514 \begin_layout Standard
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15523 \begin_layout Standard
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15532 \begin_layout Standard
15539 <row topline="true">
15540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15543 \begin_layout Standard
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15552 \begin_layout Standard
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15561 \begin_layout Standard
15568 <row topline="true">
15569 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15572 \begin_layout Standard
15578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15581 \begin_layout Standard
15587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15590 \begin_layout Standard
15597 <row topline="true">
15598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15601 \begin_layout Standard
15607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15610 \begin_layout Standard
15616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15619 \begin_layout Standard
15626 <row topline="true" bottomline="true">
15627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15630 \begin_layout Standard
15636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15639 \begin_layout Standard
15645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15648 \begin_layout Standard
15664 \begin_layout Standard
15665 If the interrupt service routine is defined without
15668 \begin_inset LatexCommand index
15669 name "using (mcs51, ds390 register bank)"
15674 \begin_inset LatexCommand index
15675 name "\\_\\_using (mcs51, ds390 register bank)"
15681 a register bank or with register bank 0 (
15685 0), the compiler will save the registers used by itself on the stack upon
15686 entry and restore them at exit, however if such an interrupt service routine
15687 calls another function then the entire register bank will be saved on the
15689 This scheme may be advantageous for small interrupt service routines which
15690 have low register usage.
15693 \begin_layout Standard
15694 If the interrupt service routine is defined to be using a specific register
15699 & psw are saved and restored, if such an interrupt service routine calls
15700 another function (using another register bank) then the entire register
15701 bank of the called function will be saved on the stack
15702 \begin_inset LatexCommand index
15708 This scheme is recommended for larger interrupt service routines.
15709 \begin_inset VSpace bigskip
15715 \begin_layout Subsection
15717 \begin_inset LatexCommand index
15722 Interrupt Service Routines
15725 \begin_layout Standard
15726 Since the number of interrupts
15727 \begin_inset LatexCommand index
15728 name "HC08!interrupt"
15732 available is chip specific and the interrupt vector table always ends at
15733 the last byte of memory, the interrupt numbers corresponds to the interrupt
15734 vectors in reverse order of address.
15735 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15736 2 will use the interrupt vector at 0xfffa, and so on.
15737 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15738 this way; instead see section
15739 \begin_inset LatexCommand ref
15740 reference "sub:Startup-Code"
15744 for details on customizing startup.
15745 \begin_inset VSpace bigskip
15751 \begin_layout Subsection
15752 Z80 Interrupt Service Routines
15755 \begin_layout Standard
15757 \begin_inset LatexCommand index
15762 uses several different methods for determining the correct interrupt
15763 \begin_inset LatexCommand index
15764 name "Z80!interrupt"
15768 vector depending on the hardware implementation.
15769 Therefore, SDCC ignores the optional interrupt number and does not attempt
15770 to generate an interrupt vector table.
15773 \begin_layout Standard
15774 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15775 instruction to return from the interrupt.
15776 To write an interrupt handler for the non-maskable interrupt, which needs
15777 a RETN instruction instead, add the
15784 \begin_layout Verse
15787 void nmi_isr (void) critical interrupt
15801 \begin_layout Standard
15802 However if you need to create a non-interruptable interrupt service routine
15803 you would also require the
15808 To distinguish between this and an nmi_isr you must provide an interrupt
15810 \begin_inset VSpace bigskip
15816 \begin_layout Section
15817 Enabling and Disabling Interrupts
15820 \begin_layout Subsection
15821 Critical Functions and Critical Statements
15824 \begin_layout Standard
15825 A special keyword may be associated with a block or a function declaring
15831 SDCC will generate code to disable all interrupts
15832 \begin_inset LatexCommand index
15837 upon entry to a critical function and restore the interrupt enable to the
15838 previous state before returning.
15839 Nesting critical functions will need one additional byte on the stack
15840 \begin_inset LatexCommand index
15848 \begin_layout Verse
15851 int foo () __critical
15852 \begin_inset LatexCommand index
15858 \begin_inset LatexCommand index
15859 name "\\_\\_critical"
15884 \begin_layout Standard
15885 The critical attribute maybe used with other attributes like
15895 may also be used to disable interrupts more locally:
15898 \begin_layout Verse
15904 \begin_layout Standard
15905 More than one statement could have been included in the block.
15908 \begin_layout Subsection
15909 Enabling and Disabling Interrupts directly
15912 \begin_layout Standard
15914 \begin_inset LatexCommand index
15919 can also be disabled and enabled directly (8051):
15922 \begin_layout Verse
15925 EA = 0;\InsetSpace ~
15951 \begin_layout Verse
15987 \begin_layout Verse
15990 EA = 1;\InsetSpace ~
16019 \begin_layout Verse
16058 \begin_layout Standard
16059 On other architectures which have separate opcodes for enabling and disabling
16060 interrupts you might want to make use of defines with inline assembly
16061 \begin_inset LatexCommand index
16062 name "Assembler routines"
16067 \begin_inset LatexCommand index
16068 name "HC08!interrupt"
16075 \begin_layout Verse
16079 \begin_inset LatexCommand index
16089 \begin_inset LatexCommand index
16097 \begin_layout Verse
16100 #define SEI _asm\InsetSpace ~
16107 \begin_layout Verse
16113 \begin_layout Standard
16114 Note: it is sometimes sufficient to disable only a specific interrupt source
16116 a timer or serial interrupt by manipulating an
16119 \begin_inset LatexCommand index
16120 name "interrupt mask"
16130 \begin_layout Standard
16131 Usually the time during which interrupts are disabled should be kept as
16133 This minimizes both
16138 \begin_inset LatexCommand index
16139 name "interrupt latency"
16143 (the time between the occurrence of the interrupt and the execution of
16144 the first code in the interrupt routine) and
16149 \begin_inset LatexCommand index
16150 name "interrupt jitter"
16154 (the difference between the shortest and the longest interrupt latency).
16155 These really are something different, f.e.
16156 a serial interrupt has to be served before its buffer overruns so it cares
16157 for the maximum interrupt latency, whereas it does not care about jitter.
16158 On a loudspeaker driven via a digital to analog converter which is fed
16159 by an interrupt a latency of a few milliseconds might be tolerable, whereas
16160 a much smaller jitter will be very audible.
16163 \begin_layout Standard
16164 You can reenable interrupts within an interrupt routine and on some architecture
16165 s you can make use of two (or more) levels of
16167 interrupt priorities
16170 \begin_inset LatexCommand index
16171 name "interrupt priority"
16176 On some architectures which don't support interrupt priorities these can
16177 be implemented by manipulating the interrupt mask and reenabling interrupts
16178 within the interrupt routine.
16179 Check there is sufficient space on the stack
16180 \begin_inset LatexCommand index
16185 and don't add complexity unless you have to.
16189 \begin_layout Subsection
16191 \begin_inset LatexCommand index
16196 locking (mcs51/ds390)
16199 \begin_layout Standard
16200 Some architectures (mcs51/ds390) have an atomic
16201 \begin_inset LatexCommand index
16206 bit test and clear instruction.
16207 These type of instructions are typically used in preemptive multitasking
16208 systems, where a routine f.e.
16209 claims the use of a data structure ('acquires a lock
16210 \begin_inset LatexCommand index
16215 on it'), makes some modifications and then releases the lock when the data
16216 structure is consistent again.
16217 The instruction may also be used if interrupt and non-interrupt code have
16218 to compete for a resource.
16219 With the atomic bit test and clear instruction interrupts
16220 \begin_inset LatexCommand index
16225 don't have to be disabled for the locking operation.
16229 \begin_layout Standard
16230 SDCC generates this instruction if the source follows this pattern:
16233 \begin_layout Verse
16237 \begin_inset LatexCommand index
16242 bit resource_is_free;
16246 if (resource_is_free)
16256 resource_is_free=0;
16269 resource_is_free=1;
16276 \begin_layout Standard
16277 Note, mcs51 and ds390 support only an atomic
16278 \begin_inset LatexCommand index
16287 instruction (as opposed to atomic bit test and
16292 \begin_layout Section
16293 Functions using private register banks
16294 \begin_inset LatexCommand label
16295 name "sub:Functions-using-private-banks"
16302 \begin_layout Standard
16303 Some architectures have support for quickly changing register sets.
16304 SDCC supports this feature with the
16307 \begin_inset LatexCommand index
16308 name "using (mcs51, ds390 register bank)"
16313 \begin_inset LatexCommand index
16314 name "\\_\\_using (mcs51, ds390 register bank)"
16320 attribute (which tells the compiler to use a register bank
16321 \begin_inset LatexCommand index
16322 name "register bank (mcs51, ds390)"
16326 other than the default bank zero).
16327 It should only be applied to
16330 \begin_inset LatexCommand index
16337 functions (see footnote below).
16338 This will in most circumstances make the generated ISR code more efficient
16339 since it will not have to save registers on the stack.
16342 \begin_layout Standard
16347 attribute will have no effect on the generated code for a
16351 function (but may occasionally be useful anyway
16355 \begin_layout Standard
16356 possible exception: if a function is called ONLY from 'interrupt' functions
16357 using a particular bank, it can be declared with the same 'using' attribute
16358 as the calling 'interrupt' functions.
16359 For instance, if you have several ISRs using bank one, and all of them
16360 call memcpy(), it might make sense to create a specialized version of memcpy()
16361 'using 1', since this would prevent the ISR from having to save bank zero
16362 to the stack on entry and switch to bank zero before calling the function
16371 (pending: Note, nowadays the
16375 attribute has an effect on
16379 the generated code for a
16390 \begin_layout Standard
16395 function using a non-zero bank will assume that it can trash that register
16396 bank, and will not save it.
16397 Since high-priority interrupts
16398 \begin_inset LatexCommand index
16404 \begin_inset LatexCommand index
16405 name "interrupt priority"
16409 can interrupt low-priority ones on the 8051 and friends, this means that
16410 if a high-priority ISR
16414 a particular bank occurs while processing a low-priority ISR
16418 the same bank, terrible and bad things can happen.
16419 To prevent this, no single register bank should be
16423 by both a high priority and a low priority ISR.
16424 This is probably most easily done by having all high priority ISRs use
16425 one bank and all low priority ISRs use another.
16426 If you have an ISR which can change priority at runtime, you're on your
16427 own: I suggest using the default bank zero and taking the small performance
16431 \begin_layout Standard
16432 It is most efficient if your ISR calls no other functions.
16433 If your ISR must call other functions, it is most efficient if those functions
16434 use the same bank as the ISR (see note 1 below); the next best is if the
16435 called functions use bank zero.
16436 It is very inefficient to call a function using a different, non-zero bank
16439 \begin_inset VSpace bigskip
16445 \begin_layout Section
16447 \begin_inset LatexCommand label
16448 name "sub:Startup-Code"
16453 \begin_inset LatexCommand index
16454 name "Startup code"
16461 \begin_layout Subsection
16462 MCS51/DS390 Startup Code
16465 \begin_layout Standard
16466 The compiler triggers the linker to link certain initialization modules
16467 from the runtime library
16468 \begin_inset LatexCommand index
16469 name "Runtime library"
16473 called crt<something>.
16474 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16475 GSINIT5) is not linked unless the -
16481 \begin_layout Standard
16492 -xstack option is used.
16493 These modules are highly entangled by the use of special segments/areas,
16494 but a common layout is shown below:
16497 \begin_layout Verse
16505 \begin_layout Verse
16529 ljmp __sdcc_gsinit_startup
16532 \begin_layout Verse
16540 \begin_layout Verse
16552 .area GSINIT0 (CODE)
16554 __sdcc_gsinit_startup::
16564 mov sp,#__start__stack - 1
16567 \begin_layout Verse
16575 \begin_layout Verse
16587 .area GSINIT1 (CODE)
16589 __sdcc_init_xstack::
16591 ; Need to initialize in GSINIT1 in
16592 case the user's __sdcc_external_startup uses the xstack.
16602 mov __XPAGE,#(__start__x
16613 mov _spx,#__start__xstack
16616 \begin_layout Verse
16624 \begin_layout Verse
16636 .area GSINIT2 (CODE)
16646 lcall __sdcc_external_startup
16666 jz __sdcc_init_data
16677 __sdcc_program_startup
16682 \begin_layout Verse
16690 \begin_layout Verse
16702 .area GSINIT3 (CODE)
16755 mov r2,#((l_XINIT+255) >> 8)
16786 __XPAGE,#(s_XISEG >> 8)
16788 00001$:\InsetSpace ~
16852 00002$:\InsetSpace ~
16879 \begin_layout Verse
16887 \begin_layout Verse
16899 .area GSINIT4 (CODE)
16901 __mcs51_genRAMCLEAR::
16923 00004$:\InsetSpace ~
16937 ; _mcs51_genRAMCLEAR() end
16940 \begin_layout Verse
16948 \begin_layout Verse
16960 .area GSINIT4 (CODE)
16962 __mcs51_genXRAMCLEAR::
17023 mov __XPAGE,#(s_PSEG >> 8)
17035 00005$:\InsetSpace ~
17110 mov r1,#((l_XSEG + 255) >> 8)
17132 00007$:\InsetSpace ~
17169 \begin_layout Verse
17177 \begin_layout Verse
17189 .area GSINIT5 (CODE)
17191 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17194 ; and __mcs51_genRAMCLEAR modifies _spx.
17204 mov __XPAGE,#(__start__x
17215 mov _spx,#__start__xstack
17218 \begin_layout Verse
17223 (application modules)
17226 \begin_layout Verse
17238 .area GSINIT (CODE)
17241 \begin_layout Verse
17249 \begin_layout Verse
17261 .area GSFINAL (CODE)
17271 ljmp __sdcc_program_startup
17273 ;---------------------------------
17274 -----------------------
17278 ;--------------------------------------------------
17301 __sdcc_program_startup:
17314 return from main will lock up
17327 \begin_layout Standard
17328 One of these modules (crtstart.asm) contains a call to the C routine
17330 _sdcc_external_startup()
17331 \begin_inset LatexCommand index
17332 name "\\_sdcc\\_external\\_startup()"
17338 at the start of the CODE area.
17339 This routine is also in the runtime library
17340 \begin_inset LatexCommand index
17341 name "Runtime library"
17345 and returns 0 by default.
17346 If this routine returns a non-zero value, the static & global variable
17347 initialization will be skipped and the function main will be invoked.
17348 Otherwise static & global variables will be initialized before the function
17352 _sdcc_external_startup()
17354 routine to your program to override the default if you need to setup hardware
17355 or perform some other critical operation prior to static & global variable
17357 \begin_inset LatexCommand index
17358 name "Variable initialization"
17363 On some mcs51 variants xdata
17364 \begin_inset LatexCommand index
17365 name "xdata (mcs51, ds390 storage class)"
17369 memory has to be explicitly enabled before it can be accessed or if the
17371 \begin_inset LatexCommand index
17376 needs to be disabled, this is the place to do it.
17377 The startup code clears all internal data memory, 256 bytes by default,
17378 but from 0 to n-1 if
17384 \begin_layout Standard
17394 \begin_inset LatexCommand index
17395 name "-\\/-iram-size <Value>"
17402 (recommended for Chipcon CC1010).
17405 \begin_layout Standard
17406 See also the compiler options
17412 \begin_layout Standard
17428 \begin_inset LatexCommand index
17429 name "-\\/-no-xinit-opt"
17439 \begin_layout Standard
17451 \begin_inset LatexCommand index
17452 name "-\\/-main-return"
17457 \begin_inset LatexCommand ref
17458 reference "sub:MCS51-variants"
17462 about MCS51-variants.
17467 \begin_layout Standard
17468 While these initialization modules are meant as generic startup code there
17469 might be the need for customization.
17470 Let's assume the return value of
17472 _sdcc_external_startup()
17478 should not be checked (or
17480 _sdcc_external_startup()
17482 should not be called at all).
17483 The recommended way would be to copy
17489 \begin_inset LatexCommand url
17490 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17494 ) into the source directory, adapt it there, then assemble it with
17500 \begin_layout Standard
17501 \begin_inset Quotes sld
17505 \begin_inset Quotes srd
17508 are the assembler options used in
17509 \begin_inset LatexCommand url
17510 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17521 and when linking your project explicitly specify
17526 As a bonus a listing of the relocated object file
17533 \begin_layout Standard
17534 \begin_inset VSpace bigskip
17540 \begin_layout Subsection
17544 \begin_layout Standard
17546 \begin_inset LatexCommand index
17551 startup code follows the same scheme as the MCS51 startup code.
17552 \begin_inset VSpace bigskip
17558 \begin_layout Subsection
17562 \begin_layout Standard
17564 \begin_inset LatexCommand index
17569 the startup code is inserted by linking with crt0.o which is generated from
17570 sdcc/device/lib/z80/crt0.s.
17571 If you need a different startup code you can use the compiler option
17580 \begin_layout Standard
17595 \begin_inset LatexCommand index
17596 name "-\\/-no-std-crt0"
17600 and provide your own crt0.o.
17602 \begin_inset VSpace bigskip
17608 \begin_layout Section
17609 Inline Assembler Code
17610 \begin_inset LatexCommand index
17611 name "Assembler routines"
17618 \begin_layout Subsection
17619 A Step by Step Introduction
17620 \begin_inset LatexCommand label
17621 name "sub:A-Step-by Assembler Introduction"
17628 \begin_layout Standard
17629 Starting from a small snippet of c-code this example shows for the MCS51
17630 how to use inline assembly, access variables, a function parameter and
17631 an array in xdata memory.
17632 The example uses an MCS51 here but is easily adapted for other architectures.
17633 This is a buffer routine which should be optimized:
17636 \begin_layout Verse
17640 unsigned char __far
17641 \begin_inset LatexCommand index
17642 name "far (storage class)"
17647 \begin_inset LatexCommand index
17648 name "\\_\\_far (storage class)"
17653 \begin_inset LatexCommand index
17659 \begin_inset LatexCommand index
17664 (0x7f00) buf[0x100];
17665 \begin_inset LatexCommand index
17666 name "Aligned array"
17672 unsigned char head, tail;\InsetSpace ~
17690 \begin_inset LatexCommand index
17743 \begin_inset LatexCommand ref
17744 reference "sub:Common-interrupt-pitfall-volatile"
17762 void to_buffer( unsigned char c )
17770 if( head != (unsigned char)(tail-1)
17783 \begin_inset LatexCommand index
17784 name "promotion to signed int"
17789 \begin_inset LatexCommand index
17790 name "type promotion"
17795 \begin_inset Marginal
17798 \begin_layout Standard
17817 buf[ head++ ] = c;\InsetSpace ~
17833 /* access to a 256 byte aligned array */
17838 \begin_layout Standard
17839 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17840 then a corresponding buffer.asm file is generated.
17841 We define a new function
17845 in file buffer.c in which we cut and paste the generated code, removing
17846 unwanted comments and some ':'.
17848 \begin_inset Quotes sld
17856 \begin_inset Quotes srd
17860 \begin_inset Quotes sld
17868 \begin_inset Quotes srd
17875 \begin_layout Standard
17876 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17877 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17879 The latter is also used in the library functions.
17884 to the beginning and the end of the function body:
17887 \begin_layout Verse
17891 /* With a cut and paste from the .asm file, we have something to start with.
17897 function is not yet OK! (registers aren't saved) */
17899 void to_buffer_asm(
17909 \begin_inset LatexCommand index
17915 \begin_inset LatexCommand index
17930 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17942 \begin_inset LatexCommand index
17943 name "promotion to signed int"
17948 \begin_inset LatexCommand index
17949 name "type promotion"
18002 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
18003 \begin_inset LatexCommand index
18004 name "Aligned array"
18070 \begin_inset LatexCommand index
18076 \begin_inset LatexCommand index
18077 name "\\_\\_endasm"
18086 \begin_layout Standard
18087 The new file buffer.c should compile with only one warning about the unreferenced
18088 function argument 'c'.
18089 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18090 (1) and finally have:
18093 \begin_layout Verse
18097 unsigned char __far __at(0x7f00) buf[0x100];
18099 unsigned char head, tail;
18110 void to_buffer( unsigned char c )
18119 head != (unsigned char)(tail-1) )
18148 c; // to avoid warning: unreferenced function argument
18155 \begin_inset LatexCommand index
18161 \begin_inset LatexCommand index
18176 ; save used registers here.
18187 ; If we were still using r2,r3 we would have to push them here.
18190 ; if( head != (unsigned char)(tail-1) )
18234 could do an ANL a,#0x0f here to use a smaller buffer (see below)
18270 a,dpl \InsetSpace ~
18277 ; dpl holds lower byte of function argument
18289 dpl,_head \InsetSpace ~
18292 ; buf is 0x100 byte aligned so head can be used directly
18335 ; we could do an ANL _head,#0x0f here to use a
18336 smaller buffer (see above)
18348 ; restore used registers here
18355 \begin_inset LatexCommand index
18361 \begin_inset LatexCommand index
18362 name "\\_\\_endasm"
18373 \begin_layout Standard
18374 The inline assembler code can contain any valid code understood by the assembler
18375 , this includes any assembler directives and comment lines.
18376 The assembler does not like some characters like ':' or ''' in comments.
18377 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18378 \begin_inset LatexCommand index
18379 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18384 \begin_inset LatexCommand index
18385 name "Assembler documentation"
18390 \begin_inset LatexCommand url
18391 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18399 \begin_layout Standard
18400 The compiler does not do any validation of the code within the
18403 \begin_inset LatexCommand index
18409 \begin_inset LatexCommand index
18418 \begin_inset LatexCommand index
18424 \begin_inset LatexCommand index
18425 name "\\_\\_endasm"
18434 Specifically it will not know which registers are used and thus register
18436 \begin_inset LatexCommand index
18441 has to be done manually.
18445 \begin_layout Standard
18446 It is recommended that each assembly instruction (including labels) be placed
18447 in a separate line (as the example shows).
18452 \begin_layout Standard
18464 \begin_inset LatexCommand index
18465 name "-\\/-peep-asm"
18471 command line option is used, the inline assembler code will be passed through
18472 the peephole optimizer
18473 \begin_inset LatexCommand index
18474 name "Peephole optimizer"
18479 There are only a few (if any) cases where this option makes sense, it might
18480 cause some unexpected changes in the inline assembler code.
18481 Please go through the peephole optimizer rules defined in file
18485 before using this option.
18488 \begin_layout Subsection
18490 \begin_inset LatexCommand label
18491 name "sub:Naked-Functions"
18496 \begin_inset LatexCommand index
18497 name "Naked functions"
18504 \begin_layout Standard
18505 A special keyword may be associated with a function declaring it as
18508 \begin_inset LatexCommand index
18514 \begin_inset LatexCommand index
18526 function modifier attribute prevents the compiler from generating prologue
18527 \begin_inset LatexCommand index
18528 name "function prologue"
18533 \begin_inset LatexCommand index
18534 name "function epilogue"
18538 code for that function.
18539 This means that the user is entirely responsible for such things as saving
18540 any registers that may need to be preserved, selecting the proper register
18541 bank, generating the
18545 instruction at the end, etc.
18546 Practically, this means that the contents of the function must be written
18547 in inline assembler.
18548 This is particularly useful for interrupt functions, which can have a large
18549 (and often unnecessary) prologue/epilogue.
18550 For example, compare the code generated by these two functions:
18553 \begin_layout Verse
18557 \begin_inset LatexCommand index
18562 data unsigned char counter;
18566 void simpleInterrupt(void) __interrupt
18567 \begin_inset LatexCommand index
18573 \begin_inset LatexCommand index
18574 name "\\_\\_interrupt"
18592 void nakedInterrupt(void) __interrupt (2) __naked
18601 \begin_inset LatexCommand index
18607 \begin_inset LatexCommand index
18625 _counter ; does not change flags, no need to save psw
18638 include ret or reti in _naked function.
18645 \begin_inset LatexCommand index
18651 \begin_inset LatexCommand index
18652 name "\\_\\_endasm"
18661 \begin_layout Standard
18662 For an 8051 target, the generated simpleInterrupt looks like:
18665 \begin_layout Verse
18678 example, recent versions of SDCC generate
18690 code for simpleInterrupt() and nakedInterrupt()!
18831 \begin_layout Standard
18832 whereas nakedInterrupt looks like:
18835 \begin_layout Verse
18848 _counter ; does not change flags, no need to save psw
18867 MUST explicitly include ret or reti in _naked function
18870 \begin_layout Standard
18871 The related directive #pragma exclude
18872 \begin_inset LatexCommand index
18873 name "\\#pragma exclude"
18877 allows a more fine grained control over pushing & popping
18878 \begin_inset LatexCommand index
18886 \begin_layout Standard
18887 While there is nothing preventing you from writing C code inside a
18891 function, there are many ways to shoot yourself in the foot doing this,
18892 and it is recommended that you stick to inline assembler.
18895 \begin_layout Subsection
18896 Use of Labels within Inline Assembler
18899 \begin_layout Standard
18900 SDCC allows the use of in-line assembler with a few restrictions regarding
18902 All labels defined within inline assembler code have to be of the form
18907 where nnnnn is a number less than 100 (which implies a limit of utmost
18908 100 inline assembler labels
18919 \begin_layout Standard
18920 This is a slightly more stringent rule than absolutely necessary, but stays
18921 always on the safe side.
18922 Labels in the form of nnnnn$ are local labels in the assembler, locality
18923 of which is confined within two labels of the standard form.
18924 The compiler uses the same form for labels within a function (but starting
18925 from nnnnn=00100); and places always a standard label at the beginning
18926 of a function, thus limiting the locality of labels within the scope of
18928 So, if the inline assembler part would be embedded into C-code, an improperly
18929 placed non-local label in the assembler would break up the reference space
18930 for labels created by the compiler for the C-code, leading to an assembling
18934 \begin_layout Standard
18935 The numeric part of local labels does not need to have 5 digits (although
18936 this is the form of labels output by the compiler), any valid integer will
18938 Please refer to the assemblers documentation for further details.
18946 \begin_layout Verse
18950 \begin_inset LatexCommand index
18956 \begin_inset LatexCommand index
18987 \begin_inset LatexCommand index
18993 \begin_inset LatexCommand index
18994 name "\\_\\_endasm"
19001 \begin_layout Standard
19002 Inline assembler code cannot reference any C-labels, however it can reference
19004 \begin_inset LatexCommand index
19009 defined by the inline assembler, e.g.:
19012 \begin_layout Verse
19035 ; some assembler code
19056 /* some more c code */
19058 clabel:\InsetSpace ~
19060 /* inline assembler cannot reference this
19065 \begin_layout Standard
19070 is translated by the compiler into a local label, so the locality of labels
19071 within the function is not broken.
19088 0003$: ;label (can be referenced by inline assembler only)
19095 \begin_inset LatexCommand index
19101 \begin_inset LatexCommand index
19102 name "\\_\\_endasm"
19112 /* some more c code */
19117 \begin_layout Standard
19118 In other words inline assembly code can access labels defined in inline
19119 assembly within the scope of the function.
19120 The same goes the other way, i.e.
19121 labels defines in inline assembly can not be accessed by C statements.
19124 \begin_layout Section
19125 Interfacing with Assembler Code
19126 \begin_inset LatexCommand index
19127 name "Assembler routines"
19134 \begin_layout Subsection
19135 Global Registers used for Parameter Passing
19136 \begin_inset LatexCommand index
19137 name "Parameter passing"
19144 \begin_layout Standard
19145 The compiler always uses the global registers
19148 \begin_inset LatexCommand index
19149 name "DPTR, DPH, DPL"
19154 \begin_inset LatexCommand index
19160 \begin_inset LatexCommand index
19161 name "B (mcs51, ds390 register)"
19170 \begin_inset LatexCommand index
19171 name "ACC (mcs51, ds390 register)"
19177 to pass the first (non-bit) parameter to a function, and also to pass the
19179 \begin_inset LatexCommand index
19180 name "return value"
19184 of function; according to the following scheme: one byte return value in
19189 , two byte value in
19198 three byte values (generic pointers) in
19210 , and four byte values in
19228 \begin_inset LatexCommand index
19229 name "generic pointer"
19233 contain type of accessed memory in
19254 \begin_inset Note Note
19257 \begin_layout Standard
19258 This might not be the case of certain memory models (medium???)
19266 \begin_layout Standard
19267 The second parameter onwards is either allocated on the stack (for reentrant
19272 \begin_layout Standard
19281 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19284 \begin_layout Standard
19285 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19286 space for reentrant functions or allocated directly in bit memory otherwise.
19289 \begin_layout Standard
19290 Functions (with two or more parameters or bit parameters) that are called
19291 through function pointers
19292 \begin_inset LatexCommand index
19293 name "function pointers"
19297 must therefor be reentrant so the compiler knows how to pass the parameters.
19300 \begin_layout Subsection
19304 \begin_layout Standard
19305 Unless the called function is declared as
19310 \begin_inset LatexCommand index
19319 \begin_layout Standard
19329 \begin_inset LatexCommand index
19330 name "-\\/-callee-saves"
19338 \begin_layout Standard
19347 -all-callee-saves command line option or the corresponding callee_saves
19348 pragma are used, the caller will save the registers (
19352 ) around the call, so the called function can destroy they content freely.
19355 \begin_layout Standard
19356 If the called function is not declared as
19360 , the caller will swap register banks around the call, if caller and callee
19361 use different register banks (having them defined by the
19369 \begin_layout Standard
19370 The called function can also use
19386 observing that they are used for parameter/return value passing.
19389 \begin_layout Subsection
19390 Assembler Routine (non-reentrant)
19393 \begin_layout Standard
19394 In the following example
19395 \begin_inset LatexCommand index
19401 \begin_inset LatexCommand index
19402 name "Assembler routines (non-reentrant)"
19406 the function c_func calls an assembler routine asm_func, which takes two
19408 \begin_inset LatexCommand index
19409 name "function parameter"
19416 \begin_layout Verse
19419 extern int asm_func(unsigned char, unsigned char);
19423 int c_func (unsigned char
19424 i, unsigned char j)
19432 return asm_func(i,j);
19446 return c_func(10,9);
19451 \begin_layout Standard
19452 The corresponding assembler function is:
19455 \begin_layout Verse
19458 .globl _asm_func_PARM_2
19560 \begin_inset LatexCommand index
19561 name "DPTR, DPH, DPL"
19578 \begin_layout Standard
19579 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19580 the parameter number starting from 1, and counting from the left.
19581 The first parameter is passed in
19597 according to the description above.
19598 The variable name for the second parameter will be _<function_name>_PARM_2.
19603 ble the assembler routine with the following command:
19610 asx8051 -losg asmfunc.asm
19617 Then compile and link the assembler routine to the C source file with the
19625 sdcc cfunc.c asmfunc.rel
19628 \begin_layout Subsection
19629 Assembler Routine (reentrant)
19632 \begin_layout Standard
19634 \begin_inset LatexCommand index
19640 \begin_inset LatexCommand index
19641 name "Assembler routines (reentrant)"
19645 the second parameter
19646 \begin_inset LatexCommand index
19647 name "function parameter"
19651 onwards will be passed on the stack, the parameters are pushed from right
19653 before the call the second leftmost parameter will be on the top of the
19654 stack (the leftmost parameter is passed in registers).
19655 Here is an example:
19658 \begin_layout Verse
19661 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19666 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
19675 return asm_func(i,j,k);
19689 return c_func(10,9,8);
19694 \begin_layout Standard
19695 The corresponding (unoptimized) assembler routine is:
19698 \begin_layout Verse
19718 _bp,sp\InsetSpace ~
19724 ;stack contains: _bp, return
19725 address, second parameter, third parameter
19749 a,#0xfd\InsetSpace ~
19755 pointer to the second parameter
19779 a,#0xfc\InsetSpace ~
19785 to the rightmost parameter
19826 result (= sum of all three parameters)
19841 ;return value goes into dptr
19875 \begin_layout Standard
19876 The compiling and linking procedure remains the same, however note the extra
19877 entry & exit linkage required for the assembler code, _bp is the stack
19878 frame pointer and is used to compute the offset into the stack for parameters
19879 and local variables.
19880 \begin_inset VSpace bigskip
19886 \begin_layout Section
19888 \begin_inset LatexCommand index
19889 name "int (16 bit)"
19894 \begin_inset LatexCommand index
19895 name "long (32 bit)"
19902 \begin_layout Standard
19903 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19904 multiplication and modulus operations are implemented by support routines.
19905 These support routines are all developed in ANSI-C to facilitate porting
19906 to other MCUs, although some model specific assembler optimizations are
19908 The following files contain the described routines, all of them can be
19909 found in <installdir>/share/sdcc/lib.
19914 \begin_layout Standard
19916 \begin_inset Tabular
19917 <lyxtabular version="3" rows="11" columns="2">
19919 <column alignment="left" valignment="top" leftline="true" width="0">
19920 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19921 <row topline="true" bottomline="true">
19922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19925 \begin_layout Standard
19933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19936 \begin_layout Standard
19945 <row topline="true">
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_layout Standard
19955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19958 \begin_layout Standard
19959 16 bit multiplication
19965 <row topline="true">
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19969 \begin_layout Standard
19975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19978 \begin_layout Standard
19979 signed 16 bit division (calls _divuint)
19985 <row topline="true">
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_layout Standard
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19998 \begin_layout Standard
19999 unsigned 16 bit division
20005 <row topline="true">
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_layout Standard
20015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20018 \begin_layout Standard
20019 signed 16 bit modulus (calls _moduint)
20025 <row topline="true">
20026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20029 \begin_layout Standard
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20038 \begin_layout Standard
20039 unsigned 16 bit modulus
20045 <row topline="true">
20046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20049 \begin_layout Standard
20055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20058 \begin_layout Standard
20059 32 bit multiplication
20065 <row topline="true">
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20069 \begin_layout Standard
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20078 \begin_layout Standard
20079 signed 32 division (calls _divulong)
20085 <row topline="true">
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20089 \begin_layout Standard
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20098 \begin_layout Standard
20099 unsigned 32 division
20105 <row topline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_layout Standard
20115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20118 \begin_layout Standard
20119 signed 32 bit modulus (calls _modulong)
20125 <row topline="true" bottomline="true">
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20129 \begin_layout Standard
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20138 \begin_layout Standard
20139 unsigned 32 bit modulus
20154 \begin_layout Standard
20155 Since they are compiled as
20160 \begin_inset LatexCommand index
20166 \begin_inset LatexCommand index
20171 service routines should not do any of the above operations.
20172 If this is unavoidable then the above routines will need to be compiled
20179 \begin_layout Standard
20189 \begin_inset LatexCommand index
20190 name "-\\/-stack-auto"
20196 option, after which the source program will have to be compiled with
20202 \begin_layout Standard
20212 \begin_inset LatexCommand index
20213 name "-\\/-int-long-reent"
20220 Notice that you don't have to call these routines directly.
20221 The compiler will use them automatically every time an integer operation
20225 \begin_layout Section
20226 Floating Point Support
20227 \begin_inset LatexCommand index
20228 name "Floating point support"
20235 \begin_layout Standard
20236 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20237 The floating point support routines are derived from gcc's floatlib.c and
20238 consist of the following routines:
20243 \begin_layout Standard
20247 \begin_inset Tabular
20248 <lyxtabular version="3" rows="17" columns="2">
20250 <column alignment="left" valignment="top" leftline="true" width="0">
20251 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20252 <row topline="true" bottomline="true">
20253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20256 \begin_layout Standard
20271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20274 \begin_layout Standard
20281 <row topline="true">
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20285 \begin_layout Standard
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20303 \begin_layout Standard
20313 add floating point numbers
20319 <row topline="true">
20320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20323 \begin_layout Standard
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20341 \begin_layout Standard
20351 subtract floating point numbers
20357 <row topline="true">
20358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20361 \begin_layout Standard
20376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20379 \begin_layout Standard
20389 divide floating point numbers
20395 <row topline="true">
20396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20399 \begin_layout Standard
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20417 \begin_layout Standard
20427 multiply floating point numbers
20433 <row topline="true">
20434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20437 \begin_layout Standard
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20455 \begin_layout Standard
20465 convert floating point to unsigned char
20471 <row topline="true">
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20475 \begin_layout Standard
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20493 \begin_layout Standard
20503 convert floating point to signed char
20509 <row topline="true">
20510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20513 \begin_layout Standard
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20531 \begin_layout Standard
20541 convert floating point to unsigned int
20547 <row topline="true">
20548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20551 \begin_layout Standard
20566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20569 \begin_layout Standard
20579 convert floating point to signed int
20585 <row topline="true">
20586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20589 \begin_layout Standard
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20615 \begin_layout Standard
20625 convert floating point to unsigned long
20631 <row topline="true">
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20635 \begin_layout Standard
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20653 \begin_layout Standard
20663 convert floating point to signed long
20669 <row topline="true">
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20673 \begin_layout Standard
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20691 \begin_layout Standard
20701 convert unsigned char to floating point
20707 <row topline="true">
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20711 \begin_layout Standard
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20729 \begin_layout Standard
20739 convert char to floating point number
20745 <row topline="true">
20746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20749 \begin_layout Standard
20764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20767 \begin_layout Standard
20777 convert unsigned int to floating point
20783 <row topline="true">
20784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20787 \begin_layout Standard
20802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20805 \begin_layout Standard
20815 convert int to floating point numbers
20821 <row topline="true">
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20825 \begin_layout Standard
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20843 \begin_layout Standard
20853 convert unsigned long to floating point number
20859 <row topline="true" bottomline="true">
20860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20863 \begin_layout Standard
20878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20881 \begin_layout Standard
20891 convert long to floating point number
20906 \begin_layout Standard
20907 These support routines are developed in ANSI-C so there is room for space
20908 and speed improvement
20912 \begin_layout Standard
20913 These floating point routines (
20917 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20924 Note if all these routines are used simultaneously the data space might
20926 For serious floating point usage the large model might be needed.
20927 Also notice that you don't have to call this routines directly.
20928 The compiler will use them automatically every time a floating point operation
20930 \begin_inset VSpace bigskip
20936 \begin_layout Section
20938 \begin_inset LatexCommand index
20946 \begin_layout Standard
20949 <pending: this is messy and incomplete - a little more information is in
20950 sdcc/doc/libdoc.txt
20955 \begin_layout Subsection
20956 Compiler support routines (_gptrget, _mulint etc.)
20959 \begin_layout Subsection
20960 Stdclib functions (puts, printf, strcat etc.)
20963 \begin_layout Subsubsection
20967 \begin_layout Paragraph
20968 getchar(), putchar()
20971 \begin_layout Standard
20972 \begin_inset LatexCommand index
20977 As usual on embedded systems you have to provide your own
20980 \begin_inset LatexCommand index
20990 \begin_inset LatexCommand index
20998 SDCC does not know whether the system connects to a serial line with or
20999 without handshake, LCD, keyboard or other device.
21013 You'll find examples for serial routines f.e.
21014 in sdcc/device/lib.
21015 For the mcs51 this minimalistic polling
21019 routine might be a start:
21022 \begin_layout Verse
21025 void putchar (char c) {
21031 while (!TI)\InsetSpace ~
21034 /* assumes UART is initialized */
21062 \begin_layout Paragraph
21066 \begin_layout Standard
21070 \begin_inset LatexCommand index
21081 does not support float (except on ds390).
21082 To enable this, recompile it with the option
21088 \begin_layout Standard
21098 \begin_inset LatexCommand index
21099 name "USE\\_FLOATS"
21105 on the command line.
21112 \begin_layout Standard
21122 \begin_inset LatexCommand index
21123 name "-\\/-model-large"
21129 for the mcs51 port, since this uses a lot of memory.
21130 To enable float support for the pic16 targets, see
21131 \begin_inset LatexCommand ref
21132 reference "sub:pic16Libraries"
21139 \begin_layout Standard
21140 If you're short on code memory you might want to use
21143 \begin_inset LatexCommand index
21144 name "printf\\_small()"
21159 For the mcs51 there additionally are assembly versions
21162 \begin_inset LatexCommand index
21163 name "printf\\_tiny() (mcs51)"
21169 (subset of printf using less than 270 bytes) and
21172 \begin_inset LatexCommand index
21173 name "printf\\_fast() (mcs51)"
21182 \begin_inset LatexCommand index
21183 name "printf\\_fast\\_f() (mcs51)"
21189 (floating-point aware version of printf_fast) which should fit the requirements
21190 of many embedded systems (printf_fast() can be customized by unsetting
21195 support long variables and field widths).
21196 Be sure to use only one of these printf options within a project.
21201 \begin_layout Standard
21202 Feature matrix of different
21209 \begin_layout Standard
21210 \begin_inset Tabular
21211 <lyxtabular version="3" rows="14" columns="7">
21212 <features islongtable="true">
21213 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21214 <column alignment="center" valignment="top" leftline="true" width="0">
21215 <column alignment="center" valignment="top" leftline="true" width="12col%">
21216 <column alignment="center" valignment="top" leftline="true" width="10col%">
21217 <column alignment="center" valignment="top" leftline="true" width="0">
21218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21219 <column alignment="center" valignment="top" rightline="true" width="0">
21220 <row topline="true" bottomline="true" endhead="true">
21221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21224 \begin_layout Standard
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21236 \begin_layout Standard
21238 \begin_inset LatexCommand index
21248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21251 \begin_layout Standard
21259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21262 \begin_layout Standard
21268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21271 \begin_layout Standard
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21280 \begin_layout Standard
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21289 \begin_layout Standard
21296 <row topline="true" endhead="true">
21297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21300 \begin_layout Standard
21306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21309 \begin_layout Standard
21317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21320 \begin_layout Standard
21328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21331 \begin_layout Standard
21339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21342 \begin_layout Standard
21350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21353 \begin_layout Standard
21361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21364 \begin_layout Standard
21373 <row topline="true" endhead="true">
21374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21377 \begin_layout Standard
21378 \begin_inset Quotes sld
21382 \begin_inset Quotes srd
21388 \begin_layout Standard
21394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21397 \begin_layout Standard
21403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21406 \begin_layout Standard
21412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21415 \begin_layout Standard
21421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21424 \begin_layout Standard
21430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21433 \begin_layout Standard
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21442 \begin_layout Standard
21449 <row topline="true" endhead="true">
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21453 \begin_layout Standard
21457 \begin_layout Standard
21463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21466 \begin_layout Standard
21472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21475 \begin_layout Standard
21481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21484 \begin_layout Standard
21485 0.45k / 0.47k (+ _ltoa)
21490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21493 \begin_layout Standard
21499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21502 \begin_layout Standard
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21511 \begin_layout Standard
21518 <row topline="true">
21519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21522 \begin_layout Standard
21528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21531 \begin_layout Standard
21541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21544 \begin_layout Standard
21591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21594 \begin_layout Standard
21633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21636 \begin_layout Standard
21642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21645 \begin_layout Standard
21651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21654 \begin_layout Standard
21661 <row topline="true">
21662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21665 \begin_layout Standard
21666 long (32 bit) support
21671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21674 \begin_layout Standard
21680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21683 \begin_layout Standard
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21692 \begin_layout Standard
21698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21701 \begin_layout Standard
21707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21710 \begin_layout Standard
21725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21728 \begin_layout Standard
21735 <row topline="true">
21736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21739 \begin_layout Standard
21740 byte arguments on stack
21745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21748 \begin_layout Standard
21754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21757 \begin_layout Standard
21763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21766 \begin_layout Standard
21772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21775 \begin_layout Standard
21781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21784 \begin_layout Standard
21790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21793 \begin_layout Standard
21800 <row topline="true">
21801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21804 \begin_layout Standard
21806 \begin_inset LatexCommand index
21807 name "Floating point support"
21816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21819 \begin_layout Standard
21825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21828 \begin_layout Standard
21834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21837 \begin_layout Standard
21843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21846 \begin_layout Standard
21852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21855 \begin_layout Standard
21860 \begin_layout Standard
21861 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21874 \begin_layout Standard
21881 <row topline="true">
21882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21885 \begin_layout Standard
21886 float formats %e %g
21891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21894 \begin_layout Standard
21900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21903 \begin_layout Standard
21909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21912 \begin_layout Standard
21918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21921 \begin_layout Standard
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21930 \begin_layout Standard
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21939 \begin_layout Standard
21946 <row topline="true" bottomline="true">
21947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21950 \begin_layout Standard
21956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21959 \begin_layout Standard
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21968 \begin_layout Standard
21974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21977 \begin_layout Standard
21983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21986 \begin_layout Standard
21992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21995 \begin_layout Standard
22001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22004 \begin_layout Standard
22011 <row bottomline="true">
22012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22015 \begin_layout Standard
22020 \begin_layout Standard
22021 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22025 n'); standard 8051 @ 22.1184 MHz, empty putchar()
22033 \begin_layout Standard
22039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22042 \begin_layout Standard
22048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22051 \begin_layout Standard
22057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22060 \begin_layout Standard
22066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22069 \begin_layout Standard
22075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22078 \begin_layout Standard
22084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22087 \begin_layout Standard
22094 <row bottomline="true">
22095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22098 \begin_layout Standard
22103 \begin_layout Standard
22104 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22113 \begin_layout Standard
22119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22122 \begin_layout Standard
22128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22131 \begin_layout Standard
22137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22140 \begin_layout Standard
22146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22149 \begin_layout Standard
22155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22158 \begin_layout Standard
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22167 \begin_layout Standard
22172 \begin_layout Standard
22173 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22184 <row bottomline="true">
22185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22188 \begin_layout Standard
22193 \begin_layout Standard
22194 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22203 \begin_layout Standard
22209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22212 \begin_layout Standard
22218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22221 \begin_layout Standard
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22230 \begin_layout Standard
22236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22239 \begin_layout Standard
22245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22248 \begin_layout Standard
22254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22257 \begin_layout Standard
22264 <row bottomline="true">
22265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22268 \begin_layout Standard
22273 \begin_layout Standard
22274 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22283 \begin_layout Standard
22289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22292 \begin_layout Standard
22298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22301 \begin_layout Standard
22307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22310 \begin_layout Standard
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22319 \begin_layout Standard
22325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22328 \begin_layout Standard
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22337 \begin_layout Standard
22351 \begin_layout Subsubsection
22353 \begin_inset LatexCommand index
22361 \begin_layout Standard
22362 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22363 using dynamic memory allocation
22364 \begin_inset LatexCommand index
22365 name "dynamic memory allocation (malloc)"
22370 \begin_inset LatexCommand index
22371 name "heap (malloc)"
22375 space of 1024 bytes is provided for malloc to allocate memory from.
22376 If you need a different heap size you need to recompile _heap.c with the
22377 required size defined in HEAP_SIZE.
22378 It is recommended to make a copy of this file into your project directory
22379 and compile it there with:
22382 \begin_layout Verse
22385 sdcc -c _heap.c -D HEAD_SIZE=2048
22388 \begin_layout Standard
22389 And then link it with:
22392 \begin_layout Verse
22395 sdcc main.rel _heap.rel
22398 \begin_layout Subsection
22399 Math functions (sinf, powf, sqrtf etc.)
22402 \begin_layout Subsubsection
22406 \begin_layout Standard
22407 See definitions in file <math.h>.
22410 \begin_layout Subsection
22414 \begin_layout Standard
22416 \begin_inset LatexCommand index
22421 included in SDCC should have a license at least as liberal as the GNU Lesser
22422 General Public License
22423 \begin_inset LatexCommand index
22424 name "GNU Lesser General Public License, LGPL"
22435 \begin_layout Standard
22436 \begin_inset Note Note
22439 \begin_layout Standard
22440 license statements for the libraries are missing.
22441 sdcc/device/lib/ser_ir.c
22444 \begin_layout Standard
22446 come with a GPL (as opposed to LGPL) License - this will not be liberal
22447 enough for many embedded programmers.
22455 \begin_layout Standard
22456 If you have ported some library or want to share experience about some code
22458 falls into any of these categories Busses (I
22459 \begin_inset Formula $^{\textrm{2}}$
22462 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22463 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22464 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
22465 \begin_inset LatexCommand url
22466 target "http://sourceforge.net/mail/?group_id=599"
22471 would certainly like to hear about it.
22474 \begin_layout Standard
22475 Programmers coding for embedded systems are not especially famous for being
22476 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22477 e these references are very valuable.
22478 Let's help to create a climate where information is shared.
22479 \begin_inset VSpace bigskip
22485 \begin_layout Section
22489 \begin_layout Subsection
22490 MCS51 Memory Models
22491 \begin_inset LatexCommand index
22492 name "Memory model"
22497 \begin_inset LatexCommand index
22498 name "MCS51 memory model"
22505 \begin_layout Subsubsection
22506 Small, Medium and Large
22509 \begin_layout Standard
22510 SDCC allows three memory models for MCS51 code,
22519 Modules compiled with different memory models should
22523 be combined together or the results would be unpredictable.
22524 The library routines supplied with the compiler are compiled as small,
22526 The compiled library modules are contained in separate directories as small,
22527 medium and large so that you can link to the appropriate set.
22530 \begin_layout Standard
22531 When the medium or large model is used all variables declared without a
22532 storage class will be allocated into the external ram, this includes all
22533 parameters and local variables (for non-reentrant
22534 \begin_inset LatexCommand index
22540 When the small model is used variables without storage class are allocated
22541 in the internal ram.
22544 \begin_layout Standard
22545 Judicious usage of the processor specific storage classes
22546 \begin_inset LatexCommand index
22547 name "Storage class"
22551 and the 'reentrant' function type will yield much more efficient code,
22552 than using the large model.
22553 Several optimizations are disabled when the program is compiled using the
22554 large model, it is therefore recommended that the small model be used unless
22555 absolutely required.
22558 \begin_layout Subsubsection
22560 \begin_inset LatexCommand label
22561 name "sub:External-Stack"
22566 \begin_inset LatexCommand index
22572 \begin_inset LatexCommand index
22573 name "External stack (mcs51)"
22580 \begin_layout Standard
22581 The external stack (-
22585 \begin_layout Standard
22595 \begin_inset LatexCommand index
22600 ) is located in pdata
22601 \begin_inset LatexCommand index
22602 name "pdata (mcs51, ds390 storage class)"
22606 memory (usually at the start of the external ram segment) and uses all
22607 unused space in pdata (max.
22613 \begin_layout Standard
22622 -xstack option is used to compile the program, the parameters and local
22624 \begin_inset LatexCommand index
22625 name "local variables"
22629 of all reentrant functions are allocated in this area.
22630 This option is provided for programs with large stack space requirements.
22631 When used with the -
22635 \begin_layout Standard
22645 \begin_inset LatexCommand index
22646 name "-\\/-stack-auto"
22650 option, all parameters and local variables are allocated on the external
22651 stack (note: support libraries will need to be recompiled with the same
22653 There is a predefined target in the library makefile).
22656 \begin_layout Standard
22657 The compiler outputs the higher order address byte of the external ram segment
22659 \begin_inset LatexCommand index
22660 name "P2 (mcs51 sfr)"
22665 \begin_inset LatexCommand ref
22666 reference "sub:MCS51-variants"
22670 ), therefore when using the External Stack option, this port
22674 be used by the application program.
22677 \begin_layout Subsection
22679 \begin_inset LatexCommand index
22680 name "Memory model"
22685 \begin_inset LatexCommand index
22686 name "DS390 memory model"
22693 \begin_layout Standard
22694 The only model supported is Flat 24
22695 \begin_inset LatexCommand index
22696 name "Flat 24 (DS390 memory model)"
22701 This generates code for the 24 bit contiguous addressing mode of the Dallas
22703 In this mode, up to four meg of external RAM or code space can be directly
22705 See the data sheets at www.dalsemi.com for further information on this part.
22710 that the compiler does not generate any code to place the processor into
22711 24 bitmode (although
22715 in the ds390 libraries will do that for you).
22721 \begin_inset LatexCommand index
22722 name "Tinibios (DS390)"
22726 , the boot loader or similar code must ensure that the processor is in 24
22727 bit contiguous addressing mode before calling the SDCC startup code.
22738 \begin_layout Standard
22749 option, variables will by default be placed into the XDATA segment.
22754 Segments may be placed anywhere in the 4 meg address space using the usual
22759 \begin_layout Standard
22769 Note that if any segments are located above 64K, the -r flag must be passed
22770 to the linker to generate the proper segment relocations, and the Intel
22771 HEX output format must be used.
22772 The -r flag can be passed to the linker by using the option
22776 on the SDCC command line.
22777 However, currently the linker can not handle code segments > 64k.
22780 \begin_layout Section
22782 \begin_inset LatexCommand label
22788 \begin_inset LatexCommand index
22796 \begin_layout Standard
22797 Pragmas are used to turn on and/or off certain compiler options.
22798 Some of them are closely related to corresponding command-line options
22800 \begin_inset LatexCommand vref
22801 reference "sec:Command-Line-Options"
22807 Pragmas should be placed before and/or after a function, placing pragmas
22808 inside a function body could have unpredictable results.
22813 following #pragma directives:
22816 \begin_layout Itemize
22822 \begin_inset LatexCommand index
22823 name "\\#pragma save"
22827 - this will save most current options to the save/restore stack.
22828 See #pragma\InsetSpace ~
22832 \begin_layout Itemize
22838 \begin_inset LatexCommand index
22839 name "\\#pragma restore"
22843 - will restore saved options from the last save.
22844 saves & restores can be nested.
22845 SDCC uses a save/restore stack: save pushes current options to the stack,
22846 restore pulls current options from the stack.
22847 See #pragma\InsetSpace ~
22853 \begin_layout Itemize
22859 \begin_inset LatexCommand index
22860 name "\\#pragma callee\\_saves"
22865 \begin_inset LatexCommand index
22866 name "function prologue"
22870 function1[,function2[,function3...]]
22871 \begin_inset LatexCommand label
22872 name "ite:callee_saves-function1[,function2[,function3...]]--"
22876 - The compiler by default uses a caller saves convention for register saving
22877 across function calls, however this can cause unnecessary register pushing
22879 \begin_inset LatexCommand index
22884 when calling small functions from larger functions.
22885 This option can be used to switch off the register saving convention for
22886 the function names specified.
22887 The compiler will not save registers when calling these functions, extra
22888 code need to be manually inserted at the entry and exit for these functions
22889 to save and restore the registers used by these functions, this can SUBSTANTIAL
22890 LY reduce code and improve run time performance of the generated code.
22891 In the future the compiler (with inter procedural analysis) may be able
22892 to determine the appropriate scheme to use for each function call.
22897 \begin_layout Standard
22906 -callee-saves command line option is used (see page
22907 \begin_inset LatexCommand vpageref
22908 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22912 ), the function names specified in #pragma\InsetSpace ~
22914 \begin_inset LatexCommand index
22915 name "\\#pragma callee\\_saves"
22919 is appended to the list of functions specified in the command line.
22922 \begin_layout Itemize
22928 \begin_inset LatexCommand index
22929 name "\\#pragma exclude"
22933 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22934 of pairs of push/pop
22935 \begin_inset LatexCommand index
22945 \begin_inset LatexCommand index
22959 The directive should be placed immediately before the ISR function definition
22960 and it affects ALL ISR functions following it.
22961 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22962 exclude\InsetSpace ~
22964 \begin_inset LatexCommand index
22965 name "\\#pragma exclude"
22970 See also the related keyword _naked
22971 \begin_inset LatexCommand index
22977 \begin_inset LatexCommand index
22985 \begin_layout Itemize
22991 \begin_inset LatexCommand index
22997 \begin_inset LatexCommand index
22998 name "\\#pragma less\\_pedantic"
23003 \begin_inset LatexCommand label
23004 name "ite:less_pedantic"
23008 - the compiler will not warn you anymore for obvious mistakes, you're on
23010 See also the command line option -
23014 \begin_layout Standard
23024 \begin_inset LatexCommand vpageref
23025 reference "lyx:--less-pedantic"
23032 More specifically, the following warnings will be disabled:
23034 comparison is always [true/false] due to limited range of data type
23038 overflow in implicit constant conversion
23040 (158); [the (in)famous]
23042 conditional flow changed by optimizer: so said EVELYN the modified DOG
23046 function '[function name]' must return value
23051 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23052 level) are disabled, too, namely:
23055 \begin_inset Note Note
23058 \begin_layout Standard
23059 dunno what comes here - this warning appears to be unused altogether
23068 [left/right] shifting more than size of object changed to zero
23076 integer overflow in expression
23080 unmatched #pragma save and #pragma restore
23084 comparison of 'signed char' with 'unsigned char' requires promotion to int
23088 ISO C90 does not support flexible array members
23092 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23096 \begin_inset Note Note
23099 \begin_layout Standard
23100 appears to be always blank - what was supposed to be here?
23109 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23110 complexity [number]
23115 \begin_layout Itemize
23121 \begin_inset LatexCommand index
23122 name "\\#pragma disable\\_warning"
23126 - the compiler will not warn you anymore about warning number <nnnn>.
23129 \begin_layout Itemize
23135 \begin_inset LatexCommand index
23136 name "\\#pragma nogcse"
23140 - will stop global common subexpression elimination.
23143 \begin_layout Itemize
23149 \begin_inset LatexCommand index
23150 name "\\#pragma noinduction"
23154 - will stop loop induction optimizations.
23157 \begin_layout Itemize
23163 \begin_inset LatexCommand index
23164 name "\\#pragma noinvariant"
23168 - will not do loop invariant optimizations.
23169 For more details see Loop Invariants in section
23170 \begin_inset LatexCommand ref
23171 reference "sub:Loop-Optimizations"
23178 \begin_layout Itemize
23184 \begin_inset LatexCommand index
23185 name "\\#pragma noiv"
23189 - Do not generate interrupt
23190 \begin_inset LatexCommand index
23196 \begin_inset LatexCommand index
23197 name "interrupt vector table"
23201 entries for all ISR functions defined after the pragma.
23202 This is useful in cases where the interrupt vector table must be defined
23203 manually, or when there is a secondary, manually defined interrupt vector
23205 for the autovector feature of the Cypress EZ-USB FX2).
23206 More elegantly this can be achieved by omitting the optional interrupt
23207 number after the interrupt keyword, see section
23208 \begin_inset LatexCommand ref
23209 reference "sub:Interrupt-Service-Routines"
23217 \begin_layout Itemize
23223 \begin_inset LatexCommand index
23224 name "\\#pragma nojtbound"
23228 - will not generate code for boundary value checking, when switch statements
23229 are turned into jump-tables (dangerous).
23230 For more details see section
23231 \begin_inset LatexCommand ref
23232 reference "sub:'switch'-Statements"
23239 \begin_layout Itemize
23245 \begin_inset LatexCommand index
23246 name "\\#pragma noloopreverse"
23250 - Will not do loop reversal optimization
23253 \begin_layout Itemize
23259 \begin_inset LatexCommand index
23260 name "\\#pragma nooverlay"
23264 - the compiler will not overlay the parameters and local variables of a
23268 \begin_layout Itemize
23274 \begin_inset LatexCommand index
23275 name "\\#pragma stackauto"
23283 \begin_layout Standard
23293 \begin_inset LatexCommand index
23294 name "-\\/-stack-auto"
23299 \begin_inset LatexCommand ref
23300 reference "sec:Parameters-and-Local-Variables"
23304 Parameters and Local Variables.
23307 \begin_layout Itemize
23313 \begin_inset LatexCommand index
23314 name "\\#pragma opt\\_code\\_speed"
23318 - The compiler will optimize code generation towards fast code, possibly
23319 at the expense of code size.
23320 Currently this has little effect.
23323 \begin_layout Itemize
23329 \begin_inset LatexCommand index
23330 name "\\#pragma opt\\_code\\_size"
23334 - The compiler will optimize code generation towards compact code, possibly
23335 at the expense of code speed.
23336 Currently this has little effect.
23339 \begin_layout Itemize
23345 \begin_inset LatexCommand index
23346 name "\\#pragma opt\\_code\\_balanced"
23350 - The compiler will attempt to generate code that is both compact and fast,
23351 as long as meeting one goal is not a detriment to the other (this is the
23356 \begin_layout Itemize
23362 \begin_inset LatexCommand index
23363 name "\\#pragma std\\_sdcc89"
23367 - Generally follow the C89 standard, but allow SDCC features that conflict
23368 with the standard (default).
23371 \begin_layout Itemize
23377 \begin_inset LatexCommand index
23378 name "\\#pragma std\\_c89"
23382 - Follow the C89 standard and disable SDCC features that conflict with the
23386 \begin_layout Itemize
23392 \begin_inset LatexCommand index
23393 name "\\#pragma std\\_sdcc99"
23397 - Generally follow the C99 standard, but allow SDCC features that conflict
23398 with the standard (incomplete support).
23401 \begin_layout Itemize
23407 \begin_inset LatexCommand index
23408 name "\\#pragma std\\_c99"
23412 - Follow the C99 standard and disable SDCC features that conflict with the
23413 standard (incomplete support).
23416 \begin_layout Itemize
23422 \begin_inset LatexCommand index
23423 name "\\#pragma codeseg"
23427 - Use this name (max.
23428 8 characters) for the code segment.
23433 \begin_layout Standard
23445 \begin_layout Itemize
23451 \begin_inset LatexCommand index
23452 name "\\#pragma constseg"
23456 - Use this name (max.
23457 8 characters) for the const segment.
23462 \begin_layout Standard
23474 \begin_layout Standard
23475 The preprocessor SDCPP
23476 \begin_inset LatexCommand index
23477 name "sdcpp (preprocessor)"
23481 supports the following #pragma directives:
23484 \begin_layout Itemize
23487 pedantic_parse_number
23490 \begin_inset LatexCommand index
23496 \begin_inset LatexCommand index
23497 name "\\#pragma pedantic\\_parse\\_number"
23502 \begin_inset LatexCommand label
23503 name "ite:pedantic_parse_number"
23507 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23508 properly and the macro LO_B(3) gets expanded.
23514 \begin_layout Standard
23523 -pedantic-parse-number command line option
23524 \begin_inset LatexCommand vpageref
23525 reference "lyx:-pedantic-parse-number"
23532 Below is an example on how to use this pragma.
23535 Note: this functionality is not in conformance with standard!
23538 \begin_layout Verse
23541 #pragma pedantic_parse_number +
23542 \begin_inset LatexCommand index
23543 name "\\#pragma pedantic\\_parse\\_number"
23551 #define LO_B(x) ((x) & 0xff)
23555 unsigned char foo(void)
23562 unsigned char c=0xfe-LO_B(3)
23577 \begin_layout Itemize
23583 \begin_inset LatexCommand index
23584 name "\\#pragma preproc\\_asm"
23588 (+ | -) - switch _asm _endasm block preprocessing on / off.
23590 You use this pragma to define multilines of assembly code.
23591 This will prevent the preprocessor from changing the formatting required
23593 Below is an example on how to use this pragma.
23596 \begin_layout Verse
23599 #pragma preproc_asm -
23600 \begin_inset LatexCommand index
23601 name "\\#pragma preproc\\_asm"
23607 #define MYDELAY _asm
23612 nop ;my assembly comment...
23626 #pragma preproc_asm
23657 \begin_layout Itemize
23663 \begin_inset LatexCommand index
23664 name "\\#pragma sdcc\\_hash"
23668 (+ | -) - Allow "naked" hash in macro definition, for example:
23672 #define DIR_LO(x) #(x & 0xff)
23677 Below is an example on how to use this pragma.
23680 \begin_layout Verse
23683 #pragma preproc_asm +
23685 #pragma sdcc_hash +
23686 \begin_inset LatexCommand index
23687 name "\\#pragma sdcc\\_hash"
23702 mov R6_B3, #(x & 0xff)
23709 mov R7_B3, #((x >> 8) & 0xff)
23733 \begin_layout Standard
23734 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23735 ons which might cause the compiler to generate extra stack and/or data space
23736 to store compiler generated temporary variables.
23737 This usually happens in large functions.
23738 Pragma directives should be used as shown in the following example, they
23739 are used to control options and optimizations for a given function.
23743 \begin_layout Verse
23747 \begin_inset LatexCommand index
23748 name "\\#pragma save"
23759 /* save the current settings */
23762 \begin_inset LatexCommand index
23763 name "\\#pragma nogcse"
23772 /* turnoff global subexpression elimination */
23774 #pragma noinduction
23775 \begin_inset LatexCommand index
23776 name "\\#pragma noinduction"
23780 /* turn off induction optimizations */
23803 \begin_inset LatexCommand index
23804 name "\\#pragma restore"
23808 /* turn the optimizations back on */
23811 \begin_layout Standard
23812 The compiler will generate a warning message when extra space is allocated.
23813 It is strongly recommended that the save and restore pragmas be used when
23814 changing options for a function.
23823 \begin_layout Section
23824 Defines Created by the Compiler
23827 \begin_layout Standard
23828 The compiler creates the following #defines
23829 \begin_inset LatexCommand index
23835 \begin_inset LatexCommand index
23836 name "Defines created by the compiler"
23845 \begin_layout Standard
23846 \begin_inset Tabular
23847 <lyxtabular version="3" rows="15" columns="2">
23849 <column alignment="left" valignment="top" leftline="true" width="3in">
23850 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23851 <row topline="true" bottomline="true">
23852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23855 \begin_layout Standard
23863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23866 \begin_layout Standard
23875 <row topline="true">
23876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23879 \begin_layout Standard
23881 \begin_inset LatexCommand index
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23894 \begin_layout Standard
23896 Since version 2.5.6 the version number as an int (ex.
23903 <row topline="true">
23904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23907 \begin_layout Standard
23909 \begin_inset LatexCommand index
23910 name "SDCC\\_mcs51"
23915 \begin_inset LatexCommand index
23916 name "SDCC\\_ds390"
23921 \begin_inset LatexCommand index
23931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23934 \begin_layout Standard
23935 depending on the model used (e.g.: -mds390)
23941 <row topline="true">
23942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23945 \begin_layout Standard
23947 \begin_inset LatexCommand index
23953 \begin_inset LatexCommand index
23959 \begin_inset LatexCommand index
23965 \begin_inset LatexCommand index
23975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23978 \begin_layout Standard
23979 depending on the model used (e.g.
23986 <row topline="true">
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23990 \begin_layout Standard
23992 \begin_inset LatexCommand index
23993 name "SDCC\\_STACK\\_AUTO"
24002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24005 \begin_layout Standard
24012 \begin_layout Standard
24029 <row topline="true">
24030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24033 \begin_layout Standard
24035 \begin_inset LatexCommand index
24036 name "SDCC\\_MODEL\\_SMALL"
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24048 \begin_layout Standard
24055 \begin_layout Standard
24072 <row topline="true">
24073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24076 \begin_layout Standard
24078 \begin_inset LatexCommand index
24079 name "SDCC\\_MODEL\\_MEDIUM"
24088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24091 \begin_layout Standard
24098 \begin_layout Standard
24115 <row topline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24119 \begin_layout Standard
24121 \begin_inset LatexCommand index
24122 name "SDCC\\_MODEL\\_LARGE"
24131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24134 \begin_layout Standard
24141 \begin_layout Standard
24158 <row topline="true">
24159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24162 \begin_layout Standard
24164 \begin_inset LatexCommand index
24165 name "SDCC\\_USE\\_XSTACK"
24174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24177 \begin_layout Standard
24184 \begin_layout Standard
24201 <row topline="true">
24202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24205 \begin_layout Standard
24207 \begin_inset LatexCommand index
24208 name "SDCC\\_STACK\\_TENBIT"
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24220 \begin_layout Standard
24231 <row topline="true">
24232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24235 \begin_layout Standard
24237 \begin_inset LatexCommand index
24238 name "SDCC\\_MODEL\\_FLAT24"
24247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24250 \begin_layout Standard
24261 <row topline="true">
24262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24265 \begin_layout Standard
24267 \begin_inset LatexCommand index
24268 name "SDCC\\_REVISION"
24277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24280 \begin_layout Standard
24282 SDCC svn revision number
24288 <row topline="true">
24289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24292 \begin_layout Standard
24293 SDCC_PARMS_IN_BANK1
24294 \begin_inset LatexCommand index
24295 name "SDCC\\_PARMS\\_IN\\_BANK1"
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24307 \begin_layout Standard
24314 \begin_layout Standard
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24335 \begin_layout Standard
24337 \begin_inset LatexCommand index
24338 name "SDCC\\_MODEL\\_FLAT24"
24347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24350 \begin_layout Standard
24357 \begin_layout Standard
24374 <row topline="true" bottomline="true">
24375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24378 \begin_layout Standard
24379 SDCC_INT_LONG_REENT
24380 \begin_inset LatexCommand index
24381 name "SDCC\\_INT\\_LONG\\_REENT"
24390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24393 \begin_layout Standard
24400 \begin_layout Standard
24424 \begin_layout Chapter
24425 Notes on supported Processors
24428 \begin_layout Section
24430 \begin_inset LatexCommand label
24431 name "sub:MCS51-variants"
24436 \begin_inset LatexCommand index
24437 name "MCS51 variants"
24444 \begin_layout Standard
24445 MCS51 processors are available from many vendors and come in many different
24447 While they might differ considerably in respect to Special Function Registers
24448 the core MCS51 is usually not modified or is kept compatible.
24452 \begin_layout Subsection
24453 pdata access by SFR
24456 \begin_layout Standard
24457 With the upcome of devices with internal xdata and flash memory devices
24459 \begin_inset LatexCommand index
24460 name "P2 (mcs51 sfr)"
24464 as dedicated I/O port is becoming more popular.
24465 Switching the high byte for pdata
24466 \begin_inset LatexCommand index
24467 name "pdata (mcs51, ds390 storage class)"
24471 access which was formerly done by port P2 is then achieved by a Special
24473 \begin_inset LatexCommand index
24479 In well-established MCS51 tradition the address of this
24483 is where the chip designers decided to put it.
24484 Needless to say that they didn't agree on a common name either.
24485 So that the startup code can correctly initialize xdata variables, you
24486 should define an sfr with the name _XPAGE
24489 \begin_inset LatexCommand index
24490 name "\\_XPAGE (mcs51)"
24496 at the appropriate location if the default, port P2, is not used for this.
24500 \begin_layout Verse
24503 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24507 \begin_layout Verse
24510 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24515 \begin_layout Verse
24518 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24522 \begin_layout Verse
24525 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24529 \begin_layout Verse
24532 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24536 \begin_layout Standard
24537 For more exotic implementations further customizations may be needed.
24539 \begin_inset LatexCommand ref
24540 reference "sub:Startup-Code"
24544 for other possibilities.
24547 \begin_layout Subsection
24548 Other Features available by SFR
24551 \begin_layout Standard
24552 Some MCS51 variants offer features like Double DPTR
24553 \begin_inset LatexCommand index
24558 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24559 These are currently not used for the MCS51 port.
24560 If you absolutely need them you can fall back to inline assembly or submit
24564 \begin_layout Subsection
24568 \begin_layout Standard
24570 \begin_inset LatexCommand index
24571 name "Bankswitching"
24577 \begin_inset LatexCommand index
24578 name "code banking"
24582 ) is a technique to increase the code space above the 64k limit of the 8051.
24585 \begin_layout Subsubsection
24589 \begin_layout Standard
24590 \begin_inset Tabular
24591 <lyxtabular version="3" rows="3" columns="4">
24593 <column alignment="center" valignment="top" width="0">
24594 <column alignment="center" valignment="top" leftline="true" width="0">
24595 <column alignment="center" valignment="top" leftline="true" width="0">
24596 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24597 <row topline="true" bottomline="true">
24598 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24601 \begin_layout Standard
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24610 \begin_layout Standard
24616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24619 \begin_layout Standard
24625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24628 \begin_layout Standard
24635 <row topline="true" bottomline="true">
24636 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24639 \begin_layout Standard
24645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24648 \begin_layout Standard
24654 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24657 \begin_layout Standard
24663 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24666 \begin_layout Standard
24674 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24677 \begin_layout Standard
24678 SiLabs C8051F120 example
24683 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24686 \begin_layout Standard
24692 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24695 \begin_layout Standard
24701 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24704 \begin_layout Standard
24719 Usually the hardware uses some sfr (an output port or an internal sfr) to
24720 select a bank and put it in the banked area of the memory map.
24721 The selected bank usually becomes active immediately upon assignment to
24722 this sfr and when running inside a bank it will switch out this code it
24723 is currently running.
24724 Therefor you cannot jump or call directly from one bank to another and
24725 need to use a so-called trampoline in the common area.
24726 For SDCC an example trampoline is in crtbank.asm and you may need to change
24727 it to your 8051 derivative or schematic.
24728 The presented code is written for the C8051F120.
24732 When calling a banked function
24733 SDCC will put the LSB of the functions address in register R0, the MSB
24734 in R1 and the bank in R2 and then call this trampoline
24739 The current selected bank is saved on the stack, the new bank is selected
24740 and an indirect jump is made.
24741 When the banked function returns it jumps to
24745 which restores the previous bank and returns to the caller.
24748 \begin_layout Subsubsection
24752 \begin_layout Standard
24753 When writing banked software using SDCC you need to use some special keywords
24755 You also need to take over a bit of work from the linker.
24759 To create a function
24760 that can be called from another bank it requires the keyword
24765 \begin_inset LatexCommand index
24771 The caller must see this in the prototype of the callee and the callee
24772 needs it for a proper return.
24773 Called functions within the same bank as the caller do not need the
24777 keyword nor do functions in the common area.
24778 Beware: SDCC does not know or check if functions are in the same bank.
24779 This is your responsibility!
24783 Normally all functions you write end up in
24785 If you want a function explicitly to reside in the common area put it in
24787 This applies for instance to interrupt service routines as they should
24791 \begin_layout Standard
24792 Functions that need to be in a switched bank must be put in a named segment.
24793 The name can be mostly anything up to eight characters (e.g.
24795 To do this you either use -
24799 \begin_layout Standard
24808 -codeseg BANK1 (See
24809 \begin_inset LatexCommand ref
24810 reference "lyx:-codeseg"
24814 ) on the command line when compiling or #pragma codeseg BANK1 (See
24815 \begin_inset LatexCommand ref
24816 reference "sec:Pragmas"
24820 ) at the top of the C source file.
24821 The segment name always applies to the whole source file and generated
24822 object so functions for different banks need to be defined in different
24827 When linking your objects you need to tell the linker where
24828 to put your segments.
24829 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24831 \begin_inset LatexCommand ref
24832 reference "lyx:-Wl option"
24837 This sets the virtual start address of this segment.
24838 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24839 The linker will not check for overflows, again this is your responsibility.
24842 \begin_layout Standard
24843 \begin_inset VSpace bigskip
24849 \begin_layout Section
24853 \begin_layout Standard
24855 \begin_inset LatexCommand index
24861 \begin_inset LatexCommand index
24866 microcontroller has a rich set of peripherals.
24867 In its built-in ROM library it includes functions to access some of the
24868 features, among them is a TCP stack with IP4 and IP6 support.
24869 Library headers (currently in beta status) and other files are provided
24873 \begin_inset LatexCommand url
24874 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24880 \begin_inset VSpace bigskip
24886 \begin_layout Section
24887 The Z80 and gbz80 port
24890 \begin_layout Standard
24891 SDCC can target both the Zilog Z80
24892 \begin_inset LatexCommand index
24897 and the Nintendo Gameboy's Z80-like gbz80
24898 \begin_inset LatexCommand index
24899 name "gbz80 (GameBoy Z80)"
24904 The Z80 port is passed through the same
24907 \begin_inset LatexCommand index
24908 name "Regression test"
24915 \begin_inset LatexCommand ref
24916 reference "sec:Quality-control"
24920 ) as the MCS51 and DS390 ports, so floating point support, support for long
24921 variables and bitfield support is fine.
24922 See mailing lists and forums about interrupt routines.
24925 \begin_layout Standard
24926 As always, the code is the authoritative reference - see z80/ralloc.c and
24929 \begin_inset LatexCommand index
24934 frame is similar to that generated by the IAR Z80 compiler.
24935 IX is used as the base pointer, HL and IY are used as a temporary registers,
24936 and BC and DE are available for holding variables.
24938 \begin_inset LatexCommand index
24939 name "Z80!return value"
24943 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24945 The gbz80 port use the same set of registers for the return values, but
24946 in a different order of significance: E (one byte), DE (two bytes), or
24948 \begin_inset VSpace bigskip
24954 \begin_layout Section
24958 \begin_layout Standard
24959 The port to the Freescale/Motorola HC08
24960 \begin_inset LatexCommand index
24965 family has been added in October 2003, and is still undergoing some basic
24967 The code generator is complete, but the register allocation is still quite
24969 Some of the SDCC's standard C library functions have embedded non-HC08
24970 inline assembly and so are not yet usable.
24973 \begin_layout Standard
24974 The HC08 port passes the regression test suite (see section
24975 \begin_inset LatexCommand ref
24976 reference "sec:Quality-control"
24981 \begin_inset VSpace bigskip
24987 \begin_layout Section
24989 \begin_inset LatexCommand index
24997 \begin_layout Standard
24998 The PIC14 port adds support for Microchip
24999 \begin_inset LatexCommand index
25005 \begin_inset Formula $^{\text{TM}}$
25009 \begin_inset LatexCommand index
25015 \begin_inset Formula $^{\text{TM}}$
25018 MCUs with 14 bit wide instructions.
25019 This port is not yet mature and still lacks many features.
25020 However, it can work for simple code.
25023 \begin_layout Standard
25025 Currently supported devices include:
25028 \begin_layout Standard
25029 12F: 629, 635, 675, 683
25032 \begin_layout Standard
25036 \begin_layout Standard
25040 \begin_layout Standard
25041 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25044 \begin_layout Standard
25045 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25049 \begin_layout Standard
25053 \begin_layout Standard
25054 16CR: 620a, 73, 74, 76, 77
25057 \begin_layout Standard
25058 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25062 \begin_layout Standard
25063 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25066 \begin_layout Standard
25067 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25068 877, 877a, 88, 886, 887
25071 \begin_layout Standard
25072 16F: 913, 914, 916, 917, 946
25075 \begin_layout Standard
25079 \begin_layout Standard
25081 An up-to-date list of currently supported devices can be obtained via
25083 sdcc -mpic14 -phelp foo.c
25085 (foo.c must exist...).
25088 \begin_layout Subsection
25090 \begin_inset LatexCommand index
25091 name "code page (pic14)"
25096 \begin_inset LatexCommand index
25097 name "Memory bank (pic14)"
25104 \begin_layout Standard
25105 The linker organizes allocation for the code page and RAM banks.
25106 It does not have intimate knowledge of the code flow.
25107 It will put all the code section of a single .asm file into a single code
25109 In order to make use of multiple code pages, separate asm files must be
25111 The compiler assigns all
25115 functions of a single .c file into the same code page.
25119 To get the best results,
25120 follow these guidelines:
25123 \begin_layout Enumerate
25124 Make local functions static, as non static functions require code page selection
25127 Due to the way sdcc handles functions, place called functions prior
25128 to calling functions in the file wherever possible: Otherwise sdcc will
25129 insert unnecessary pagesel directives around the call, believing that the
25130 called function is externally defined.
25133 \begin_layout Enumerate
25134 For devices that have multiple code pages it is more efficient to use the
25135 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25136 but only 2 files for the 16F874.
25137 This way the linker can put the code for each file into different code
25138 pages and there will be less page selection overhead.
25141 \begin_layout Enumerate
25142 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25143 instruction set), use `unsigned char' wherever possible instead of `int'.
25146 \begin_layout Subsection
25147 Adding New Devices to the Port
25150 \begin_layout Standard
25151 Adding support for a new 14
25155 \begin_layout Standard
25164 bit PIC MCU requires the following steps:
25167 \begin_layout Enumerate
25168 Create a new device description.
25170 Each device is described in two files: pic16f*.h
25172 These files primarily define SFRs, structs to access their bits, and symbolic
25173 configuration options.
25174 Both files can be generated from gputils' .inc files using the perl script
25177 support/scripts/inc2h.pl
25180 This file also contains further instructions on how to proceed.
25183 \begin_layout Enumerate
25184 Copy the .h file into SDCC's include path and either add the .c file to your
25185 project or copy it to
25187 device/lib/pic/libdev
25190 Afterwards, rebuild and install the libraries.
25193 \begin_layout Enumerate
25194 Edit pic14devices.txt in SDCC's include path (
25196 device/include/pic/
25198 in the source tree or
25200 /usr/local/share/sdcc/include/pic
25202 after installation).
25204 You need to add a device specification here to make
25205 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25207 Probably you can copy and modify an existing entry.
25208 The file format is documented at the top of the file.
25211 \begin_layout Subsection
25215 \begin_layout Standard
25216 For the interrupt function, use the keyword `__interrupt'
25217 \begin_inset LatexCommand index
25218 name "PIC14!interrupt"
25222 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25223 there to avoid a syntax error - it ought to be fixed).
25227 \begin_layout Verse
25230 void Intr(void) __interrupt 0
25236 T0IF = 0; /* Clear timer interrupt */
25241 \begin_layout Subsection
25242 Linking and Assembling
25245 \begin_layout Standard
25246 For assembling you can use either GPUTILS'
25247 \begin_inset LatexCommand index
25248 name "gputils (pic tools)"
25252 gpasm.exe or MPLAB's mpasmwin.exe.
25253 GPUTILS are available from
25254 \begin_inset LatexCommand url
25255 target "http://sourceforge.net/projects/gputils"
25260 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25261 If you use MPLAB and an interrupt function then the linker script file
25262 vectors section will need to be enlarged to link with mplink.
25273 \begin_layout Verse
25286 sdcc -V -mpic14 -p16f877 -c $<
25290 $(PRJ).hex: $(OBJS)
25300 gplink -m -s $(PRJ).lkr
25301 -o $(PRJ).hex $(OBJS) libsdcc.lib
25304 \begin_layout Standard
25312 \begin_layout Verse
25325 sdcc -S -V -mpic14 -p16f877 $<
25335 mpasmwin /q /o $*.asm
25339 $(PRJ).hex: $(OBJS)
25350 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25353 \begin_layout Standard
25354 Please note that indentations within a
25358 have to be done with a tabulator character.
25361 \begin_layout Subsection
25362 Command-Line Options
25365 \begin_layout Standard
25366 Besides the switches common to all SDCC backends, the PIC14 port accepts
25367 the following options (for an updated list see sdcc -
25371 \begin_layout Standard
25383 \begin_layout Description
25388 \begin_layout Standard
25398 \begin_inset LatexCommand index
25399 name "PIC14!Options!-\\/-debug-extra"
25403 emit debug info in assembly output
25406 \begin_layout Description
25411 \begin_layout Standard
25421 \begin_inset LatexCommand index
25422 name "PIC14!Options!-\\/-no-pcode-opt"
25426 disable (slightly faulty) optimization on pCode
25429 \begin_layout Description
25434 \begin_layout Standard
25444 \begin_inset LatexCommand index
25445 name "PIC14!Options!-\\/-stack-loc"
25449 sets the lowest address of the argument passing stack (defaults to a suitably
25450 large shared databank to reduce BANKSEL overhead)
25453 \begin_layout Description
25458 \begin_layout Standard
25468 \begin_inset LatexCommand index
25469 name "PIC14!Options!-\\/-stack-size"
25473 sets the size if the argument passing stack (default: 16, minimum: 4)
25476 \begin_layout Subsection
25477 Environment Variables
25480 \begin_layout Standard
25481 The PIC14 port recognizes the following environment variables:
25484 \begin_layout Description
25485 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25486 register (the ones called r0xNNNN) in a section of its own.
25487 By default (if this variable is unset), sdcc tries to cluster registers
25488 in sections in order to reduce the BANKSEL overhead when accessing them.
25491 \begin_layout Subsection
25495 \begin_layout Standard
25496 The PIC14 library currently only contains support routines required by the
25497 compiler to implement multiplication, division, and floating point support.
25498 No libc-like replacement is available at the moment, though many of the
25499 common sdcc library sources (in
25503 ) should also compile with the PIC14 port.
25506 \begin_layout Subsubsection
25507 error: missing definition for symbol ``__gptrget1''
25510 \begin_layout Standard
25511 The PIC14 port uses library routines to provide more complex operations
25512 like multiplication, division/modulus and (generic) pointer dereferencing.
25513 In order to add these routines to your project, you must link with PIC14's
25519 For single source file projects this is done automatically, more complex
25524 to the linker's arguments.
25525 Make sure you also add an include path for the library (using the -I switch
25529 \begin_layout Subsubsection
25530 Processor mismatch in file ``XXX''.
25533 \begin_layout Standard
25534 This warning can usually be ignored due to the very good compatibility amongst
25539 \begin_layout Standard
25549 \begin_inset LatexCommand index
25557 \begin_layout Standard
25558 You might also consider recompiling the library for your specific device
25559 by changing the ARCH=p16f877 (default target) entry in
25561 device/lib/pic/Makefile.in
25565 device/lib/pic/Makefile
25567 to reflect your device.
25568 This might even improve performance for smaller devices as unnecessary
25569 BANKSELs might be removed.
25572 \begin_layout Subsection
25576 \begin_layout Subsubsection
25580 \begin_layout Standard
25581 Functions with variable argument lists (like printf) are not yet supported.
25582 Similarly, taking the address of the first argument passed into a function
25583 does not work: It is currently passed in WREG and has no address...
25586 \begin_layout Subsubsection
25587 Regression tests fail
25590 \begin_layout Standard
25591 Though the small subset of regression tests in src/regression passes, SDCC
25592 regression test suite does not, indicating that there are still major bugs
25594 However, many smaller projects have successfully used SDCC in the past...
25597 \begin_layout Standard
25605 \begin_layout Section
25607 \begin_inset LatexCommand index
25615 \begin_layout Standard
25616 The PIC16 port adds support for Microchip
25617 \begin_inset LatexCommand index
25623 \begin_inset Formula $^{\text{TM}}$
25627 \begin_inset LatexCommand index
25633 \begin_inset Formula $^{\text{TM}}$
25636 MCUs with 16 bit wide instructions.
25637 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25638 ; devices supported by the port include:
25641 \begin_layout Standard
25642 18F: 242, 248, 252, 258, 442, 448, 452, 458
25645 \begin_layout Standard
25649 \begin_layout Standard
25650 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25654 \begin_layout Standard
25655 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25659 \begin_layout Standard
25660 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25664 \begin_layout Standard
25665 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25669 \begin_layout Standard
25670 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25673 \begin_layout Standard
25674 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25677 \begin_layout Standard
25678 18F: 96j60, 96j65, 97j60
25681 \begin_layout Standard
25683 An up-to-date list of supported devices is also available via '
25685 sdcc -mpic16 -plist
25690 \begin_layout Subsection
25694 \begin_layout Standard
25695 PIC16 port supports the standard command line arguments as supposed, with
25696 the exception of certain cases that will be mentioned in the following
25700 \begin_layout Description
25705 \begin_layout Standard
25715 \begin_inset LatexCommand index
25716 name "PIC16!Options!-\\/-callee-saves"
25724 \begin_layout Standard
25736 \begin_layout Description
25741 \begin_layout Standard
25750 -fommit-frame-pointer
25751 \begin_inset LatexCommand index
25752 name "PIC16!Options!-\\/-fommit-frame-pointer"
25756 Frame pointer will be omitted when the function uses no local variables.
25759 \begin_layout Subsection
25760 Port Specific Options
25761 \begin_inset LatexCommand index
25762 name "Options PIC16"
25769 \begin_layout Standard
25770 The port specific options appear after the global options in the sdcc -
25774 \begin_layout Standard
25786 \begin_layout Subsubsection
25787 Code Generation Options
25790 \begin_layout Standard
25791 These options influence the generated assembler code.
25794 \begin_layout Description
25799 \begin_layout Standard
25808 -pstack-model=[model] Used in conjunction with the command above.
25809 Defines the stack model to be used, valid stack models are:
25814 \labelwidthstring 00.00.0000
25819 Selects small stack model.
25820 8 bit stack and frame pointers.
25821 Supports 256 bytes stack size.
25825 \labelwidthstring 00.00.0000
25830 Selects large stack model.
25831 16 bit stack and frame pointers.
25832 Supports 65536 bytes stack size.
25836 \begin_layout Description
25841 \begin_layout Standard
25850 -pno-banksel Do not generate BANKSEL assembler directives.
25853 \begin_layout Description
25858 \begin_layout Standard
25867 -extended Enable extended instruction set/literal offset addressing mode.
25871 \begin_layout Subsubsection
25872 Optimization Options
25875 \begin_layout Description
25880 \begin_layout Standard
25889 -obanksel=n Set optimization level for inserting BANKSELs.
25896 \labelwidthstring 00.00.0000
25901 \labelwidthstring 00.00.0000
25902 1 checks previous used register and if it is the same then does not emit
25903 BANKSEL, accounts only for labels.
25907 \labelwidthstring 00.00.0000
25908 2 tries to check the location of (even different) symbols and removes BANKSELs
25909 if they are in the same bank.
25914 Important: There might be problems if the linker script has data sections
25915 across bank borders!
25919 \begin_layout Description
25924 \begin_layout Standard
25933 -denable-peeps Force the usage of peepholes.
25937 \begin_layout Description
25942 \begin_layout Standard
25951 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25954 \begin_layout Description
25959 \begin_layout Standard
25968 -optimize-cmp Try to optimize some compares.
25971 \begin_layout Description
25976 \begin_layout Standard
25985 -optimize-df Analyze the dataflow of the generated code and improve it.
25988 \begin_layout Subsubsection
25992 \begin_layout Description
25997 \begin_layout Standard
26006 -asm= Sets the full path and name of an external assembler to call.
26009 \begin_layout Description
26014 \begin_layout Standard
26024 \begin_inset LatexCommand index
26029 compatibility option.
26030 Currently only suppresses special gpasm directives.
26033 \begin_layout Subsubsection
26037 \begin_layout Description
26042 \begin_layout Standard
26051 -link= Sets the full path and name of an external linker to call.
26054 \begin_layout Description
26059 \begin_layout Standard
26068 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26069 unitialized data variables with [kword].
26070 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26073 \begin_layout Description
26078 \begin_layout Standard
26087 -ivt-loc=n Place the interrupt vector table at address
26092 Useful for bootloaders.
26095 \begin_layout Description
26100 \begin_layout Standard
26109 -nodefaultlibs Do not link default libraries when linking.
26112 \begin_layout Description
26117 \begin_layout Standard
26126 -use-crt= Use a custom run-time module instead of the defaults.
26129 \begin_layout Description
26134 \begin_layout Standard
26143 -no-crt Don't link the default run-time modules
26146 \begin_layout Subsubsection
26150 \begin_layout Standard
26151 Debugging options enable extra debugging information in the output files.
26154 \begin_layout Description
26159 \begin_layout Standard
26168 -debug-xtra Similar to -
26172 \begin_layout Standard
26182 \begin_inset LatexCommand index
26187 , but dumps more information.
26190 \begin_layout Description
26195 \begin_layout Standard
26204 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26206 <source> is the name of the file being compiled.
26209 \begin_layout Description
26214 \begin_layout Standard
26223 -pcode-verbose Enable pcode debugging information in translation.
26226 \begin_layout Description
26231 \begin_layout Standard
26240 -calltree Dump call tree in .calltree file.
26243 \begin_layout Description
26248 \begin_layout Standard
26257 -gstack Trace push/pops for stack pointer overflow.
26260 \begin_layout Subsection
26261 Environment Variables
26264 \begin_layout Standard
26265 There is a number of environmental variables that can be used when running
26266 SDCC to enable certain optimizations or force a specific program behaviour.
26267 these variables are primarily for debugging purposes so they can be enabled/dis
26271 \begin_layout Standard
26272 Currently there is only two such variables available:
26275 \begin_layout Description
26276 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26277 bitfields is optimized by directly loading FSR0 with the address of the
26278 bitfield structure.
26279 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26281 This step saves data ram and code space for functions that make heavy use
26283 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26288 \begin_layout Description
26289 NO_REG_OPT Do not perform pCode registers optimization.
26290 This should be used for debugging purposes.
26291 If bugs in the pcode optimizer are found, users can benefit from temporarily
26292 disabling the optimizer until the bug is fixed.
26295 \begin_layout Subsection
26296 Preprocessor Macros
26299 \begin_layout Standard
26301 \begin_inset LatexCommand index
26306 port defines the following preprocessor macros while translating a source.
26309 \begin_layout Standard
26311 \begin_inset Tabular
26312 <lyxtabular version="3" rows="6" columns="2">
26314 <column alignment="center" valignment="top" leftline="true" width="0">
26315 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26316 <row topline="true" bottomline="true">
26317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26320 \begin_layout Standard
26326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26329 \begin_layout Standard
26336 <row topline="true">
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26340 \begin_layout Standard
26346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26349 \begin_layout Standard
26350 Port identification
26356 <row topline="true">
26357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_layout Standard
26365 \begin_layout Standard
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26382 \begin_layout Standard
26383 Port identification (same as above)
26389 <row topline="true">
26390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26393 \begin_layout Standard
26399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26402 \begin_layout Standard
26403 MCU Identification.
26408 is the microcontrol identification number, i.e.
26415 <row topline="true">
26416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26419 \begin_layout Standard
26424 \begin_layout Standard
26438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26441 \begin_layout Standard
26442 MCU Identification (same as above)
26448 <row topline="true" bottomline="true">
26449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26452 \begin_layout Standard
26458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26461 \begin_layout Standard
26462 nnn = SMALL or LARGE respectively according to the stack model used
26475 \begin_layout Standard
26477 In addition the following macros are defined when calling assembler:
26480 \begin_layout Standard
26482 \begin_inset Tabular
26483 <lyxtabular version="3" rows="4" columns="2">
26485 <column alignment="center" valignment="top" leftline="true" width="0">
26486 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26487 <row topline="true" bottomline="true">
26488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26491 \begin_layout Standard
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26500 \begin_layout Standard
26507 <row topline="true">
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26511 \begin_layout Standard
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26520 \begin_layout Standard
26521 MCU Identification.
26526 is the microcontrol identification number, i.e.
26533 <row topline="true">
26534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26537 \begin_layout Standard
26543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26546 \begin_layout Standard
26547 nnn = SMALL or LARGE respectively according to the memory model used for
26554 <row topline="true" bottomline="true">
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26558 \begin_layout Standard
26564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26567 \begin_layout Standard
26568 nnn = SMALL or LARGE respectively according to the stack model used
26581 \begin_layout Subsection
26585 \begin_layout Standard
26587 \begin_inset LatexCommand index
26592 port uses the following directories for searching header files and libraries.
26595 \begin_layout Standard
26597 \begin_inset Tabular
26598 <lyxtabular version="3" rows="3" columns="4">
26600 <column alignment="center" valignment="top" leftline="true" width="0">
26601 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26602 <column alignment="center" valignment="top" width="0">
26603 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26604 <row topline="true" bottomline="true">
26605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26608 \begin_layout Standard
26614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26617 \begin_layout Standard
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26626 \begin_layout Standard
26632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26635 \begin_layout Standard
26642 <row topline="true">
26643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26646 \begin_layout Standard
26647 PREFIX/sdcc/include/pic16
26652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26655 \begin_layout Standard
26656 PIC16 specific headers
26661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26664 \begin_layout Standard
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26673 \begin_layout Standard
26680 <row topline="true" bottomline="true">
26681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26684 \begin_layout Standard
26685 PREFIX/sdcc/lib/pic16
26690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26693 \begin_layout Standard
26694 PIC16 specific libraries
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26702 \begin_layout Standard
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26711 \begin_layout Standard
26725 \begin_layout Subsection
26727 \begin_inset LatexCommand label
26728 name "sub:PIC16_Pragmas"
26735 \begin_layout Standard
26737 \begin_inset LatexCommand index
26742 port currently supports the following pragmas:
26745 \begin_layout Description
26747 \begin_inset LatexCommand index
26748 name "PIC16!Pragmas!\\#pragma stack"
26752 This forces the code generator to initialize the stack & frame pointers
26753 at a specific address.
26754 This is an ad hoc solution for cases where no STACK directive is available
26755 in the linker script or gplink is not instructed to create a stack section.
26758 stack pragma should be used only once in a project.
26759 Multiple pragmas may result in indeterminate behaviour of the program.
26763 \begin_layout Standard
26764 The old format (ie.
26765 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26766 cross page boundaries (or even exceed the available data RAM) and crash
26768 Make sure that stack does not cross page boundaries when using the SMALL
26776 The format is as follows:
26781 \begin_layout LyX-Code
26782 #pragma stack bottom_address [stack_size]
26787 \begin_layout Standard
26792 is the lower bound of the stack section.
26793 The stack pointer initially will point at address (bottom_address+stack_size-1).
26796 \begin_layout LyX-Code
26800 \begin_layout LyX-Code
26804 \begin_layout LyX-Code
26805 /* initializes stack of 100 bytes at RAM address 0x200 */
26808 \begin_layout LyX-Code
26809 #pragma stack 0x200 100
26812 \begin_layout Standard
26813 If the stack_size field is omitted then a stack is created with the default
26815 This size might be enough for most programs, but its not enough for operations
26816 with deep function nesting or excessive stack usage.
26819 \begin_layout Description
26821 \begin_inset LatexCommand index
26822 name "PIC16!Pragmas!\\#pragma code"
26826 Force a function to a static FLASH address.
26829 \begin_layout LyX-Code
26833 \begin_layout LyX-Code
26837 \begin_layout LyX-Code
26838 /* place function test_func at 0x4000 */
26841 \begin_layout LyX-Code
26842 #pragma code test_func 0x4000
26845 \begin_layout LyX-Code
26849 \begin_layout Description
26850 library instructs the linker to use a library module.
26855 \begin_layout LyX-Code
26856 #pragma library module_name
26859 \begin_layout Standard
26864 can be any library or object file (including its path).
26865 Note that there are four reserved keywords which have special meaning.
26869 \begin_layout Standard
26871 \begin_inset Tabular
26872 <lyxtabular version="3" rows="6" columns="3">
26874 <column alignment="center" valignment="top" leftline="true" width="0">
26875 <column alignment="block" valignment="top" leftline="true" width="20page%">
26876 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26877 <row topline="true" bottomline="true">
26878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26881 \begin_layout Standard
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26890 \begin_layout Standard
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26899 \begin_layout Standard
26906 <row topline="true">
26907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26910 \begin_layout Standard
26918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26921 \begin_layout Standard
26922 ignore all library pragmas
26927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26930 \begin_layout Standard
26939 <row topline="true">
26940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26943 \begin_layout Standard
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26954 \begin_layout Standard
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26963 \begin_layout Standard
26974 <row topline="true">
26975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26978 \begin_layout Standard
26986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26989 \begin_layout Standard
26990 link the Math libarary
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26998 \begin_layout Standard
27009 <row topline="true">
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_layout Standard
27021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27024 \begin_layout Standard
27025 link the I/O library
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27033 \begin_layout Standard
27044 <row topline="true" bottomline="true">
27045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27048 \begin_layout Standard
27056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27059 \begin_layout Standard
27060 link the debug library
27065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27068 \begin_layout Standard
27085 * is the device number, i.e.
27086 452 for PIC18F452 MCU.
27089 \begin_layout Standard
27091 This feature allows for linking with specific libraries without having to
27092 explicit name them in the command line.
27097 keyword will reject all modules specified by the library pragma.
27100 \begin_layout Description
27101 udata The pragma udata instructs the compiler to emit code so that linker
27102 will place a variable at a specific memory bank.
27105 \begin_layout LyX-Code
27109 \begin_layout LyX-Code
27113 \begin_layout LyX-Code
27114 /* places variable foo at bank2 */
27117 \begin_layout LyX-Code
27118 #pragma udata bank2 foo
27121 \begin_layout LyX-Code
27125 \begin_layout Standard
27126 In order for this pragma to work extra SECTION directives should be added
27127 in the .lkr script.
27128 In the following example a sample .lkr file is shown:
27131 \begin_layout LyX-Code
27135 \begin_layout LyX-Code
27136 // Sample linker script for the PIC18F452 processor
27139 \begin_layout LyX-Code
27143 \begin_layout LyX-Code
27144 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27147 \begin_layout LyX-Code
27148 CODEPAGE NAME=page START=0x2A END=0x7FFF
27151 \begin_layout LyX-Code
27152 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27155 \begin_layout LyX-Code
27156 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27159 \begin_layout LyX-Code
27160 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27163 \begin_layout LyX-Code
27164 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27167 \begin_layout LyX-Code
27168 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27171 \begin_layout LyX-Code
27175 \begin_layout LyX-Code
27176 DATABANK NAME=gpr0 START=0x80 END=0xFF
27179 \begin_layout LyX-Code
27180 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27183 \begin_layout LyX-Code
27184 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27187 \begin_layout LyX-Code
27188 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27191 \begin_layout LyX-Code
27192 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27195 \begin_layout LyX-Code
27196 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27199 \begin_layout LyX-Code
27200 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27203 \begin_layout LyX-Code
27207 \begin_layout LyX-Code
27208 SECTION NAME=CONFIG ROM=config
27211 \begin_layout LyX-Code
27215 \begin_layout LyX-Code
27216 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27219 \begin_layout LyX-Code
27220 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27223 \begin_layout LyX-Code
27224 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27227 \begin_layout LyX-Code
27228 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27231 \begin_layout LyX-Code
27232 SECTION NAME=bank4 RAM=gpr4
27235 \begin_layout LyX-Code
27236 SECTION NAME=bank5 RAM=gpr5
27239 \begin_layout Standard
27240 The linker will recognise the section name set in the pragma statement and
27241 will position the variable at the memory bank set with the RAM field at
27242 the SECTION line in the linker script file.
27245 \begin_layout Subsection
27247 \begin_inset LatexCommand label
27248 name "sub:PIC16_Header-Files"
27255 \begin_layout Standard
27256 There is one main header file
27257 \begin_inset LatexCommand index
27258 name "PIC16!Header files"
27262 that can be included to the source files using the pic16
27263 \begin_inset LatexCommand index
27274 This header file contains the definitions for the processor special registers,
27275 so it is necessary if the source accesses them.
27276 It can be included by adding the following line in the beginning of the
27280 \begin_layout LyX-Code
27281 #include <pic18fregs.h>
27284 \begin_layout Standard
27285 The specific microcontroller is selected within the pic18fregs.h automatically,
27286 so the same source can be used with a variety of devices.
27289 \begin_layout Subsection
27291 \begin_inset LatexCommand label
27292 name "sub:pic16Libraries"
27299 \begin_layout Standard
27301 \begin_inset LatexCommand index
27302 name "PIC16!Libraries"
27307 \begin_inset LatexCommand index
27312 port depends on are the microcontroller device libraries which contain
27313 the symbol definitions for the microcontroller special function registers.
27314 These libraries have the format pic18fxxxx.lib, where
27318 is the microcontroller identification number.
27319 The specific library is selected automatically by the compiler at link
27320 stage according to the selected device.
27323 \begin_layout Standard
27325 Libraries are created with gplib which is part of the gputils package
27326 \begin_inset LatexCommand url
27327 target "http://sourceforge.net/projects/gputils"
27334 \begin_layout Subsubsection*
27335 Building the libraries
27338 \begin_layout Standard
27339 Before using SDCC/pic16 there are some libraries that need to be compiled.
27340 This process is done automatically if gputils are found at SDCC's compile
27342 Should you require to rebuild the pic16 libraries manually (e.g.
27343 in order to enable output of float values
27344 \begin_inset LatexCommand index
27345 name "Floating point support"
27353 , see below), these are the steps required to do so under Linux or Mac OS
27354 X (cygwin might work as well, but is untested):
27357 \begin_layout LyX-Code
27358 cd device/lib/pic16
27361 \begin_layout LyX-Code
27365 \begin_layout LyX-Code
27369 \begin_layout LyX-Code
27373 \begin_layout LyX-Code
27374 su -c 'make install' # install the libraries, you need the root password
27377 \begin_layout LyX-Code
27381 \begin_layout Standard
27382 If you need to install the headers too, do:
27385 \begin_layout LyX-Code
27389 \begin_layout LyX-Code
27390 su -c 'make install' # install the headers, you need the root password
27393 \begin_layout Subsubsection*
27394 Output of float values via printf()
27397 \begin_layout Standard
27398 The library is normally built without support for displaying float values,
27399 only <NO FLOAT> will appear instead of the value.
27400 To change this, rebuild the library as stated above, but call
27402 ./configure.gnu --enable-floats
27409 Also make sure that at least
27411 libc/stdio/vfprintf.c
27413 is actually recompiled, e.g.
27422 run or deleting its
27429 \begin_layout Standard
27430 The more common appraoch of compiling
27438 should also work, but is untested.
27441 \begin_layout Subsection
27442 Adding New Devices to the Port
27445 \begin_layout Standard
27446 Adding support for a new 16
27450 \begin_layout Standard
27459 bit PIC MCU requires the following steps:
27462 \begin_layout Enumerate
27463 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27467 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27471 \begin_layout Enumerate
27474 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27477 \begin_layout Enumerate
27480 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27483 \begin_layout Enumerate
27486 /path/to/sdcc/device/lib/pic16/pics.all
27490 Note: No 18f prefix here!
27493 \begin_layout Enumerate
27496 /path/to/sdcc/device/include/pic16/adc.h
27500 Add the new devices to the correct ADC style class (depending on the number
27507 if the device does not offer any ADC at all.
27510 \begin_layout Enumerate
27513 /path/to/sdcc/device/include/pic16/pic18fregs.h
27517 The file format is self-explanatory, just add
27521 #elif defined(picDEVICE)
27527 \begin_layout Standard
27538 include <picDEVICE.h>
27542 at the right place (keep the file sorted, please).
27545 \begin_layout Enumerate
27548 /path/to/sdcc/device/include/pic16devices.txt
27552 Copy and modify an existing entry or create a new one and insert it at the
27553 correct place (keep the file sorted, please).
27556 \begin_layout Enumerate
27559 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27563 Copy an existing entry and adjust the device name.
27566 \begin_layout Enumerate
27569 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27573 Copy the record from the 18f2220 and adjust the device name.
27576 does not offer ADC, I
27577 \begin_inset Formula $^{\text{2}}$
27580 C, and/or (E)USART functionality as assumed by the library, remove the lines
27596 \begin_layout Enumerate
27615 /path/to/sdcc/device/lib/pic16
27620 \begin_layout Enumerate
27621 Recompile the pic16 libraries as described in
27622 \begin_inset LatexCommand ref
27623 reference "sub:pic16Libraries"
27630 \begin_layout Subsection
27634 \begin_layout Standard
27635 The following memory models are supported by the PIC16 port:
27638 \begin_layout Itemize
27642 \begin_layout Itemize
27646 \begin_layout Standard
27647 Memory model affects the default size of pointers within the source.
27648 The sizes are shown in the next table:
27651 \begin_layout Standard
27653 \begin_inset Tabular
27654 <lyxtabular version="3" rows="3" columns="3">
27656 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27657 <column alignment="center" valignment="top" leftline="true" width="0">
27658 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27659 <row topline="true" bottomline="true">
27660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27663 \begin_layout Standard
27664 Pointer sizes according to memory model
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27672 \begin_layout Standard
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27681 \begin_layout Standard
27688 <row topline="true" bottomline="true">
27689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27692 \begin_layout Standard
27698 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27701 \begin_layout Standard
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27710 \begin_layout Standard
27717 <row topline="true" bottomline="true">
27718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27721 \begin_layout Standard
27727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27730 \begin_layout Standard
27736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27739 \begin_layout Standard
27753 \begin_layout Standard
27754 It is advisable that all sources within a project are compiled with the
27756 If one wants to override the default memory model, this can be done by
27757 declaring a pointer as
27766 Far selects large memory model's pointers, while near selects small memory
27770 \begin_layout Standard
27771 The standard device libraries (see
27772 \begin_inset LatexCommand ref
27773 reference "sub:PIC16_Header-Files"
27777 ) contain no reference to pointers, so they can be used with both memory
27781 \begin_layout Subsection
27785 \begin_layout Standard
27787 \begin_inset LatexCommand index
27792 implementation for the PIC16 port uses two indirect registers, FSR1 and
27796 \begin_layout Description
27797 FSR1 is assigned as stack pointer
27800 \begin_layout Description
27801 FSR2 is assigned as frame pointer
27804 \begin_layout Standard
27805 The following stack models are supported by the PIC16 port
27808 \begin_layout Itemize
27816 \begin_layout Itemize
27824 \begin_layout Standard
27829 model means that only the FSRxL byte is used to access stack and frame,
27836 uses both FSRxL and FSRxH registers.
27837 The following table shows the stack/frame pointers sizes according to stack
27838 model and the maximum space they can address:
27841 \begin_layout Standard
27843 \begin_inset Tabular
27844 <lyxtabular version="3" rows="3" columns="3">
27846 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27847 <column alignment="center" valignment="top" leftline="true" width="0">
27848 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27849 <row topline="true" bottomline="true">
27850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27853 \begin_layout Standard
27854 Stack & Frame pointer sizes according to stack model
27859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27862 \begin_layout Standard
27868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27871 \begin_layout Standard
27878 <row topline="true">
27879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27882 \begin_layout Standard
27888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27891 \begin_layout Standard
27897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27900 \begin_layout Standard
27907 <row topline="true" bottomline="true">
27908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27911 \begin_layout Standard
27917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27920 \begin_layout Standard
27926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27929 \begin_layout Standard
27943 \begin_layout Standard
27949 stack model is currently not working properly throughout the code generator.
27950 So its use is not advised.
27951 Also there are some other points that need special care:
27956 \begin_layout Enumerate
27957 Do not create stack sections with size more than one physical bank (that
27961 \begin_layout Enumerate
27962 Stack sections should no cross physical bank limits (i.e.
27963 #pragma stack 0x50 0x100)
27966 \begin_layout Standard
27967 These limitations are caused by the fact that only FSRxL is modified when
27968 using SMALL stack model, so no more than 256 bytes of stack can be used.
27969 This problem will disappear after LARGE model is fully implemented.
27972 \begin_layout Subsection
27976 \begin_layout Standard
27977 In addition to the standard SDCC function keywords, PIC16
27978 \begin_inset LatexCommand index
27983 port makes available two more:
27986 \begin_layout Description
27988 \begin_inset LatexCommand index
27989 name "PIC16!wparam"
27993 Use the WREG to pass one byte of the first function argument.
27994 This improves speed but you may not use this for functions with arguments
27995 that are called via function pointers, otherwise the first byte of the
27996 first parameter will get lost.
28000 \begin_layout LyX-Code
28001 void func_wparam(int a) wparam
28004 \begin_layout LyX-Code
28008 \begin_layout LyX-Code
28009 /* WREG hold the lower part of a */
28012 \begin_layout LyX-Code
28013 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28017 \begin_layout LyX-Code
28021 \begin_layout LyX-Code
28025 \begin_layout Description
28027 \begin_inset LatexCommand index
28028 name "PIC16!shadowregs"
28032 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28033 hardware shadow registers which hold the values of WREG, STATUS and BSR
28035 This can be done by adding the keyword
28043 keyword in the function's header.
28046 \begin_layout LyX-Code
28047 void isr_shadow(void) shadowregs interrupt 1
28050 \begin_layout LyX-Code
28054 \begin_layout LyX-Code
28058 \begin_layout LyX-Code
28062 \begin_layout Standard
28067 instructs the code generator not to store/restore WREG, STATUS, BSR when
28068 entering/exiting the ISR.
28071 \begin_layout Subsection
28072 Function return values
28075 \begin_layout Standard
28076 Return values from functions are placed to the appropriate registers following
28077 a modified Microchip policy optimized for SDCC.
28078 The following table shows these registers:
28081 \begin_layout Standard
28083 \begin_inset Tabular
28084 <lyxtabular version="3" rows="6" columns="2">
28086 <column alignment="center" valignment="top" leftline="true" width="0">
28087 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28088 <row topline="true" bottomline="true">
28089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28092 \begin_layout Standard
28098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28101 \begin_layout Standard
28102 destination register
28108 <row topline="true">
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28112 \begin_layout Standard
28118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28121 \begin_layout Standard
28128 <row topline="true">
28129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28132 \begin_layout Standard
28138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28141 \begin_layout Standard
28148 <row topline="true">
28149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28152 \begin_layout Standard
28158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28161 \begin_layout Standard
28168 <row topline="true">
28169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28172 \begin_layout Standard
28178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28181 \begin_layout Standard
28182 FSR0L:PRODH:PRODL:WREG
28188 <row topline="true" bottomline="true">
28189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28192 \begin_layout Standard
28198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28201 \begin_layout Standard
28202 on stack, FSR0 points to the beginning
28215 \begin_layout Subsection
28219 \begin_layout Standard
28221 \begin_inset LatexCommand index
28222 name "PIC16!interrupt"
28226 service routine (ISR) is declared using the
28233 \begin_layout LyX-Code
28234 void isr(void) interrupt
28239 \begin_layout LyX-Code
28243 \begin_layout LyX-Code
28247 \begin_layout LyX-Code
28251 \begin_layout Standard
28256 is the interrupt number, which for PIC18F devices can be:
28259 \begin_layout Standard
28261 \begin_inset Tabular
28262 <lyxtabular version="3" rows="4" columns="3">
28264 <column alignment="center" valignment="top" leftline="true" width="0">
28265 <column alignment="center" valignment="top" leftline="true" width="0">
28266 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28267 <row topline="true" bottomline="true">
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28271 \begin_layout Standard
28279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28282 \begin_layout Standard
28288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28291 \begin_layout Standard
28292 Interrupt Vector Address
28298 <row topline="true">
28299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28302 \begin_layout Standard
28308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28311 \begin_layout Standard
28317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28320 \begin_layout Standard
28327 <row topline="true">
28328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28331 \begin_layout Standard
28346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28349 \begin_layout Standard
28359 HIGH priority interrupts
28364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28367 \begin_layout Standard
28374 <row topline="true" bottomline="true">
28375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28378 \begin_layout Standard
28384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28387 \begin_layout Standard
28388 LOW priority interrupts
28393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28396 \begin_layout Standard
28410 \begin_layout Standard
28411 When generating assembly code for ISR the code generator places a
28417 Interrupt Vector Address
28419 which points at the generated ISR.
28420 This single GOTO instruction is part of an automatically generated
28422 interrupt entry point
28425 The actuall ISR code is placed as normally would in the code space.
28426 Upon interrupt request, the GOTO instruction is executed which jumps to
28428 When declaring interrupt functions as _naked this GOTO instruction is
28433 The whole interrupt functions is therefore placed at the Interrupt Vector
28434 Address of the specific interrupt.
28435 This is not a problem for the LOW priority interrupts, but it is a problem
28436 for the RESET and the HIGH priority interrupts because code may be written
28437 at the next interrupt's vector address and cause indeterminate program
28438 behaviour if that interrupt is raised.
28442 \begin_layout Standard
28443 This is not a problem when
28446 \begin_layout Enumerate
28447 this is a HIGH interrupt ISR and LOW interrupts are
28454 \begin_layout Enumerate
28455 when the ISR is small enough not to reach the next interrupt's vector address.
28463 \begin_layout Standard
28469 This way a function is generated similar to an ISR, but it is not assigned
28473 \begin_layout Standard
28474 When entering an interrupt, currently the PIC16
28475 \begin_inset LatexCommand index
28480 port automatically saves the following registers:
28483 \begin_layout Itemize
28487 \begin_layout Itemize
28491 \begin_layout Itemize
28495 \begin_layout Itemize
28496 PROD (PRODL and PRODH)
28499 \begin_layout Itemize
28500 FSR0 (FSR0L and FSR0H)
28503 \begin_layout Standard
28504 These registers are restored upon return from the interrupt routine.
28508 \begin_layout Standard
28509 NOTE that when the _naked attribute is specified for an interrupt routine,
28510 then NO registers are stored or restored.
28518 \begin_layout Subsection
28522 \begin_layout Standard
28523 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28524 There are 3 types of generic pointers currently implemented data, code
28525 and eeprom pointers.
28526 They are differentiated by the value of the 7th and 6th bits of the upper
28530 \begin_layout Standard
28532 \begin_inset Tabular
28533 <lyxtabular version="3" rows="5" columns="5">
28535 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28536 <column alignment="center" valignment="top" width="0">
28537 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28538 <column alignment="center" valignment="top" width="0">
28539 <column alignment="left" valignment="top" rightline="true" width="0">
28540 <row topline="true" bottomline="true">
28541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28544 \begin_layout Standard
28550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28553 \begin_layout Standard
28559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28562 \begin_layout Standard
28568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28571 \begin_layout Standard
28572 rest of the pointer
28577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28580 \begin_layout Standard
28587 <row topline="true" bottomline="true">
28588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28591 \begin_layout Standard
28597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28600 \begin_layout Standard
28606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28609 \begin_layout Standard
28615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28618 \begin_layout Standard
28623 uuuuuu uuuuxxxx xxxxxxxx
28628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28631 \begin_layout Standard
28632 a 12-bit data pointer in data RAM memory
28638 <row bottomline="true">
28639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28642 \begin_layout Standard
28648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28651 \begin_layout Standard
28657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28660 \begin_layout Standard
28666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28669 \begin_layout Standard
28674 uxxxxx xxxxxxxx xxxxxxxx
28679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28682 \begin_layout Standard
28683 a 21-bit code pointer in FLASH memory
28689 <row bottomline="true">
28690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28693 \begin_layout Standard
28699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28702 \begin_layout Standard
28708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28711 \begin_layout Standard
28717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28720 \begin_layout Standard
28725 uuuuuu uuuuuuxx xxxxxxxx
28730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28733 \begin_layout Standard
28734 a 10-bit eeprom pointer in EEPROM memory
28740 <row bottomline="true">
28741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28744 \begin_layout Standard
28750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28753 \begin_layout Standard
28759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28762 \begin_layout Standard
28768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28771 \begin_layout Standard
28776 xxxxxx xxxxxxxx xxxxxxxx
28781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28784 \begin_layout Standard
28785 unimplemented pointer type
28798 \begin_layout Standard
28800 Generic pointer are read and written with a set of library functions which
28801 read/write 1, 2, 3, 4 bytes.
28804 \begin_layout Subsection
28808 \begin_layout Subsubsection
28809 Standard I/O Streams
28812 \begin_layout Standard
28817 the type FILE is defined as:
28820 \begin_layout LyX-Code
28821 typedef char * FILE;
28824 \begin_layout Standard
28825 This type is the stream type implemented I/O in the PIC18F devices.
28826 Also the standard input and output streams are declared in stdio.h:
28829 \begin_layout LyX-Code
28830 extern FILE * stdin;
28833 \begin_layout LyX-Code
28834 extern FILE * stdout;
28837 \begin_layout Standard
28838 The FILE type is actually a generic pointer which defines one more type
28839 of generic pointers, the
28844 This new type has the format:
28847 \begin_layout Standard
28850 \begin_inset Tabular
28851 <lyxtabular version="3" rows="2" columns="7">
28853 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28854 <column alignment="center" valignment="top" width="0">
28855 <column alignment="center" valignment="top" leftline="true" width="0">
28856 <column alignment="center" valignment="top" leftline="true" width="0">
28857 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28858 <column alignment="center" valignment="top" width="0">
28859 <column alignment="left" valignment="top" rightline="true" width="0">
28860 <row topline="true" bottomline="true">
28861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28864 \begin_layout Standard
28870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28873 \begin_layout Standard
28879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28882 \begin_layout Standard
28888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28891 \begin_layout Standard
28897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28900 \begin_layout Standard
28906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28909 \begin_layout Standard
28910 rest of the pointer
28915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28918 \begin_layout Standard
28925 <row topline="true" bottomline="true">
28926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28929 \begin_layout Standard
28935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28938 \begin_layout Standard
28944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28947 \begin_layout Standard
28953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28956 \begin_layout Standard
28962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28965 \begin_layout Standard
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28974 \begin_layout Standard
28984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28987 \begin_layout Standard
28988 upper byte high nubble is 0x2n, the rest are zeroes
29001 \begin_layout Standard
29003 Currently implemented there are 3 types of streams defined:
29006 \begin_layout Standard
29009 \begin_inset Tabular
29010 <lyxtabular version="3" rows="4" columns="4">
29012 <column alignment="center" valignment="top" leftline="true" width="0">
29013 <column alignment="center" valignment="top" leftline="true" width="0">
29014 <column alignment="center" valignment="top" leftline="true" width="0">
29015 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29016 <row topline="true" bottomline="true">
29017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29020 \begin_layout Standard
29026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29029 \begin_layout Standard
29035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29038 \begin_layout Standard
29044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29047 \begin_layout Standard
29054 <row topline="true">
29055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29058 \begin_layout Standard
29064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29067 \begin_layout Standard
29075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29078 \begin_layout Standard
29084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29087 \begin_layout Standard
29088 Writes/Reads characters via the USART peripheral
29094 <row topline="true">
29095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29098 \begin_layout Standard
29104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29107 \begin_layout Standard
29115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29118 \begin_layout Standard
29124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29127 \begin_layout Standard
29128 Writes/Reads characters via the MSSP peripheral
29134 <row topline="true" bottomline="true">
29135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29138 \begin_layout Standard
29144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29147 \begin_layout Standard
29155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29158 \begin_layout Standard
29164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29167 \begin_layout Standard
29168 Writes/Reads characters via used defined functions
29181 \begin_layout Standard
29183 The stream identifiers are declared as macros in the stdio.h header.
29186 \begin_layout Standard
29188 In the libc library there exist the functions that are used to write to
29189 each of the above streams.
29193 \begin_layout Description
29198 \begin_layout Standard
29207 _stream_usart_putchar writes a character at the USART stream
29210 \begin_layout Description
29215 \begin_layout Standard
29224 _stream_mssp_putchar writes a character at the MSSP stream
29227 \begin_layout Description
29228 putchar dummy function.
29229 This writes a character to a user specified manner.
29232 \begin_layout Standard
29233 In order to increase performance
29237 is declared in stdio.h as having its parameter in WREG (it has the wparam
29239 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29240 in a user-friendly way.
29245 is the name of the variable that holds the character to print.
29246 An example follows:
29249 \begin_layout LyX-Code
29250 #include <pic18fregs.h>
29259 \begin_layout LyX-Code
29263 \begin_layout LyX-Code
29264 PORTA = c; /* dump character c to PORTA */
29267 \begin_layout LyX-Code
29275 \begin_layout LyX-Code
29279 \begin_layout LyX-Code
29280 stdout = STREAM_USER; /* this is not necessary, since stdout points
29283 \begin_layout LyX-Code
29284 * by default to STREAM_USER */
29287 \begin_layout LyX-Code
29289 \begin_inset Quotes sld
29292 This is a printf test
29295 \begin_inset Quotes srd
29301 \begin_layout LyX-Code
29305 \begin_layout LyX-Code
29309 \begin_layout Subsubsection
29313 \begin_layout Standard
29314 PIC16 contains an implementation of the printf-family of functions.
29315 There exist the following functions:
29318 \begin_layout LyX-Code
29319 extern unsigned int sprintf(char *buf, char *fmt, ...);
29322 \begin_layout LyX-Code
29323 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29326 \begin_layout LyX-Code
29330 \begin_layout LyX-Code
29331 extern unsigned int printf(char *fmt, ...);
29334 \begin_layout LyX-Code
29335 extern unsigned int vprintf(char *fmt, va_lista ap);
29338 \begin_layout LyX-Code
29342 \begin_layout LyX-Code
29343 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29346 \begin_layout LyX-Code
29347 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29350 \begin_layout Standard
29351 For sprintf and vsprintf
29355 should normally be a data pointer where the resulting string will be placed.
29356 No range checking is done so the user should allocate the necessary buffer.
29357 For fprintf and vfprintf
29361 should be a stream pointer (i.e.
29362 stdout, STREAM_MSSP, etc...).
29365 \begin_layout Subsubsection
29369 \begin_layout Standard
29370 The PIC18F family of microcontrollers supports a number of interrupt sources.
29371 A list of these interrupts is shown in the following table:
29374 \begin_layout Standard
29376 \begin_inset Tabular
29377 <lyxtabular version="3" rows="11" columns="4">
29379 <column alignment="left" valignment="top" leftline="true" width="0">
29380 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29381 <column alignment="left" valignment="top" leftline="true" width="0">
29382 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29383 <row topline="true" bottomline="true">
29384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29387 \begin_layout Standard
29393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29396 \begin_layout Standard
29402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29405 \begin_layout Standard
29411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29414 \begin_layout Standard
29421 <row topline="true">
29422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29425 \begin_layout Standard
29431 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29434 \begin_layout Standard
29435 PORTB change interrupt
29440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29443 \begin_layout Standard
29449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29452 \begin_layout Standard
29453 EEPROM/FLASH write complete interrupt
29459 <row topline="true">
29460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29463 \begin_layout Standard
29469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29472 \begin_layout Standard
29473 INT0 external interrupt
29478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29481 \begin_layout Standard
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29490 \begin_layout Standard
29491 Bus collision interrupt
29497 <row topline="true">
29498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29501 \begin_layout Standard
29507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29510 \begin_layout Standard
29511 INT1 external interrupt
29516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29519 \begin_layout Standard
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29528 \begin_layout Standard
29529 Low voltage detect interrupt
29535 <row topline="true">
29536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29539 \begin_layout Standard
29545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29548 \begin_layout Standard
29549 INT2 external interrupt
29554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29557 \begin_layout Standard
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29566 \begin_layout Standard
29567 Parallel slave port interrupt
29573 <row topline="true">
29574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29577 \begin_layout Standard
29583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29586 \begin_layout Standard
29587 CCP1 module interrupt
29592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29595 \begin_layout Standard
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29604 \begin_layout Standard
29605 AD convertion complete interrupt
29611 <row topline="true">
29612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29615 \begin_layout Standard
29621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29624 \begin_layout Standard
29625 CCP2 module interrupt
29630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29633 \begin_layout Standard
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29642 \begin_layout Standard
29643 USART receive interrupt
29649 <row topline="true">
29650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29653 \begin_layout Standard
29659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29662 \begin_layout Standard
29663 TMR0 overflow interrupt
29668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29671 \begin_layout Standard
29677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29680 \begin_layout Standard
29681 USART transmit interrupt
29687 <row topline="true">
29688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29691 \begin_layout Standard
29697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29700 \begin_layout Standard
29701 TMR1 overflow interrupt
29706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29709 \begin_layout Standard
29715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29718 \begin_layout Standard
29719 SSP receive/transmit interrupt
29725 <row topline="true">
29726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29729 \begin_layout Standard
29735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29738 \begin_layout Standard
29739 TMR2 matches PR2 interrupt
29744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29747 \begin_layout Standard
29753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29756 \begin_layout Standard
29763 <row topline="true" bottomline="true">
29764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29767 \begin_layout Standard
29773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29776 \begin_layout Standard
29777 TMR3 overflow interrupt
29782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29785 \begin_layout Standard
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29794 \begin_layout Standard
29808 \begin_layout Standard
29810 The prototypes for these names are defined in the header file
29817 \begin_layout Standard
29819 In order to simplify signal handling, a number of macros is provided:
29823 \labelwidthstring 00.00.0000
29824 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29825 high priority interrupts.
29830 is the function name to use.
29834 \labelwidthstring 00.00.0000
29835 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29836 low priority interrupt.
29841 is the function name to use.
29845 \labelwidthstring 00.00.0000
29846 DEF_HANDLER(sig,handler) define a handler for signal
29852 \labelwidthstring 00.00.0000
29853 END_DEF end the declaration of the dispatch table.
29856 \begin_layout Standard
29857 Additionally there are two more macros to simplify the declaration of the
29862 \labelwidthstring 00.00.0000
29865 SIGHANDLER(handler)
29867 this declares the function prototype for the
29875 \labelwidthstring 00.00.0000
29876 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29879 \begin_layout Standard
29880 An example of using the macros above is shown below:
29883 \begin_layout LyX-Code
29884 #include <pic18fregs.h>
29887 \begin_layout LyX-Code
29888 #include <signal.h>
29892 DEF_INTHIGH(high_int)
29895 \begin_layout LyX-Code
29896 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29899 \begin_layout LyX-Code
29900 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29903 \begin_layout LyX-Code
29908 SIGHANDLER(_tmr0_handler)
29911 \begin_layout LyX-Code
29915 \begin_layout LyX-Code
29916 /* action to be taken when timer 0 overflows */
29919 \begin_layout LyX-Code
29924 SIGHANDLERNAKED(_bcol_handler)
29927 \begin_layout LyX-Code
29931 \begin_layout LyX-Code
29935 \begin_layout LyX-Code
29936 /* action to be taken when bus collision occurs */
29939 \begin_layout LyX-Code
29943 \begin_layout LyX-Code
29947 \begin_layout LyX-Code
29951 \begin_layout Standard
29956 Special care should be taken when using the above scheme:
29959 \begin_layout Itemize
29960 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29963 \begin_layout Itemize
29964 when declaring SIGHANDLERNAKED handler never forget to use
29968 for proper returning.
29971 \begin_layout Subsection
29975 \begin_layout Standard
29976 Here you can find some general tips for compiling programs with SDCC/pic16.
29979 \begin_layout Subsubsection
29983 \begin_layout Standard
29985 \begin_inset LatexCommand index
29990 size (that is 64 bytes) probably is enough for many programs.
29991 One must take care that when there are many levels of function nesting,
29992 or there is excessive usage of stack, its size should be extended.
29993 An example of such a case is the printf/sprintf family of functions.
29994 If you encounter problems like not being able to print integers, then you
29995 need to set the stack size around the maximum (256 for small stack model).
29996 The following diagram shows what happens when calling printf to print an
30000 \begin_layout LyX-Code
30001 printf () --> ltoa () --> ultoa () --> divschar ()
30004 \begin_layout Standard
30005 It is should be understood that stack is easily consumed when calling complicate
30007 Using command line arguments like -
30011 \begin_layout Standard
30020 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30022 Other ways to reduce stack usage may exist.
30025 \begin_layout Subsection
30029 \begin_layout Subsubsection
30030 Extended Instruction Set
30033 \begin_layout Standard
30034 The PIC16 port emits code which is incompatible with the extended instruction
30035 set available with many newer devices.
30036 Make sure to always explicitly disable it, usually using
30039 \begin_layout Standard
30042 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30045 \begin_layout Standard
30047 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30048 instead of _XINST_OFF_4L.
30051 \begin_layout Subsubsection
30055 \begin_layout Standard
30056 The PIC16 port currently passes most but not all of the tests in SDCC's
30058 \begin_inset LatexCommand index
30059 name "Regression test (PIC16)"
30064 \begin_inset LatexCommand ref
30065 reference "sec:Quality-control"
30069 ), thus no automatic regression tests are currently performed for the PIC16
30073 \begin_layout Chapter
30077 \begin_layout Standard
30078 There are several approaches to debugging your code.
30079 This chapter is meant to show your options and to give detail on some of
30084 When writing your code:
30087 \begin_layout Itemize
30088 write your code with debugging in mind (avoid duplicating code, put conceptually
30089 similar variables into structs, use structured code, have strategic points
30090 within your code where all variables are consistent, ...)
30093 \begin_layout Itemize
30094 run a syntax-checking tool like splint
30095 \begin_inset LatexCommand index
30096 name "splint (syntax checking tool)"
30101 \begin_inset LatexCommand index
30102 name "lint (syntax checking tool)"
30110 \begin_layout Standard
30120 \begin_inset LatexCommand ref
30121 reference "lyx:more-pedantic-SPLINT"
30128 \begin_layout Itemize
30129 for the high level code use a C-compiler (like f.e.
30130 GCC) to compile run and debug the code on your host.
30135 \begin_layout Standard
30145 \begin_inset LatexCommand ref
30146 reference "lyx:more-pedantic-SPLINT"
30150 ) on how to handle syntax extensions like __xdata, __at(), ...
30154 \begin_layout Itemize
30155 use another C-compiler to compile code for your target.
30156 Always an option but not recommended:) And not very likely to help you.
30157 If you seriously consider walking this path you should at least occasionally
30158 check portability of your code.
30159 Most commercial compiler vendors will offer an evaluation version so you
30160 can test compile your code or snippets of your code.
30163 \begin_layout Standard
30164 Debugging on a simulator:
30167 \begin_layout Itemize
30168 there is a separate section about SDCDB (section
30169 \begin_inset LatexCommand ref
30170 reference "cha:Debugging-with-SDCDB"
30177 \begin_layout Itemize
30178 or (8051 specific) use a freeware/commercial simulator which interfaces
30180 \begin_inset LatexCommand index
30181 name "AOMF, AOMF51"
30186 \begin_inset LatexCommand ref
30187 reference "OMF file"
30191 ) optionally generated by SDCC.
30194 \begin_layout Standard
30195 Debugging On-target:
30198 \begin_layout Itemize
30199 use a MCU port pin to serially output debug data to the RS232 port of your
30201 You'll probably want some level shifting device typically involving a MAX232
30203 If the hardware serial port of the MCU is not available search for 'Software
30204 UART' in your favourite search machine.
30207 \begin_layout Itemize
30208 use an on-target monitor.
30209 In this context a monitor is a small program which usually accepts commands
30210 via a serial line and allows to set program counter, to single step through
30211 a program and read/write memory locations.
30212 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30214 \begin_inset LatexCommand ref
30215 reference "sec:Related-open-source-tools"
30222 \begin_layout Itemize
30223 toggle MCU port pins at strategic points within your code and use an oscilloscop
30227 digital oscilloscope
30230 \begin_inset LatexCommand index
30231 name "Oscilloscope"
30235 with deep trace memory is really helpful especially if you have to debug
30236 a realtime application.
30237 If you need to monitor more pins than your oscilloscope provides you can
30238 sometimes get away with a small R-2R network.
30239 On a single channel oscilloscope you could f.e.
30240 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30242 \begin_inset Formula $\Omega$
30245 resistor and the other one by a 5\InsetSpace ~
30247 \begin_inset Formula $\Omega$
30250 resistor to the oscilloscope probe (check output drive capability of the
30251 pins you want to monitor).
30252 If you need to monitor many more pins a
30259 \begin_layout Itemize
30273 \begin_inset LatexCommand index
30274 name "ICE (in circuit emulator)"
30279 Usually very expensive.
30280 And very nice to have too.
30281 And usually locks you (for years...) to the devices the ICE can emulate.
30285 \begin_layout Itemize
30286 use a remote debugger.
30287 In most 8-bit systems the symbol information is not available on the target,
30288 and a complete debugger is too bulky for the target system.
30289 Therefore usually a debugger on the host system connects to an on-target
30290 debugging stub which accepts only primitive commands.
30293 Terms to enter into your favourite search engine could be 'remote debugging',
30294 'gdb stub' or 'inferior debugger'.
30298 \begin_layout Itemize
30299 use an on target hardware debugger.
30300 Some of the more modern MCUs include hardware support for setting break
30301 points and monitoring/changing variables by using dedicated hardware pins.
30302 This facility doesn't require additional code to run on the target and
30307 doesn't affect runtime behaviour until a breakpoint is hit.
30308 For the mcs51 most hardware debuggers use the AOMF
30309 \begin_inset LatexCommand index
30310 name "AOMF, AOMF51"
30315 \begin_inset LatexCommand ref
30316 reference "OMF file"
30324 \begin_layout Standard
30328 \begin_layout Itemize
30329 if you are not familiar with any of the following terms you're likely to
30330 run into problems rather sooner than later:
30347 As an embedded programmer you
30351 to know them so why not look them up
30355 you have problems?)
30358 \begin_layout Itemize
30359 tell someone else about your problem (actually this is a surprisingly effective
30360 means to hunt down the bug even if the listener is not familiar with your
30362 As 'failure to communicate' is probably one of the job-induced deformations
30363 of an embedded programmer this is highly encouraged.
30366 \begin_layout Section
30367 Debugging with SDCDB
30368 \begin_inset LatexCommand label
30369 name "cha:Debugging-with-SDCDB"
30374 \begin_inset LatexCommand index
30375 name "SDCDB (debugger)"
30382 \begin_layout Standard
30383 SDCC is distributed with a source level debugger
30384 \begin_inset LatexCommand index
30390 The debugger uses a command line interface, the command repertoire of the
30391 debugger has been kept as close to gdb
30392 \begin_inset LatexCommand index
30397 (the GNU debugger) as possible.
30398 The configuration and build process is part of the standard compiler installati
30399 on, which also builds and installs the debugger in the target directory
30400 specified during configuration.
30401 The debugger allows you debug BOTH at the C source and at the ASM source
30405 \begin_layout Subsection
30406 Compiling for Debugging
30409 \begin_layout Standard
30414 \begin_layout Standard
30424 \begin_inset LatexCommand index
30429 option must be specified for all files for which debug information is to
30431 The compiler generates a .adb file for each of these files.
30432 The linker creates the .cdb
30433 \begin_inset LatexCommand index
30439 \begin_inset LatexCommand index
30444 files and the address information.
30445 This .cdb is used by the debugger.
30448 \begin_layout Subsection
30449 How the Debugger Works
30452 \begin_layout Standard
30457 \begin_layout Standard
30466 -debug option is specified the compiler generates extra symbol information
30467 some of which are put into the assembler source and some are put into the
30469 Then the linker creates the .cdb file from the individual .adb files with
30470 the address information for the symbols.
30471 The debugger reads the symbolic information generated by the compiler &
30472 the address information generated by the linker.
30473 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30474 execution is controlled by the debugger.
30475 When a command is issued for the debugger, it translates it into appropriate
30476 commands for the simulator.
30477 (Currently SDCDM only connects to the simulator but
30482 \begin_inset LatexCommand url
30483 target "http://ec2drv.sf.net/"
30487 is an effort to connect directly to the hardware.)
30490 \begin_layout Subsection
30491 Starting the Debugger SDCDB
30494 \begin_layout Standard
30495 The debugger can be started using the following command line.
30496 (Assume the file you are debugging has the file name foo).
30510 The debugger will look for the following files.
30513 \begin_layout Itemize
30514 foo.c - the source file.
30517 \begin_layout Itemize
30518 foo.cdb - the debugger symbol information file.
30521 \begin_layout Itemize
30522 foo.ihx - the Intel hex format
30523 \begin_inset LatexCommand index
30524 name "Intel hex format"
30531 \begin_layout Subsection
30532 SDCDB Command Line Options
30535 \begin_layout Itemize
30540 \begin_layout Standard
30549 -directory=<source file directory> this option can used to specify the directory
30551 The debugger will look into the directory list specified for source, cdb
30553 The items in the directory list must be separated by ':', e.g.
30554 if the source files can be in the directories /home/src1 and /home/src2,
30559 \begin_layout Standard
30568 -directory option should be -
30572 \begin_layout Standard
30581 -directory=/home/src1:/home/src2.
30582 Note there can be no spaces in the option.
30586 \begin_layout Itemize
30587 -cd <directory> - change to the <directory>.
30590 \begin_layout Itemize
30591 -fullname - used by GUI front ends.
30594 \begin_layout Itemize
30595 -cpu <cpu-type> - this argument is passed to the simulator please see the
30596 simulator docs for details.
30599 \begin_layout Itemize
30600 -X <Clock frequency > this options is passed to the simulator please see
30601 the simulator docs for details.
30604 \begin_layout Itemize
30605 -s <serial port file> passed to simulator see the simulator docs for details.
30608 \begin_layout Itemize
30609 -S <serial in,out> passed to simulator see the simulator docs for details.
30612 \begin_layout Itemize
30613 -k <port number> passed to simulator see the simulator docs for details.
30616 \begin_layout Subsection
30617 SDCDB Debugger Commands
30620 \begin_layout Standard
30621 As mentioned earlier the command interface for the debugger has been deliberatel
30622 y kept as close the GNU debugger gdb, as possible.
30623 This will help the integration with existing graphical user interfaces
30624 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30625 If you use a graphical user interface for the debugger you can skip this
30629 \begin_layout Subsubsection*
30630 break [line | file:line | function | file:function]
30633 \begin_layout Standard
30634 Set breakpoint at specified line or function:
30643 sdcdb>break foo.c:100
30645 sdcdb>break funcfoo
30647 sdcdb>break foo.c:funcfoo
30650 \begin_layout Subsubsection*
30651 clear [line | file:line | function | file:function ]
30654 \begin_layout Standard
30655 Clear breakpoint at specified line or function:
30664 sdcdb>clear foo.c:100
30666 sdcdb>clear funcfoo
30668 sdcdb>clear foo.c:funcfoo
30671 \begin_layout Subsubsection*
30675 \begin_layout Standard
30676 Continue program being debugged, after breakpoint.
30679 \begin_layout Subsubsection*
30683 \begin_layout Standard
30684 Execute till the end of the current function.
30687 \begin_layout Subsubsection*
30691 \begin_layout Standard
30692 Delete breakpoint number 'n'.
30693 If used without any option clear ALL user defined break points.
30696 \begin_layout Subsubsection*
30697 info [break | stack | frame | registers ]
30700 \begin_layout Itemize
30701 info break - list all breakpoints
30704 \begin_layout Itemize
30705 info stack - show the function call stack.
30708 \begin_layout Itemize
30709 info frame - show information about the current execution frame.
30712 \begin_layout Itemize
30713 info registers - show content of all registers.
30716 \begin_layout Subsubsection*
30720 \begin_layout Standard
30721 Step program until it reaches a different source line.
30722 Note: pressing <return> repeats the last command.
30725 \begin_layout Subsubsection*
30729 \begin_layout Standard
30730 Step program, proceeding through subroutine calls.
30733 \begin_layout Subsubsection*
30737 \begin_layout Standard
30738 Start debugged program.
30741 \begin_layout Subsubsection*
30745 \begin_layout Standard
30746 Print type information of the variable.
30749 \begin_layout Subsubsection*
30753 \begin_layout Standard
30754 print value of variable.
30757 \begin_layout Subsubsection*
30761 \begin_layout Standard
30762 load the given file name.
30763 Note this is an alternate method of loading file for debugging.
30766 \begin_layout Subsubsection*
30770 \begin_layout Standard
30771 print information about current frame.
30774 \begin_layout Subsubsection*
30778 \begin_layout Standard
30779 Toggle between C source & assembly source.
30782 \begin_layout Subsubsection*
30783 ! simulator command
30786 \begin_layout Standard
30787 Send the string following '!' to the simulator, the simulator response is
30789 Note the debugger does not interpret the command being sent to the simulator,
30790 so if a command like 'go' is sent the debugger can loose its execution
30791 context and may display incorrect values.
30794 \begin_layout Subsubsection*
30798 \begin_layout Standard
30801 My name is Bobby Brown"
30804 \begin_layout Subsection
30805 Interfacing SDCDB with DDD
30808 \begin_layout Standard
30809 \begin_inset Note Note
30812 \begin_layout Standard
30813 The screenshot was converted from png to eps with:
30814 \begin_inset Quotes sld
30817 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30818 \begin_inset Quotes srd
30821 which produces a pretty compact eps file which is free from compression
30825 \begin_layout Standard
30826 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30827 as this broke the build system on Sourceforge (pdf-file was broken.
30828 pdflatex does not accept eps files).
30836 \begin_layout Standard
30852 \begin_inset LatexCommand url
30853 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30859 shows a screenshot of a debugging session with DDD
30860 \begin_inset LatexCommand index
30861 name "DDD (debugger)"
30865 (Unix only) on a simulated 8032.
30866 The debugging session might not run as smoothly as the screenshot suggests.
30867 The debugger allows setting of breakpoints, displaying and changing variables,
30868 single stepping through C and assembler code.
30871 The source was compiled with
30885 \begin_layout Standard
30897 -debug ddd_example.c
30910 and DDD was invoked with
30917 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30920 \begin_layout Standard
30921 \begin_inset Note Note
30924 \begin_layout Standard
30925 Check that the double quotes or an apostrophe within the command line survive
30926 the LyX tool chain.
30927 Previously the apostrophes got slanted in the PDF output so a cut and paste
30936 \begin_layout Subsection
30937 Interfacing SDCDB with XEmacs
30938 \begin_inset LatexCommand index
30944 \begin_inset LatexCommand index
30952 \begin_layout Standard
30953 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30954 sdcdb.el and sdcdbsrc.el.
30955 These two files can be found in the $(prefix)/bin directory after the installat
30957 These files need to be loaded into XEmacs for the interface to work.
30958 This can be done at XEmacs startup time by inserting the following into
30959 your '.xemacs' file (which can be found in your HOME directory):
30965 (load-file sdcdbsrc.el)
30971 .xemacs is a lisp file so the () around the command is REQUIRED.
30972 The files can also be loaded dynamically while XEmacs is running, set the
30973 environment variable 'EMACSLOADPATH' to the installation bin directory
30974 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
30975 To start the interface enter the following command:
30989 You will prompted to enter the file name to be debugged.
30994 The command line options that are passed to the simulator directly are
30995 bound to default values in the file sdcdbsrc.el.
30996 The variables are listed below, these values maybe changed as required.
30999 \begin_layout Itemize
31000 sdcdbsrc-cpu-type '51
31003 \begin_layout Itemize
31004 sdcdbsrc-frequency '11059200
31007 \begin_layout Itemize
31008 sdcdbsrc-serial nil
31011 \begin_layout Standard
31012 The following is a list of key mapping for the debugger interface.
31015 \begin_layout Standard
31038 binding\InsetSpace ~
31076 -------\InsetSpace ~
31147 sdcdb-back-from-src\InsetSpace ~
31176 rom-src\InsetSpace ~
31186 SDCDB continue command
31204 sdcdb-step-from-src\InsetSpace ~
31233 hatis-c-sexp\InsetSpace ~
31243 SDCDB ptypecommand for data at
31310 sdcdbsrc-delete\InsetSpace ~
31325 B Delete all breakpoints if no arg
31374 given or delete arg (C-u arg x)
31393 -frame\InsetSpace ~
31408 SDCDB Display current frame if no arg,
31457 given or display frame arg
31525 sdcdbsrc-goto-sdcdb\InsetSpace ~
31535 Goto the SDCDB output buffer
31554 t-c-sexp\InsetSpace ~
31565 SDCDB print command for data at
31632 sdcdbsrc-goto-sdcdb\InsetSpace ~
31643 o the SDCDB output buffer
31661 sdcdbsrc-mode\InsetSpace ~
31677 Toggles Sdcdbsrc mode (turns it
31693 sdcdb-finish-from-src\InsetSpace ~
31701 SDCDB finish command
31735 Set break for line with point
31750 sdcdbsrc-mode\InsetSpace ~
31766 Toggle Sdcdbsrc mode
31782 dbsrc-srcmode\InsetSpace ~
31806 \begin_layout Chapter
31810 \begin_layout Standard
31811 Here are a few guidelines that will help the compiler generate more efficient
31812 code, some of the tips are specific to this compiler others are generally
31813 good programming practice.
31816 \begin_layout Itemize
31817 Use the smallest data type to represent your data-value.
31818 If it is known in advance that the value is going to be less than 256 then
31819 use an 'unsigned char' instead of a 'short' or 'int'.
31820 Please note, that ANSI C requires both signed and unsigned chars to be
31821 promoted to 'signed int'
31822 \begin_inset LatexCommand index
31823 name "promotion to signed int"
31828 \begin_inset Marginal
31831 \begin_layout Standard
31840 before doing any operation.
31842 \begin_inset LatexCommand index
31843 name "type promotion"
31848 \begin_inset LatexCommand label
31849 name "type promotion"
31853 can be omitted, if the result is the same.
31854 The effect of the promotion rules together with the sign-extension is often
31859 \begin_layout Verse
31862 unsigned char uc = 0xfe;
31864 if (uc * uc < 0) /* this is true! */
31877 \begin_layout Standard
31884 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31892 \begin_layout Verse
31895 (unsigned char) -12 / (signed char) -3 = ...
31898 \begin_layout Standard
31899 No, the result is not 4:
31902 \begin_layout Verse
31905 (int) (unsigned char) -12 / (int) (signed char) -3 =
31907 (int) (unsigned char)
31908 0xf4 / (int) (signed char) 0xfd =
31910 (int) 0x00f4 / (int) 0xfffd =
31915 (int) 244 / (int) -3 =
31917 (int) -81 = (int) 0xffaf;
31920 \begin_layout Standard
31921 Don't complain, that gcc gives you a different result.
31922 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31923 Therefore the results are different.
31926 \begin_inset Quotes sld
31930 \begin_inset Quotes srd
31936 \begin_layout Quote
31939 If well-defined overflow characteristics are important and negative values
31940 are not, or if you want to steer clear of sign-extension problems when
31941 manipulating bits or bytes, use one of the corresponding unsigned types.
31942 (Beware when mixing signed and unsigned values in expressions, though.)
31945 character types (especially unsigned char) can be used as "tiny" integers,
31946 doing so is sometimes more trouble than it's worth, due to unpredictable
31947 sign extension and increased code size.
31951 \begin_layout Itemize
31952 Use unsigned when it is known in advance that the value is not going to
31954 This helps especially if you are doing division or multiplication, bit-shifting
31955 or are using an array index.
31958 \begin_layout Itemize
31959 NEVER jump into a LOOP.
31962 \begin_layout Itemize
31963 Declare the variables to be local
31964 \begin_inset LatexCommand index
31965 name "local variables"
31969 whenever possible, especially loop control variables (induction).
31972 \begin_layout Itemize
31973 Have a look at the assembly listing to get a
31974 \begin_inset Quotes sld
31978 \begin_inset Quotes srd
31981 for the code generation.
31984 \begin_layout Section
31985 Porting code from or to other compilers
31986 \begin_inset LatexCommand label
31987 name "sec:Porting-code-to-other-compilers"
31994 \begin_layout Itemize
31995 check whether endianness of the compilers differs and adapt where needed.
31998 \begin_layout Itemize
31999 check the device specific header files
32000 \begin_inset LatexCommand index
32001 name "Header files"
32006 \begin_inset LatexCommand index
32007 name "Include files"
32011 for compiler specific syntax.
32012 Eventually include the file <compiler.h
32013 \begin_inset LatexCommand index
32014 name "compiler.h (include file)"
32019 \begin_inset LatexCommand url
32020 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32024 to allow using common header files.
32027 \begin_inset LatexCommand url
32028 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32035 \begin_layout Itemize
32036 check whether the startup code contains the correct initialization (watchdog,
32040 \begin_layout Itemize
32041 check whether the sizes of short, int, long match.
32044 \begin_layout Itemize
32045 check if some 16 or 32 bit hardware registers require a specific addressing
32046 order (least significant or most significant byte first) and adapt if needed
32055 relate to time and not to lower/upper memory location here, so this is
32060 the same as endianness).
32063 \begin_layout Itemize
32064 check whether the keyword
32068 is used where needed.
32069 The compilers might differ in their optimization characteristics (as different
32070 versions of the same compiler might also use more clever optimizations
32071 this is good idea anyway).
32073 \begin_inset LatexCommand ref
32074 reference "sub:Common-interrupt-pitfall-volatile"
32081 \begin_layout Itemize
32082 check that the compilers are not told to suppress warnings.
32085 \begin_layout Itemize
32086 check and convert compiler specific extensions (interrupts, memory areas,
32090 \begin_layout Itemize
32091 check for differences in type promotion.
32092 Especially check for math operations on
32101 For the sake of C99 compatibility SDCC will probably promote these to
32105 more often than other compilers.
32106 Eventually insert explicit casts to
32115 Also check that the ~\InsetSpace ~
32117 \begin_inset LatexCommand index
32118 name "\\~\\/ Operator"
32125 \begin_inset LatexCommand index
32132 variables, use the !\InsetSpace ~
32135 \begin_inset LatexCommand ref
32136 reference "type promotion"
32141 \begin_inset LatexCommand ref
32142 reference "sec:Compatibility-with-previous"
32149 \begin_layout Itemize
32150 check the assembly code generated for interrupt routines (f.e.
32151 for calls to possibly non-reentrant library functions).
32154 \begin_layout Itemize
32155 check whether timing loops result in proper timing (or preferably consider
32156 a rewrite of the code with timer based delays instead).
32159 \begin_layout Itemize
32160 check for differences in printf parameters (some compilers push (va_arg
32161 \begin_inset LatexCommand index
32162 name "vararg, va\\_arg"
32166 ) char variables as
32170 others push them as
32176 \begin_inset LatexCommand ref
32177 reference "sec:Compatibility-with-previous"
32184 \begin_layout Itemize
32185 check the resulting memory map
32186 \begin_inset LatexCommand index
32192 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32193 ly idata, pdata, xdata).
32194 Eventually check if unexpected library functions are included.
32197 \begin_layout Section
32199 \begin_inset LatexCommand index
32204 included in the distribution
32207 \begin_layout Standard
32209 \begin_inset Tabular
32210 <lyxtabular version="3" rows="12" columns="3">
32212 <column alignment="left" valignment="top" leftline="true" width="0pt">
32213 <column alignment="left" valignment="top" leftline="true" width="0pt">
32214 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32215 <row topline="true" bottomline="true">
32216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32219 \begin_layout Standard
32227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32230 \begin_layout Standard
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32241 \begin_layout Standard
32250 <row topline="true">
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32254 \begin_layout Standard
32256 \begin_inset LatexCommand index
32266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32269 \begin_layout Standard
32270 Simulator for various architectures
32275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32278 \begin_layout Standard
32285 <row topline="true">
32286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32289 \begin_layout Standard
32295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32298 \begin_layout Standard
32300 \begin_inset LatexCommand index
32301 name "Header files"
32306 \begin_inset LatexCommand index
32307 name "Include files"
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32319 \begin_layout Standard
32320 sdcc/support/scripts
32326 <row topline="true">
32327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32330 \begin_layout Standard
32336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32339 \begin_layout Standard
32340 header file conversion
32345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32348 \begin_layout Standard
32349 sdcc/support/scripts
32355 <row topline="true">
32356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32359 \begin_layout Standard
32365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32368 \begin_layout Standard
32374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32377 \begin_layout Standard
32393 <row topline="true">
32394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32397 \begin_layout Standard
32403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32406 \begin_layout Standard
32412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32415 \begin_layout Standard
32431 <row topline="true">
32432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32435 \begin_layout Standard
32441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32444 \begin_layout Standard
32450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32453 \begin_layout Standard
32469 <row topline="true">
32470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32473 \begin_layout Standard
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32482 \begin_layout Standard
32488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32491 \begin_layout Standard
32507 <row topline="true">
32508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32511 \begin_layout Standard
32517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32520 \begin_layout Standard
32526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32529 \begin_layout Standard
32545 <row topline="true">
32546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32549 \begin_layout Standard
32555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32558 \begin_layout Standard
32564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32567 \begin_layout Standard
32583 <row topline="true">
32584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32587 \begin_layout Standard
32593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32596 \begin_layout Standard
32602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32605 \begin_layout Standard
32621 <row topline="true" bottomline="true">
32622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32625 \begin_layout Standard
32631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32634 \begin_layout Standard
32636 \begin_inset LatexCommand index
32637 name "packihx (tool)"
32646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32649 \begin_layout Standard
32674 \begin_layout Section
32676 \begin_inset LatexCommand index
32677 name "Documentation"
32681 included in the distribution
32684 \begin_layout Standard
32686 \begin_inset Tabular
32687 <lyxtabular version="3" rows="10" columns="2">
32689 <column alignment="block" valignment="top" leftline="true" width="40col%">
32690 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32691 <row topline="true" bottomline="true" endhead="true">
32692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32695 \begin_layout Standard
32703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32706 \begin_layout Standard
32709 Filename / Where to get
32715 <row topline="true">
32716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32719 \begin_layout Standard
32720 SDCC Compiler User Guide
32725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32728 \begin_layout Standard
32729 You're reading it right now
32741 \begin_inset LatexCommand url
32742 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32752 <row topline="true">
32753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32756 \begin_layout Standard
32762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32765 \begin_layout Standard
32778 \begin_inset LatexCommand url
32779 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32789 <row topline="true">
32790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32793 \begin_layout Standard
32795 \begin_inset LatexCommand index
32796 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32801 \begin_inset LatexCommand index
32802 name "Assembler documentation"
32809 \begin_inset LatexCommand index
32815 \begin_inset LatexCommand index
32816 name "Linker documentation"
32825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32828 \begin_layout Standard
32829 sdcc/as/doc/asxhtm.html
32841 \begin_inset LatexCommand url
32842 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32852 <row topline="true">
32853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32856 \begin_layout Standard
32857 SDCC regression test
32858 \begin_inset LatexCommand index
32859 name "Regression test"
32868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32871 \begin_layout Standard
32872 sdcc/doc/test_suite_spec.pdf
32884 \begin_inset LatexCommand url
32885 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32895 <row topline="true">
32896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32899 \begin_layout Standard
32905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32908 \begin_layout Standard
32921 \begin_inset LatexCommand url
32922 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32932 <row topline="true">
32933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32936 \begin_layout Standard
32937 Notes on debugging with SDCDB
32938 \begin_inset LatexCommand index
32939 name "SDCDB (debugger)"
32948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32951 \begin_layout Standard
32952 sdcc/debugger/README
32964 \begin_inset LatexCommand url
32965 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32975 <row topline="true">
32976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32979 \begin_layout Standard
32981 \begin_inset LatexCommand index
32986 Software simulator for microcontrollers
32991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32994 \begin_layout Standard
33024 \begin_inset LatexCommand url
33025 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33035 <row topline="true">
33036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33039 \begin_layout Standard
33040 Temporary notes on the pic16
33041 \begin_inset LatexCommand index
33051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33054 \begin_layout Standard
33055 sdcc/src/pic16/NOTES
33067 \begin_inset LatexCommand url
33068 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33078 <row topline="true" bottomline="true">
33079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33082 \begin_layout Standard
33083 SDCC internal documentation (debugging file format)
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33091 \begin_layout Standard
33121 \begin_inset LatexCommand url
33122 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33141 \begin_layout Section
33142 Related open source tools
33143 \begin_inset LatexCommand label
33144 name "sec:Related-open-source-tools"
33149 \begin_inset LatexCommand index
33150 name "Related tools"
33157 \begin_layout Standard
33159 \begin_inset Tabular
33160 <lyxtabular version="3" rows="16" columns="3">
33162 <column alignment="left" valignment="top" leftline="true" width="0pt">
33163 <column alignment="block" valignment="top" leftline="true" width="30line%">
33164 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33165 <row topline="true" bottomline="true">
33166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33169 \begin_layout Standard
33177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33180 \begin_layout Standard
33188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33191 \begin_layout Standard
33200 <row topline="true">
33201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33204 \begin_layout Standard
33206 \begin_inset LatexCommand index
33207 name "gpsim (pic simulator)"
33216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33219 \begin_layout Standard
33225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33228 \begin_layout Standard
33229 \begin_inset LatexCommand url
33230 target "http://www.dattalo.com/gnupic/gpsim.html"
33240 <row topline="true">
33241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33244 \begin_layout Standard
33246 \begin_inset LatexCommand index
33247 name "gputils (pic tools)"
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33259 \begin_layout Standard
33265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33268 \begin_layout Standard
33269 \begin_inset LatexCommand url
33270 target "http://sourceforge.net/projects/gputils"
33280 <row topline="true">
33281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33284 \begin_layout Standard
33290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33293 \begin_layout Standard
33299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33302 \begin_layout Standard
33303 \begin_inset LatexCommand url
33304 target "http://freshmeat.net/projects/flp5/"
33314 <row topline="true">
33315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33318 \begin_layout Standard
33324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33327 \begin_layout Standard
33328 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33337 \begin_layout Standard
33338 \begin_inset LatexCommand url
33339 target "http://sourceforge.net/projects/ec2drv"
33349 <row topline="true">
33350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33353 \begin_layout Standard
33355 \begin_inset LatexCommand index
33356 name "indent (source formatting tool)"
33365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33368 \begin_layout Standard
33369 Formats C source - Master of the white spaces
33374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33377 \begin_layout Standard
33378 \begin_inset LatexCommand url
33379 target "http://directory.fsf.org/GNU/indent.html"
33389 <row topline="true">
33390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33393 \begin_layout Standard
33395 \begin_inset LatexCommand index
33396 name "srecord (bin, hex, ... tool)"
33405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33408 \begin_layout Standard
33409 Object file conversion, checksumming, ...
33414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33417 \begin_layout Standard
33418 \begin_inset LatexCommand url
33419 target "http://sourceforge.net/projects/srecord"
33429 <row topline="true">
33430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33433 \begin_layout Standard
33435 \begin_inset LatexCommand index
33436 name "objdump (tool)"
33445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33448 \begin_layout Standard
33449 Object file conversion, ...
33454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33457 \begin_layout Standard
33458 Part of binutils (should be there anyway)
33464 <row topline="true">
33465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33468 \begin_layout Standard
33474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33477 \begin_layout Standard
33478 8051 monitor (hex up-/download, single step, disassemble)
33483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33486 \begin_layout Standard
33487 \begin_inset LatexCommand url
33488 target "http://sourceforge.net/projects/cmon51"
33498 <row topline="true">
33499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33502 \begin_layout Standard
33504 \begin_inset LatexCommand index
33505 name "doxygen (source documentation tool)"
33514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33517 \begin_layout Standard
33518 Source code documentation system
33523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33526 \begin_layout Standard
33527 \begin_inset LatexCommand url
33528 target "http://www.doxygen.org"
33538 <row topline="true">
33539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33542 \begin_layout Standard
33548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33551 \begin_layout Standard
33552 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33560 \begin_layout Standard
33561 \begin_inset LatexCommand url
33562 target "http://www.kdevelop.org"
33572 <row topline="true">
33573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33576 \begin_layout Standard
33582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33585 \begin_layout Standard
33586 8051 monitor (hex up-/download, single step, disassemble)
33591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33594 \begin_layout Standard
33595 \begin_inset LatexCommand url
33596 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33606 <row topline="true">
33607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33610 \begin_layout Standard
33612 \begin_inset LatexCommand index
33613 name "splint (syntax checking tool)"
33622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33625 \begin_layout Standard
33626 Statically checks c sources (see
33627 \begin_inset LatexCommand ref
33628 reference "lyx:more-pedantic-SPLINT"
33637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33640 \begin_layout Standard
33641 \begin_inset LatexCommand url
33642 target "http://www.splint.org"
33652 <row topline="true" bottomline="true">
33653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33656 \begin_layout Standard
33658 \begin_inset LatexCommand index
33659 name "DDD (debugger)"
33668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33671 \begin_layout Standard
33672 Debugger, serves nicely as GUI to SDCDB
33673 \begin_inset LatexCommand index
33674 name "SDCDB (debugger)"
33683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33686 \begin_layout Standard
33687 \begin_inset LatexCommand url
33688 target "http://www.gnu.org/software/ddd/"
33698 <row bottomline="true">
33699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33702 \begin_layout Standard
33704 \begin_inset LatexCommand index
33710 \begin_inset LatexCommand index
33711 name "d52 (disassembler)"
33720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33723 \begin_layout Standard
33724 Disassembler, can count instruction cycles
33725 \begin_inset LatexCommand index
33726 name "instruction cycles (count)"
33730 , use with options -pnd
33735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33738 \begin_layout Standard
33739 \begin_inset LatexCommand url
33740 target "http://www.8052.com/users/disasm/"
33750 <row bottomline="true">
33751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33754 \begin_layout Standard
33756 \begin_inset LatexCommand index
33766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33769 \begin_layout Standard
33770 Cross platform build system, generates Makefiles
33771 \begin_inset LatexCommand index
33776 and project workspaces
33777 \begin_inset LatexCommand index
33778 name "project workspace"
33787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33790 \begin_layout Standard
33791 \begin_inset LatexCommand url
33792 target "http://www.cmake.org"
33800 and a dedicated wiki entry:
33801 \begin_inset LatexCommand url
33802 target "http://www.cmake.org/Wiki/CmakeSdcc"
33821 \begin_layout Section
33822 Related documentation / recommended reading
33825 \begin_layout Standard
33827 \begin_inset Tabular
33828 <lyxtabular version="3" rows="7" columns="3">
33830 <column alignment="left" valignment="top" leftline="true" width="0pt">
33831 <column alignment="left" valignment="top" leftline="true" width="0">
33832 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33833 <row topline="true" bottomline="true">
33834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33837 \begin_layout Standard
33845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33848 \begin_layout Standard
33856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33859 \begin_layout Standard
33868 <row topline="true">
33869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33872 \begin_layout Standard
33887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33890 \begin_layout Standard
33892 \begin_inset LatexCommand index
33893 name "C Reference card"
33902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33905 \begin_layout Standard
33906 \begin_inset LatexCommand url
33907 target "http://refcards.com/refcards/c/index.html"
33917 <row topline="true">
33918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33921 \begin_layout Standard
33927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33930 \begin_layout Standard
33932 \begin_inset LatexCommand index
33942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33945 \begin_layout Standard
33946 \begin_inset LatexCommand url
33947 target "http://www.c-faq.com"
33957 <row topline="true">
33958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33961 \begin_layout Standard
33967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33970 \begin_layout Standard
33971 \begin_inset Quotes sld
33975 \begin_inset Quotes srd
33983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33986 \begin_layout Standard
33989 \begin_inset LatexCommand url
33990 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34000 <row topline="true">
34001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34004 \begin_layout Standard
34010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34013 \begin_layout Standard
34014 \begin_inset Quotes sld
34017 Extensions for Embedded C
34018 \begin_inset Quotes srd
34026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34029 \begin_layout Standard
34032 \begin_inset LatexCommand url
34033 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34043 <row topline="true">
34044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34047 \begin_layout Standard
34053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34056 \begin_layout Standard
34057 Latest datasheet of target CPU
34062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34065 \begin_layout Standard
34072 <row topline="true" bottomline="true">
34073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34076 \begin_layout Standard
34082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34085 \begin_layout Standard
34086 Revision history of datasheet
34091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34094 \begin_layout Standard
34110 \begin_layout Section
34111 Application notes specifically for SDCC
34114 \begin_layout Standard
34115 SDCC makes no claims about the completeness of this list and about up-to-datenes
34116 s or correctness of the application notes
34117 \begin_inset LatexCommand index
34118 name "Application notes"
34125 \begin_layout Standard
34129 \begin_inset Tabular
34130 <lyxtabular version="3" rows="7" columns="3">
34132 <column alignment="block" valignment="top" leftline="true" width="17col%">
34133 <column alignment="block" valignment="top" leftline="true" width="27col%">
34134 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34135 <row topline="true" bottomline="true">
34136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34139 \begin_layout Standard
34148 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34151 \begin_layout Standard
34160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34163 \begin_layout Standard
34173 <row topline="true">
34174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34177 \begin_layout Standard
34185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34188 \begin_layout Standard
34191 Using the SDCC Compiler for the DS80C400
34192 \begin_inset LatexCommand index
34202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34205 \begin_layout Standard
34208 \begin_inset LatexCommand url
34209 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34219 <row topline="true">
34220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34223 \begin_layout Standard
34231 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34234 \begin_layout Standard
34237 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34238 \begin_inset LatexCommand index
34243 Family of Microcontrollers
34248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34251 \begin_layout Standard
34254 \begin_inset LatexCommand url
34255 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34265 <row topline="true">
34266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34269 \begin_layout Standard
34272 Silicon Laboratories / Cygnal
34277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34280 \begin_layout Standard
34283 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34284 \begin_inset LatexCommand index
34294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34297 \begin_layout Standard
34300 \begin_inset LatexCommand url
34301 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34311 <row topline="true">
34312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34315 \begin_layout Standard
34318 Ramtron / Goal Semiconductor
34323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34326 \begin_layout Standard
34329 Interfacing SDCC to Syn and Textpad
34334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34337 \begin_layout Standard
34340 \begin_inset LatexCommand url
34341 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34351 <row topline="true">
34352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34355 \begin_layout Standard
34358 Ramtron / Goal Semiconductor
34363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34366 \begin_layout Standard
34369 Installing and Configuring SDCC and Crimson Editor
34374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34377 \begin_layout Standard
34380 \begin_inset LatexCommand url
34381 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34391 <row topline="true" bottomline="true">
34392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34395 \begin_layout Standard
34403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34406 \begin_layout Standard
34409 MSC12xx Programming with SDCC
34414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34417 \begin_layout Standard
34420 \begin_inset LatexCommand url
34421 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34438 \begin_layout Section
34442 \begin_layout Standard
34443 Some questions answered, some pointers given - it might be time to in turn
34451 \begin_layout Itemize
34452 can you solve your project with the selected microcontroller? Would you
34453 find out early or rather late that your target is too small/slow/whatever?
34454 Can you switch to a slightly better device if it doesn't fit?
34457 \begin_layout Itemize
34458 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34459 and/or another programming language be more adequate? Would an operating
34460 system on the target device help?
34463 \begin_layout Itemize
34464 if you solved the problem, will the marketing department be happy?
34467 \begin_layout Itemize
34468 if the marketing department is happy, will customers be happy?
34471 \begin_layout Itemize
34472 if you're the project manager, marketing department and maybe even the customer
34473 in one person, have you tried to see the project from the outside?
34476 \begin_layout Itemize
34477 is the project done if you think it is done? Or is just that other interface/pro
34478 tocol/feature/configuration/option missing? How about website, manual(s),
34479 internationali(z|s)ation, packaging, labels, 2nd source for components,
34480 electromagnetic compatability/interference, documentation for production,
34481 production test software, update mechanism, patent issues?
34484 \begin_layout Itemize
34485 is your project adequately positioned in that magic triangle: fame, fortune,
34489 \begin_layout Standard
34490 Maybe not all answers to these questions are known and some answers may
34495 , nevertheless knowing these questions may help you to avoid burnout
34499 \begin_layout Standard
34500 burnout is bad for electronic devices, programmers and motorcycle tyres
34506 Chances are you didn't want to hear some of them...
34509 \begin_layout Chapter
34511 \begin_inset LatexCommand index
34519 \begin_layout Standard
34520 SDCC has grown to be a large project.
34521 The compiler alone (without the preprocessor, assembler and linker) is
34522 well over 150,000 lines of code (blank stripped).
34523 The open source nature of this project is a key to its continued growth
34525 You gain the benefit and support of many active software developers and
34527 Is SDCC perfect? No, that's why we need your help.
34528 The developers take pride in fixing reported bugs.
34529 You can help by reporting the bugs and helping other SDCC users.
34530 There are lots of ways to contribute, and we encourage you to take part
34531 in making SDCC a great software package.
34535 \begin_layout Standard
34536 The SDCC project is hosted on the SDCC sourceforge site at
34537 \begin_inset LatexCommand htmlurl
34538 target "http://sourceforge.net/projects/sdcc"
34543 You'll find the complete set of mailing lists
34544 \begin_inset LatexCommand index
34545 name "Mailing list(s)"
34549 , forums, bug reporting system, patch submission
34550 \begin_inset LatexCommand index
34551 name "Patch submission"
34556 \begin_inset LatexCommand index
34561 area and Subversion code repository
34562 \begin_inset LatexCommand index
34563 name "Subversion code repository"
34570 \begin_layout Section
34572 \begin_inset LatexCommand index
34573 name "Bug reporting"
34578 \begin_inset LatexCommand index
34579 name "Reporting bugs"
34586 \begin_layout Standard
34587 The recommended way of reporting bugs is using the infrastructure of the
34589 You can follow the status of bug reports there and have an overview about
34593 \begin_layout Standard
34594 Bug reports are automatically forwarded to the developer mailing list and
34595 will be fixed ASAP.
34596 When reporting a bug, it is very useful to include a small test program
34597 (the smaller the better) which reproduces the problem.
34598 If you can isolate the problem by looking at the generated assembly code,
34599 this can be very helpful.
34600 Compiling your program with the -
34604 \begin_layout Standard
34614 \begin_inset LatexCommand index
34615 name "-\\/-dumpall"
34619 option can sometimes be useful in locating optimization problems.
34620 When reporting a bug please make sure you:
34623 \begin_layout Enumerate
34624 Attach the code you are compiling with SDCC.
34628 \begin_layout Enumerate
34629 Specify the exact command you use to run SDCC, or attach your Makefile.
34633 \begin_layout Enumerate
34634 Specify the SDCC version (type "
34640 "), your platform, and operating system.
34644 \begin_layout Enumerate
34645 Provide an exact copy of any error message or incorrect output.
34649 \begin_layout Enumerate
34650 Put something meaningful in the subject of your message.
34653 \begin_layout Standard
34654 Please attempt to include these 5 important parts, as applicable, in all
34655 requests for support or when reporting any problems or bugs with SDCC.
34656 Though this will make your message lengthy, it will greatly improve your
34657 chance that SDCC users and developers will be able to help you.
34658 Some SDCC developers are frustrated by bug reports without code provided
34659 that they can use to reproduce and ultimately fix the problem, so please
34660 be sure to provide sample code if you are reporting a bug!
34663 \begin_layout Standard
34664 Please have a short check that you are using a recent version of SDCC and
34665 the bug is not yet known.
34666 This is the link for reporting bugs:
34667 \begin_inset LatexCommand htmlurl
34668 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34673 With SDCC on average having more than 200 downloads
34674 \begin_inset LatexCommand index
34679 on sourceforge per day
34683 \begin_layout Standard
34684 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34685 between 2002 and 2005.
34686 This does not include other methods of distribution.
34691 there must be some users.
34692 So it's not exactly easy to find a new bug.
34693 If you find one we need it:
34695 reporting bugs is good
34700 \begin_layout Section
34701 Requesting Features
34702 \begin_inset LatexCommand label
34703 name "sub:Requesting-Features"
34708 \begin_inset LatexCommand index
34709 name "Feature request"
34714 \begin_inset LatexCommand index
34715 name "Requesting features"
34722 \begin_layout Standard
34723 Like bug reports feature requests are forwarded to the developer mailing
34725 This is the link for requesting features:
34726 \begin_inset LatexCommand htmlurl
34727 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34734 \begin_layout Section
34738 \begin_layout Standard
34739 Like bug reports contributed patches are forwarded to the developer mailing
34741 This is the link for submitting patches
34742 \begin_inset LatexCommand index
34743 name "Patch submission"
34748 \begin_inset LatexCommand url
34749 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34756 \begin_layout Standard
34757 You need to specify some parameters to the
34761 command for the patches to be useful.
34762 If you modified more than one file a patch created f.e.
34767 \begin_inset Quotes sld
34770 diff -Naur unmodified_directory modified_directory >my_changes.patch
34771 \begin_inset Quotes srd
34777 will be fine, otherwise
34781 \begin_inset Quotes sld
34784 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34785 \begin_inset Quotes srd
34794 \begin_layout Section
34798 \begin_layout Standard
34799 These links should take you directly to the
34800 \begin_inset LatexCommand url
34801 name "Mailing lists"
34802 target "http://sourceforge.net/mail/?group_id=599"
34810 \begin_layout Standard
34811 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34812 automated messages (mid 2003)
34818 \begin_inset LatexCommand url
34820 target "http://sourceforge.net/forum/?group_id=599"
34825 \begin_inset LatexCommand index
34826 name "Mailing list(s)"
34830 and forums are archived and searchable so if you are lucky someone already
34831 had a similar problem.
34832 While mails to the lists themselves are delivered promptly their web front
34833 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34834 if you're seriously using SDCC please consider subscribing to the lists.
34837 \begin_layout Section
34841 \begin_layout Standard
34842 You can follow the status of the Subversion version
34843 \begin_inset LatexCommand index
34848 of SDCC by watching the Changelog
34849 \begin_inset LatexCommand index
34854 in the Subversion repository
34857 \begin_inset LatexCommand htmlurl
34858 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34865 \begin_layout Section
34866 Subversion Source Code Repository
34869 \begin_layout Standard
34879 \begin_layout Standard
34893 or the filenames of the snapshot versions of SDCC include date and its
34895 \begin_inset LatexCommand index
34896 name "Subversion code repository"
34901 Subversion allows to download the source of recent or previous versions
34903 \begin_inset LatexCommand url
34904 target "http://sourceforge.net/svn/?group_id=599"
34908 (by number or by date).
34909 An on-line source code browser and detailled instructions are also available
34911 SDCC versions starting from 1999 up to now are available (currently the
34912 versions prior to the conversion from cvs
34913 \begin_inset LatexCommand index
34914 name "cvs|see{Subversion}"
34918 to Subversion (April 2006) are either by accessible by Subversion or by
34922 \begin_layout Section
34924 \begin_inset LatexCommand index
34925 name "Release policy"
34932 \begin_layout Standard
34933 Historically there often were long delays between official releases and
34934 the sourceforge download area tends to get not updated at all.
34935 Excuses in the past might have referred to problems with live range analysis,
34936 but as this was fixed a while ago, the current problem is that another
34937 excuse has to be found.
34938 Kidding aside, we have to get better there! On the other hand there are
34939 daily snapshots available at
34940 \begin_inset LatexCommand htmlurl
34942 target "http://sdcc.sourceforge.net/snap.php"
34946 , and you can always build the very last version (hopefully with many bugs
34947 fixed, and features added) from the source code available at
34948 \begin_inset LatexCommand htmlurl
34950 target "http://sdcc.sourceforge.net/snap.php#Source"
34956 \begin_inset LatexCommand index
34962 \begin_inset LatexCommand index
34968 \begin_inset LatexCommand url
34969 target "http://sdcc.wiki.sourceforge.net/"
34973 also holds some information about past and future releases.
34976 \begin_layout Section
34978 \begin_inset LatexCommand index
34986 \begin_layout Standard
34987 You'll find some small examples in the directory
34989 sdcc/device/examples/.
34992 More examples and libraries are available at
34994 The SDCC Open Knowledge Resource
34995 \begin_inset LatexCommand url
34996 target "http://sdccokr.dl9sec.de/"
35003 \begin_inset LatexCommand url
35004 target "http://www.pjrc.com/tech/8051/"
35011 \begin_layout Standard
35012 \begin_inset Note Note
35015 \begin_layout Standard
35016 I did insert a reference to Paul's web site here although it seems rather
35017 dedicated to a specific 8032 board (I think it's okay because it f.e.
35018 shows LCD/Harddisc interface and has a free 8051 monitor.
35019 Independent 8032 board vendors face hard competition of heavily subsidized
35020 development boards anyway).
35023 \begin_layout Standard
35024 Maybe we should include some links to real world applications.
35025 Preferably pointer to pointers (one for each architecture) so this stays
35034 \begin_layout Section
35036 \begin_inset LatexCommand label
35037 name "sec:Quality-control"
35042 \begin_inset LatexCommand index
35043 name "Quality control"
35050 \begin_layout Standard
35051 The compiler is passed through snaphot build compile and build checks.
35057 \begin_inset LatexCommand index
35058 name "Regression test"
35062 check that SDCC itself compiles flawlessly on several host platforms (i386,
35063 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35064 and checks the quality of the code generated by SDCC by running the code
35065 for several target platforms through simulators.
35066 The regression test suite comprises more than 100 files which expand to
35067 more than 500 test cases which include more than 4500 tests.
35068 The results of these tests are published daily on SDCC's snapshot page
35069 (click on the red or green symbols on the right side of
35070 \begin_inset LatexCommand url
35071 target "http://sdcc.sourceforge.net/snap.php"
35078 \begin_layout Standard
35079 There is a separate document
35082 \begin_inset LatexCommand index
35090 \begin_inset LatexCommand url
35091 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35095 about the regression test suite.
35098 \begin_layout Standard
35099 You'll find the test code in the directory
35101 sdcc/support/regression
35104 You can run these tests manually by running
35108 in this directory (or f.e.
35113 \begin_inset Quotes sld
35117 \begin_inset Quotes srd
35123 if you don't want to run the complete tests).
35124 The test code might also be interesting if you want to look for examples
35125 \begin_inset LatexCommand index
35130 checking corner cases of SDCC or if you plan to submit patches
35131 \begin_inset LatexCommand index
35132 name "Patch submission"
35139 \begin_layout Standard
35140 The PIC14 port uses a different set of regression tests
35141 \begin_inset LatexCommand index
35142 name "Regression test (PIC14)"
35146 , you'll find them in the directory
35148 sdcc/src/regression
35153 \begin_layout Section
35154 Use of SDCC in Education
35157 \begin_layout Standard
35166 \begin_layout Standard
35167 the phrase "use in education" might evoke the association "
35171 fit for use in education".
35172 This connotation is not intended but nevertheless risked as the licensing
35173 of SDCC makes it difficult to offer educational discounts
35179 If your rationales are to:
35182 \begin_layout Enumerate
35183 give students a chance to understand the
35187 steps of code generation
35190 \begin_layout Enumerate
35191 have a curriculum that can be extended for years.
35192 Then you could use an fpga board as target and your curriculum will seamlessly
35193 extend from logic synthesis (
35194 \begin_inset LatexCommand url
35195 name "http://www.opencores.org"
35196 target "opencores.org"
35201 \begin_inset LatexCommand url
35203 target "http://www.oregano.at/ip/ip01.htm"
35207 ), over assembly programming, to C to FPGA compilers (
35208 \begin_inset LatexCommand url
35210 target "http://sf.net/projects/fpgac"
35217 \begin_layout Enumerate
35218 be able to insert excursions about skills like using a revision control
35219 system, submitting/applying patches, using a type-setting (as opposed to
35220 word-processing) engine LyX/LaTeX, using
35221 \begin_inset LatexCommand url
35223 target "http://www.sf.net"
35228 \begin_inset LatexCommand url
35230 target "http://en.wikipedia.org/wiki/Netiquette"
35234 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35235 Source Software, CPU simulation, compiler regression tests
35236 \begin_inset LatexCommand index
35237 name "Regression test"
35244 And if there should be a shortage of ideas then you can always point students
35245 to the ever-growing feature request list
35246 \begin_inset LatexCommand htmlurl
35247 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35254 \begin_layout Enumerate
35255 not tie students to a specific host platform and instead allow them to use
35260 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35262 \begin_inset LatexCommand url
35264 target "http://www.laptop.org"
35271 \begin_layout Enumerate
35272 not encourage students to use illegal copies of educational software
35275 \begin_layout Enumerate
35276 be immune to licensing/availability/price changes of the chosen tool chain
35279 \begin_layout Enumerate
35280 be able to change to a new target platform without having to adopt a new
35284 \begin_layout Enumerate
35285 have complete control over and insight into the tool chain
35288 \begin_layout Enumerate
35289 make your students aware about the pros and cons of open source software
35293 \begin_layout Enumerate
35294 give back to the public as you are probably at least partially publicly
35298 \begin_layout Enumerate
35299 give students a chance to publicly prove their skills and to possibly see
35300 a world wide impact
35303 \begin_layout Standard
35304 then SDCC is probably among the first choices.
35305 Well, probably SDCC might be the only choice.
35310 \begin_layout Chapter
35311 SDCC Technical Data
35314 \begin_layout Section
35316 \begin_inset LatexCommand index
35317 name "Optimizations"
35324 \begin_layout Standard
35325 SDCC performs a host of standard optimizations in addition to some MCU specific
35330 \begin_layout Subsection
35331 Sub-expression Elimination
35332 \begin_inset LatexCommand index
35333 name "Subexpression elimination"
35340 \begin_layout Standard
35341 The compiler does local and
35360 \begin_layout Verse
35368 \begin_layout Standard
35369 will be translated to
35372 \begin_layout Verse
35382 \begin_layout Standard
35383 Some subexpressions are not as obvious as the above example, e.g.:
35386 \begin_layout Verse
35394 \begin_layout Standard
35395 In this case the address arithmetic a->b[i] will be computed only once;
35396 the equivalent code in C would be.
35399 \begin_layout Verse
35409 \begin_layout Standard
35410 The compiler will try to keep these temporary variables in registers.
35413 \begin_layout Subsection
35414 Dead-Code Elimination
35415 \begin_inset LatexCommand index
35416 name "Dead-code elimination"
35423 \begin_layout Verse
35438 i = 1; \InsetSpace ~
35447 global = 1;\InsetSpace ~
35461 global = 3;\InsetSpace ~
35467 \begin_layout Standard
35471 \begin_layout Verse
35487 \begin_layout Subsection
35489 \begin_inset LatexCommand index
35490 name "Copy propagation"
35497 \begin_layout Verse
35521 \begin_layout Standard
35525 \begin_layout Verse
35549 \begin_layout Standard
35550 Note: the dead stores created by this copy propagation will be eliminated
35551 by dead-code elimination.
35554 \begin_layout Subsection
35556 \begin_inset LatexCommand index
35557 name "Loop optimization"
35562 \begin_inset LatexCommand label
35563 name "sub:Loop-Optimizations"
35570 \begin_layout Standard
35571 Two types of loop optimizations are done by SDCC
35579 of loop induction variables.
35580 In addition to the strength reduction the optimizer marks the induction
35581 variables and the register allocator tries to keep the induction variables
35582 in registers for the duration of the loop.
35583 Because of this preference of the register allocator
35584 \begin_inset LatexCommand index
35585 name "Register allocation"
35589 , loop induction optimization causes an increase in register pressure, which
35590 may cause unwanted spilling of other temporary variables into the stack
35591 \begin_inset LatexCommand index
35597 The compiler will generate a warning message when it is forced to allocate
35598 extra space either on the stack or data space.
35599 If this extra space allocation is undesirable then induction optimization
35600 can be eliminated either for the entire source file (with -
35604 \begin_layout Standard
35613 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35615 \begin_inset LatexCommand index
35616 name "\\#pragma noinduction"
35627 \begin_layout Verse
35630 for (i = 0 ; i < 100 ; i ++)
35639 \begin_layout Standard
35643 \begin_layout Verse
35648 for (i = 0; i < 100; i++)
35657 \begin_layout Standard
35658 As mentioned previously some loop invariants are not as apparent, all static
35659 address computations are also moved out of the loop.
35664 \begin_inset LatexCommand index
35665 name "Strength reduction"
35669 , this optimization substitutes an expression by a cheaper expression:
35672 \begin_layout Verse
35675 for (i=0;i < 100; i++)
35684 \begin_layout Standard
35688 \begin_layout Verse
35695 for (i=0;i< 100;i++) {
35701 ar[itemp1] = itemp2;
35719 \begin_layout Standard
35720 The more expensive multiplication
35721 \begin_inset LatexCommand index
35722 name "Multiplication"
35726 is changed to a less expensive addition.
35729 \begin_layout Subsection
35731 \begin_inset LatexCommand index
35732 name "Loop reversing"
35739 \begin_layout Standard
35740 This optimization is done to reduce the overhead of checking loop boundaries
35741 for every iteration.
35742 Some simple loops can be reversed and implemented using a
35743 \begin_inset Quotes eld
35746 decrement and jump if not zero
35747 \begin_inset Quotes erd
35751 SDCC checks for the following criterion to determine if a loop is reversible
35752 (note: more sophisticated compilers use data-dependency analysis to make
35753 this determination, SDCC uses a more simple minded analysis).
35756 \begin_layout Itemize
35757 The 'for' loop is of the form
35763 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35773 \begin_layout Itemize
35774 The <for body> does not contain
35775 \begin_inset Quotes eld
35779 \begin_inset Quotes erd
35783 \begin_inset Quotes erd
35789 \begin_layout Itemize
35790 All goto's are contained within the loop.
35793 \begin_layout Itemize
35794 No function calls within the loop.
35797 \begin_layout Itemize
35798 The loop control variable <sym> is not assigned any value within the loop
35801 \begin_layout Itemize
35802 The loop control variable does NOT participate in any arithmetic operation
35806 \begin_layout Itemize
35807 There are NO switch statements in the loop.
35810 \begin_layout Subsection
35811 Algebraic Simplifications
35814 \begin_layout Standard
35815 SDCC does numerous algebraic simplifications, the following is a small sub-set
35816 of these optimizations.
35819 \begin_layout Verse
35822 i = j + 0;\InsetSpace ~
35826 /* changed to: */\InsetSpace ~
35832 i /= 2;\InsetSpace ~
35839 /* changed to: */\InsetSpace ~
35846 = j - j;\InsetSpace ~
35850 /* changed to: */\InsetSpace ~
35856 i = j / 1;\InsetSpace ~
35860 /* changed to: */\InsetSpace ~
35867 \begin_layout Standard
35868 Note the subexpressions
35869 \begin_inset LatexCommand index
35870 name "Subexpression"
35874 given above are generally introduced by macro expansions or as a result
35875 of copy/constant propagation.
35878 \begin_layout Subsection
35879 'switch' Statements
35880 \begin_inset LatexCommand label
35881 name "sub:'switch'-Statements"
35886 \begin_inset LatexCommand index
35887 name "switch statement"
35894 \begin_layout Standard
35895 SDCC can optimize switch statements to jump tables
35896 \begin_inset LatexCommand index
35902 It makes the decision based on an estimate of the generated code size.
35903 SDCC is quite liberal in the requirements for jump table generation:
35906 \begin_layout Itemize
35907 The labels need not be in order, and the starting number need not be one
35908 or zero, the case labels are in numerical sequence or not too many case
35909 labels are missing.
35913 \begin_layout Verse
35916 switch(i) {\InsetSpace ~
35947 case 4: ...\InsetSpace ~
35979 case 5: ...\InsetSpace ~
36011 case 3: ...\InsetSpace ~
36042 case 6: ...\InsetSpace ~
36074 case 7: ...\InsetSpace ~
36106 case 8: ...\InsetSpace ~
36138 case 9: ...\InsetSpace ~
36170 case 10: ...\InsetSpace ~
36201 case 11: ...\InsetSpace ~
36268 \begin_layout Standard
36269 Both the above switch statements will be implemented using a jump-table.
36270 The example to the right side is slightly more efficient as the check for
36271 the lower boundary of the jump-table is not needed.
36275 \begin_layout Itemize
36276 The number of case labels is not larger than supported by the target architectur
36280 \begin_layout Itemize
36281 If the case labels are not in numerical sequence ('gaps' between cases)
36282 SDCC checks whether a jump table with additionally inserted dummy cases
36283 is still attractive.
36287 \begin_layout Itemize
36288 If the starting number is not zero and a check for the lower boundary of
36289 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36294 \begin_layout Standard
36295 Switch statements which have large gaps in the numeric sequence or those
36296 that have too many case labels can be split into more than one switch statement
36297 for efficient code generation, e.g.:
36300 \begin_layout Verse
36378 \begin_layout Standard
36379 If the above switch statement is broken down into two switch statements
36382 \begin_layout Verse
36425 \begin_layout Standard
36429 \begin_layout Verse
36472 \begin_layout Standard
36473 then both the switch statements will be implemented using jump-tables whereas
36474 the unmodified switch statement will not be.
36477 \begin_layout Standard
36478 \begin_inset Note Note
36481 \begin_layout Standard
36482 There might be reasons which SDCC cannot know about to either favour or
36483 not favour jump tables.
36484 If the target system has to be as quick for the last switch case as for
36485 the first (pro jump table), or if the switch argument is known to be zero
36486 in the majority of the cases (contra jump table).
36494 \begin_layout Standard
36495 The pragma nojtbound
36496 \begin_inset LatexCommand index
36497 name "\\#pragma nojtbound"
36501 can be used to turn off checking the
36514 It has no effect if a default label is supplied.
36515 Use of this pragma is dangerous: if the switch
36516 \begin_inset LatexCommand index
36517 name "switch statement"
36521 argument is not matched by a case statement the processor will happily
36525 \begin_layout Subsection
36526 Bit-shifting Operations
36527 \begin_inset LatexCommand index
36528 name "Bit shifting"
36535 \begin_layout Standard
36536 Bit shifting is one of the most frequently used operation in embedded programmin
36538 SDCC tries to implement bit-shift operations in the most efficient way
36542 \begin_layout Verse
36555 \begin_layout Standard
36556 generates the following code:
36559 \begin_layout Verse
36574 \begin_layout Standard
36575 In general SDCC will never setup a loop if the shift count is known.
36579 \begin_layout Verse
36592 \begin_layout Standard
36596 \begin_layout Verse
36620 \begin_layout Subsection
36622 \begin_inset LatexCommand index
36623 name "Bit rotation"
36630 \begin_layout Standard
36631 A special case of the bit-shift operation is bit rotation
36632 \begin_inset LatexCommand index
36633 name "rotating bits"
36637 , SDCC recognizes the following expression to be a left bit-rotation:
36640 \begin_layout Verse
36648 char i;\InsetSpace ~
36659 /* unsigned is needed for rotation */
36664 i = ((i << 1) | (i >> 7));
36673 \begin_layout Standard
36674 will generate the following code:
36677 \begin_layout Verse
36694 \begin_layout Standard
36695 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36696 ns of this case will also be recognized as bit-rotation, i.e.:
36699 \begin_layout Verse
36702 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36705 \begin_layout Subsection
36706 Nibble and Byte Swapping
36709 \begin_layout Standard
36710 Other special cases of the bit-shift operations are nibble or byte swapping
36711 \begin_inset LatexCommand index
36712 name "swapping nibbles/bytes"
36716 , SDCC recognizes the following expressions:
36719 \begin_layout Verse
36740 i = ((i << 4) | (i >> 4));
36746 j = ((j << 8) | (j >> 8));
36749 \begin_layout Standard
36750 and generates a swap instruction for the nibble swapping
36751 \begin_inset LatexCommand index
36752 name "Nibble swapping"
36756 or move instructions for the byte swapping
36757 \begin_inset LatexCommand index
36758 name "Byte swapping"
36764 \begin_inset Quotes sld
36768 \begin_inset Quotes srd
36771 example can be used to convert from little to big-endian or vice versa.
36772 If you want to change the endianness of a
36776 integer you have to cast to
36783 \begin_layout Standard
36784 Note that SDCC stores numbers in little-endian
36788 \begin_layout Standard
36789 Usually 8-bit processors don't care much about endianness.
36790 This is not the case for the standard 8051 which only has an instruction
36796 \begin_inset LatexCommand index
36801 -datapointer so little-endian is the more efficient byte order.
36807 \begin_inset LatexCommand index
36808 name "little-endian"
36813 \begin_inset LatexCommand index
36819 lowest order first).
36822 \begin_layout Subsection
36824 \begin_inset LatexCommand index
36825 name "Highest Order Bit"
36830 \begin_inset LatexCommand index
36831 name "Any Order Bit"
36838 \begin_layout Standard
36839 It is frequently required to obtain the highest order bit of an integral
36840 type (long, int, short or char types).
36841 Also obtaining any other order bit is not uncommon.
36842 SDCC recognizes the following expressions to yield the highest order bit
36843 and generates optimized code for it, e.g.:
36846 \begin_layout Verse
36857 unsigned char hob1, aob1;
36861 bit hob2, hob3, aob2,
36871 hob1 = (gint >> 15) & 1;
36875 hob2 = (gint >> 15) & 1;
36879 hob3 = gint & 0x8000;
36884 aob1 = (gint >> 9) & 1;
36888 aob2 = (gint >> 8) & 1;
36892 aob3 = gint & 0x0800;
36902 \begin_layout Standard
36903 will generate the following code:
36906 \begin_layout Verse
36937 000A E5*01\InsetSpace ~
36964 000C 23\InsetSpace ~
36995 000D 54 01\InsetSpace ~
37023 000F F5*02\InsetSpace ~
37078 0011 E5*01\InsetSpace ~
37106 0013 33\InsetSpace ~
37136 0014 92*00\InsetSpace ~
37192 0016 E5*01\InsetSpace ~
37219 0018 33\InsetSpace ~
37249 0019 92*01\InsetSpace ~
37305 001B E5*01\InsetSpace ~
37364 001E 54 01\InsetSpace ~
37391 0020 F5*03\InsetSpace ~
37447 0022 E5*01\InsetSpace ~
37474 0024 13\InsetSpace ~
37504 0025 92*02\InsetSpace ~
37560 0027 E5*01\InsetSpace ~
37615 002B 92*03\InsetSpace ~
37643 \begin_layout Standard
37644 Other variations of these cases however will
37649 They are standard C expressions, so I heartily recommend these be the only
37650 way to get the highest order bit, (it is portable).
37651 Of course it will be recognized even if it is embedded in other expressions,
37655 \begin_layout Verse
37658 xyz = gint + ((gint >> 15) & 1);
37661 \begin_layout Standard
37662 will still be recognized.
37665 \begin_layout Subsection
37667 \begin_inset LatexCommand index
37668 name "Higher Order Byte"
37672 / Higher Order Word
37673 \begin_inset LatexCommand index
37674 name "Higher Order Word"
37681 \begin_layout Standard
37682 It is also frequently required to obtain a higher order byte or word of
37683 a larger integral type (long, int or short types).
37684 SDCC recognizes the following expressions to yield the higher order byte
37685 or word and generates optimized code for it, e.g.:
37688 \begin_layout Verse
37693 unsigned long int glong;
37701 unsigned char hob1,
37706 unsigned int how1, how2;
37715 hob1 = (gint >> 8) & 0xFF;
37719 hob2 = glong >> 24;
37723 how1 = (glong >> 16) & 0xFFFF;
37738 \begin_layout Standard
37739 will generate the following code:
37742 \begin_layout Verse
37773 0037 85*01*06\InsetSpace ~
37795 _foo_hob1_1_1,(_gint + 1)
37826 003A 85*05*07\InsetSpace ~
37848 _foo_hob2_1_1,(_glong + 3)
37878 003D 85*04*08\InsetSpace ~
37901 _foo_how1_1_1,(_glong + 2)
37903 0040 85*05*09\InsetSpace ~
37928 0043 85*03*0A\InsetSpace ~
37950 _foo_how2_1_1,(_glong + 1)
37952 0046 85*04*0B\InsetSpace ~
37975 (_foo_how2_1_1 + 1),(_glong + 2)
37978 \begin_layout Standard
37979 Again, variations of these cases may
37984 They are standard C expressions, so I heartily recommend these be the only
37985 way to get the higher order byte/word, (it is portable).
37986 Of course it will be recognized even if it is embedded in other expressions,
37990 \begin_layout Verse
37993 xyz = gint + ((gint >> 8) & 0xFF);
37996 \begin_layout Standard
37997 will still be recognized.
38000 \begin_layout Subsection
38002 \begin_inset LatexCommand label
38003 name "sub:Peephole-Optimizer"
38008 \begin_inset LatexCommand index
38009 name "Peephole optimizer"
38016 \begin_layout Standard
38017 The compiler uses a rule based, pattern matching and re-writing mechanism
38018 for peep-hole optimization.
38023 a peep-hole optimizer by Christopher W.
38024 Fraser (cwfraser\InsetSpace ~
38027 A default set of rules are compiled into the compiler, additional rules
38028 may be added with the
38034 \begin_layout Standard
38044 \begin_inset LatexCommand index
38045 name "-\\/-peep-file"
38052 The rule language is best illustrated with examples.
38055 \begin_layout Verse
38077 \begin_layout Standard
38078 The above rule will change the following assembly
38079 \begin_inset LatexCommand index
38080 name "Assembler routines"
38087 \begin_layout Verse
38095 \begin_layout Standard
38099 \begin_layout Verse
38105 \begin_layout Standard
38106 Note: All occurrences of a
38110 (pattern variable) must denote the same string.
38111 With the above rule, the assembly sequence:
38114 \begin_layout Verse
38122 \begin_layout Standard
38123 will remain unmodified.
38127 Other special case optimizations may be added by the
38134 \begin_layout Standard
38147 some variants of the 8051 MCU
38148 \begin_inset LatexCommand index
38149 name "MCS51 variants"
38162 The following two rules will change all
38179 \begin_layout Verse
38182 replace { lcall %1 } by { acall %1 }
38184 replace { ljmp %1 } by { ajmp %1 }
38187 \begin_layout Standard
38188 (NOTE: from version 2.7.3 on, you can use option -
38194 \begin_layout Standard
38206 \begin_inset LatexCommand index
38207 name "-\\/-acall-ajmp"
38211 , which also takes care of aligning the interrupt vectors properly.)
38216 \begin_layout Standard
38219 inline-assembler code
38221 is also passed through the peep hole optimizer, thus the peephole optimizer
38222 can also be used as an assembly level macro expander.
38223 The rules themselves are MCU dependent whereas the rule language infra-structur
38224 e is MCU independent.
38225 Peephole optimization rules for other MCU can be easily programmed using
38230 The syntax for a rule is as follows:
38233 \begin_layout Verse
38236 rule := replace [ restart ] '{' <assembly sequence> '
38274 <assembly sequence> '
38292 '}' [if <functionName> ] '
38297 \begin_layout Standard
38298 <assembly sequence> := assembly instruction (each instruction including
38299 labels must be on a separate line).
38303 The optimizer will apply to the rules
38304 one by one from the top in the sequence of their appearance, it will terminate
38305 when all rules are exhausted.
38306 If the 'restart' option is specified, then the optimizer will start matching
38307 the rules again from the top, this option for a rule is expensive (performance)
38308 , it is intended to be used in situations where a transformation will trigger
38309 the same rule again.
38310 An example of this (not a good one, it has side effects) is the following
38314 \begin_layout Verse
38334 \begin_layout Standard
38335 Note that the replace pattern cannot be a blank, but can be a comment line.
38336 Without the 'restart' option only the innermost 'pop' 'push' pair would
38337 be eliminated, i.e.:
38340 \begin_layout Verse
38352 \begin_layout Standard
38356 \begin_layout Verse
38366 \begin_layout Standard
38371 the restart option the rule will be applied again to the resulting code
38372 and then all the pop-push pairs will be eliminated to yield:
38375 \begin_layout Verse
38383 \begin_layout Standard
38384 A conditional function can be attached to a rule.
38385 Attaching rules are somewhat more involved, let me illustrate this with
38389 \begin_layout Verse
38413 \begin_layout Standard
38414 The optimizer does a look-up of a function name table defined in function
38419 in the source file SDCCpeeph.c, with the name
38424 If it finds a corresponding entry the function is called.
38425 Note there can be no parameters specified for these functions, in this
38430 is crucial, since the function
38434 expects to find the label in that particular variable (the hash table containin
38435 g the variable bindings is passed as a parameter).
38436 If you want to code more such functions, take a close look at the function
38437 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38438 Currently implemented are
38440 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38441 24bitMode, portIsDS390, 24bitModeAndPortDS390
38450 \begin_layout Standard
38451 I know this whole thing is a little kludgey, but maybe some day we will
38452 have some better means.
38453 If you are looking at this file, you will see the default rules that are
38454 compiled into the compiler, you can add your own rules in the default set
38455 there if you get tired of specifying the -
38459 \begin_layout Standard
38471 \begin_layout Section
38473 \begin_inset LatexCommand index
38474 name "ANSI-compliance"
38479 \begin_inset LatexCommand label
38480 name "sub:ANSI-Compliance"
38487 \begin_layout Standard
38488 The latest publicly available version of the standard
38490 ISO/IEC 9899 - Programming languages - C
38492 should be available at:
38493 \begin_inset LatexCommand url
38494 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38503 \begin_layout Standard
38504 Deviations from the compliance:
38507 \begin_layout Itemize
38508 functions are not reentrant
38509 \begin_inset LatexCommand index
38514 unless explicitly declared as such or the
38520 \begin_layout Standard
38530 \begin_inset LatexCommand index
38531 name "-\\/-stack-auto"
38537 command line option is specified.
38540 \begin_layout Itemize
38542 \begin_inset LatexCommand index
38548 \begin_inset LatexCommand index
38553 cannot be assigned values directly, cannot be passed as function parameters
38554 or assigned to each other and cannot be a return value
38555 \begin_inset LatexCommand index
38556 name "return value"
38560 from a function, e.g.:
38564 \begin_layout Verse
38587 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38612 s parms) /* invalid in SDCC although allowed in ANSI */
38634 return rets; /* is invalid in SDCC although allowed in ANSI */
38640 \begin_layout Itemize
38641 initialization of structure arrays must be fully braced.
38645 \begin_layout Verse
38648 struct s { char x } a[] = {1, 2};\InsetSpace ~
38653 /* invalid in SDCC */
38656 } a[] = {{1}, {2}}; /* OK */
38660 \begin_layout Itemize
38662 \begin_inset LatexCommand index
38663 name "long long (not supported)"
38668 \begin_inset LatexCommand index
38669 name "int (64 bit) (not supported)"
38676 \begin_layout Itemize
38678 \begin_inset LatexCommand index
38679 name "double (not supported)"
38683 ' precision floating point
38684 \begin_inset LatexCommand index
38685 name "Floating point support"
38692 \begin_layout Itemize
38694 \begin_inset LatexCommand index
38699 function declarations are NOT allowed.
38703 \begin_layout Verse
38706 foo(i,j) /* this old style of function declarations */
38708 int i,j; /* is valid
38709 in ANSI but not valid in SDCC */
38724 \begin_layout Itemize
38725 Most enhancements in C99 are not supported, e.g.:
38729 \begin_layout Verse
38739 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38743 \begin_layout Itemize
38744 But some have been added recently in SDCC 2.7.0.
38745 They must be considered alpha quality however.
38749 \begin_layout Verse
38754 \begin_inset LatexCommand index
38755 name "inline (not supported)"
38764 int increment (int a) { return a+1; } /* inlines the increment without function
38773 \begin_inset LatexCommand index
38774 name "inline (not supported)"
38783 p; /* accepted but ignored */
38787 \begin_layout Itemize
38788 Certain words that are valid identifiers in the standard may be reserved
38789 words in SDCC unless the
38795 \begin_layout Standard
38805 \begin_inset LatexCommand index
38806 name "-\\/-std-c89"
38818 \begin_layout Standard
38828 \begin_inset LatexCommand index
38829 name "-\\/-std-c99"
38835 command line options are used.
38836 These may include (depending on the selected processor): 'at', 'banked',
38837 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38838 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38839 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38841 Compliant equivalents of these keywords are always available in a form
38842 that begin with two underscores
38843 \begin_inset LatexCommand index
38844 name "\\_\\_ (prefix for extended keywords)"
38849 '__data' instead of 'data'.
38852 \begin_layout Itemize
38853 Integer promotion of variable arguments is not performed if the argument
38854 is explicitly taypecasted unless the
38860 \begin_layout Standard
38870 \begin_inset LatexCommand index
38871 name "-\\/-std-c89"
38883 \begin_layout Standard
38893 \begin_inset LatexCommand index
38894 name "-\\/-std-c99"
38900 command line options are used.
38904 \begin_layout Verse
38907 void vararg_func (char *str, ...) { str; }
38924 u is promoted to int before
38929 * passing to function */
38933 vararg_func ("%c", c);
38940 argument u is not promoted to int,
38945 * it is passed as char to function
38951 --std-cXX is not defined;
38956 * is promoted to int before passing
38962 if --std-cXX is defined */
38966 vararg_func ("%bc", (char)u);
38972 \begin_layout Section
38973 Cyclomatic Complexity
38974 \begin_inset LatexCommand index
38975 name "Cyclomatic complexity"
38982 \begin_layout Standard
38983 Cyclomatic complexity of a function is defined as the number of independent
38984 paths the program can take during execution of the function.
38985 This is an important number since it defines the number test cases you
38986 have to generate to validate the function.
38987 The accepted industry standard for complexity number is 10, if the cyclomatic
38988 complexity reported by SDCC exceeds 10 you should think about simplification
38989 of the function logic.
38990 Note that the complexity level is not related to the number of lines of
38991 code in a function.
38992 Large functions can have low complexity, and small functions can have large
38998 SDCC uses the following formula to compute the complexity:
39003 \begin_layout Standard
39004 complexity = (number of edges in control flow graph) - (number of nodes
39005 in control flow graph) + 2;
39009 Having said that the industry standard is 10,
39010 you should be aware that in some cases it be may unavoidable to have a
39011 complexity level of less than 10.
39012 For example if you have switch statement with more than 10 case labels,
39013 each case label adds one to the complexity level.
39014 The complexity level is by no means an absolute measure of the algorithmic
39015 complexity of the function, it does however provide a good starting point
39016 for which functions you might look at for further optimization.
39019 \begin_layout Section
39020 Retargetting for other Processors
39023 \begin_layout Standard
39024 The issues for retargetting the compiler are far too numerous to be covered
39026 What follows is a brief description of each of the seven phases of the
39027 compiler and its MCU dependency.
39030 \begin_layout Itemize
39031 Parsing the source and building the annotated parse tree.
39032 This phase is largely MCU independent (except for the language extensions).
39033 Syntax & semantic checks are also done in this phase, along with some initial
39034 optimizations like back patching labels and the pattern matching optimizations
39035 like bit-rotation etc.
39038 \begin_layout Itemize
39039 The second phase involves generating an intermediate code which can be easy
39040 manipulated during the later phases.
39041 This phase is entirely MCU independent.
39042 The intermediate code generation assumes the target machine has unlimited
39043 number of registers, and designates them with the name iTemp.
39044 The compiler can be made to dump a human readable form of the code generated
39049 \begin_layout Standard
39061 \begin_layout Itemize
39062 This phase does the bulk of the standard optimizations and is also MCU independe
39064 This phase can be broken down into several sub-phases:
39068 Break down intermediate
39069 code (iCode) into basic blocks.
39071 Do control flow & data flow analysis on the
39074 Do local common subexpression elimination, then global subexpressio
39077 Dead code elimination
39081 If loop optimizations
39082 caused any changes then do 'global subexpression elimination' and 'dead
39083 code elimination' again.
39086 \begin_layout Itemize
39087 This phase determines the live-ranges; by live range I mean those iTemp
39088 variables defined by the compiler that still survive after all the optimization
39090 Live range analysis
39091 \begin_inset LatexCommand index
39092 name "Live range analysis"
39096 is essential for register allocation, since these computation determines
39097 which of these iTemps will be assigned to registers, and for how long.
39100 \begin_layout Itemize
39101 Phase five is register allocation.
39102 There are two parts to this process.
39106 The first part I call 'register packing'
39107 (for lack of a better term).
39108 In this case several MCU specific expression folding is done to reduce
39113 The second part is more MCU independent and deals with
39114 allocating registers to the remaining live ranges.
39115 A lot of MCU specific code does creep into this phase because of the limited
39116 number of index registers available in the 8051.
39119 \begin_layout Itemize
39120 The Code generation phase is (unhappily), entirely MCU dependent and very
39121 little (if any at all) of this code can be reused for other MCU.
39122 However the scheme for allocating a homogenized assembler operand for each
39123 iCode operand may be reused.
39126 \begin_layout Itemize
39127 As mentioned in the optimization section the peep-hole optimizer is rule
39128 based system, which can reprogrammed for other MCUs.
39131 \begin_layout Standard
39132 More information is available on SDCC Wiki
39133 \begin_inset LatexCommand index
39139 \begin_inset LatexCommand url
39140 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39144 ) and in the thread
39145 \begin_inset LatexCommand url
39146 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39153 \begin_layout Chapter
39155 \begin_inset LatexCommand index
39156 name "Compiler internals"
39163 \begin_layout Section
39164 The anatomy of the compiler
39165 \begin_inset LatexCommand label
39166 name "sub:The-anatomy-of"
39173 \begin_layout Standard
39176 This is an excerpt from an article published in Circuit Cellar Magazine
39185 It's a little outdated (the compiler is much more efficient now and user/develo
39186 per friendly), but pretty well exposes the guts of it all.
39192 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39193 It is fairly easy to retarget for other 8-bit MCU.
39194 Here we take a look at some of the internals of the compiler.
39198 \begin_layout Paragraph*
39200 \begin_inset LatexCommand index
39208 \begin_layout Standard
39209 Parsing the input source file and creating an AST (Annotated Syntax Tree
39210 \begin_inset LatexCommand index
39211 name "Annotated syntax tree"
39216 This phase also involves propagating types (annotating each node of the
39217 parse tree with type information) and semantic analysis.
39218 There are some MCU specific parsing rules.
39219 For example the storage classes, the extended storage classes are MCU specific
39220 while there may be a xdata storage class for 8051 there is no such storage
39221 class for z80 or Atmel AVR.
39222 SDCC allows MCU specific storage class extensions, i.e.
39223 xdata will be treated as a storage class specifier when parsing 8051 C
39224 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39228 \begin_layout Paragraph*
39230 \begin_inset LatexCommand index
39238 \begin_layout Standard
39239 Intermediate code generation.
39240 In this phase the AST is broken down into three-operand form (iCode).
39241 These three operand forms are represented as doubly linked lists.
39242 ICode is the term given to the intermediate form generated by the compiler.
39243 ICode example section shows some examples of iCode generated for some simple
39244 C source functions.
39247 \begin_layout Paragraph*
39249 \begin_inset LatexCommand index
39250 name "Optimizations"
39257 \begin_layout Standard
39258 Bulk of the target independent optimizations is performed in this phase.
39259 The optimizations include constant propagation, common sub-expression eliminati
39260 on, loop invariant code movement, strength reduction of loop induction variables
39261 and dead-code elimination.
39264 \begin_layout Paragraph*
39265 Live range analysis
39266 \begin_inset LatexCommand index
39267 name "Live range analysis"
39274 \begin_layout Standard
39275 During intermediate code generation phase, the compiler assumes the target
39276 machine has infinite number of registers and generates a lot of temporary
39278 The live range computation determines the lifetime of each of these compiler-ge
39279 nerated temporaries.
39280 A picture speaks a thousand words.
39281 ICode example sections show the live range annotations for each of the
39283 It is important to note here, each iCode is assigned a number in the order
39284 of its execution in the function.
39285 The live ranges are computed in terms of these numbers.
39286 The from number is the number of the iCode which first defines the operand
39287 and the to number signifies the iCode which uses this operand last.
39290 \begin_layout Paragraph*
39291 Register Allocation
39292 \begin_inset LatexCommand index
39293 name "Register allocation"
39300 \begin_layout Standard
39301 The register allocation determines the type and number of registers needed
39303 In most MCUs only a few registers can be used for indirect addressing.
39304 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39305 address the internal ram and DPTR to indirectly address the external ram.
39306 The compiler will try to allocate the appropriate register to pointer variables
39308 ICode example section shows the operands annotated with the registers assigned
39310 The compiler will try to keep operands in registers as much as possible;
39311 there are several schemes the compiler uses to do achieve this.
39312 When the compiler runs out of registers the compiler will check to see
39313 if there are any live operands which is not used or defined in the current
39314 basic block being processed, if there are any found then it will push that
39315 operand and use the registers in this block, the operand will then be popped
39316 at the end of the basic block.
39320 \begin_layout Standard
39321 There are other MCU specific considerations in this phase.
39322 Some MCUs have an accumulator; very short-lived operands could be assigned
39323 to the accumulator instead of a general-purpose register.
39326 \begin_layout Paragraph*
39330 \begin_layout Standard
39331 Figure II gives a table of iCode
39332 \begin_inset LatexCommand index
39337 operations supported by the compiler.
39338 The code generation involves translating these operations into corresponding
39339 assembly code for the processor.
39340 This sounds overly simple but that is the essence of code generation.
39341 Some of the iCode operations are generated on a MCU specific manner for
39342 example, the z80 port does not use registers to pass parameters so the
39343 SEND and RECV iCode operations will not be generated, and it also does
39344 not support JUMPTABLES.
39350 \begin_layout Standard
39354 \begin_inset Tabular
39355 <lyxtabular version="3" rows="39" columns="4">
39356 <features islongtable="true" headBottomDL="true">
39357 <column alignment="block" valignment="top" leftline="true" width="13col%">
39358 <column alignment="left" valignment="top" leftline="true" width="13col%">
39359 <column alignment="block" valignment="top" leftline="true" width="22col%">
39360 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39361 <row topline="true" bottomline="true" endhead="true">
39362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39365 \begin_layout Standard
39371 \begin_inset LatexCommand index
39381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39384 \begin_layout Standard
39392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39395 \begin_layout Standard
39403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39406 \begin_layout Standard
39415 <row topline="true">
39416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39419 \begin_layout Standard
39427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39430 \begin_layout Standard
39433 IC_LEFT() IC_RESULT()
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39441 \begin_layout Standard
39449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39452 \begin_layout Standard
39455 IC_RESULT = ! IC_LEFT;
39461 <row topline="true">
39462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39465 \begin_layout Standard
39473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39476 \begin_layout Standard
39479 IC_LEFT() IC_RESULT()
39484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39487 \begin_layout Standard
39490 Bitwise complement of
39495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39498 \begin_layout Standard
39501 IC_RESULT = ~IC_LEFT;
39507 <row topline="true">
39508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39511 \begin_layout Standard
39519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39522 \begin_layout Standard
39525 IC_LEFT() IC_RESULT()
39530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39533 \begin_layout Standard
39536 Rotate right with carry
39541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39544 \begin_layout Standard
39547 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39553 <row topline="true">
39554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39557 \begin_layout Standard
39565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39568 \begin_layout Standard
39571 IC_LEFT() IC_RESULT()
39576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39579 \begin_layout Standard
39582 Rotate left with carry
39587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39590 \begin_layout Standard
39593 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39599 <row topline="true">
39600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39603 \begin_layout Standard
39611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39614 \begin_layout Standard
39617 IC_LEFT() IC_RESULT()
39622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39625 \begin_layout Standard
39628 Get the highest order bit of IC_LEFT
39633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39636 \begin_layout Standard
39639 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39645 <row topline="true">
39646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39649 \begin_layout Standard
39657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39660 \begin_layout Standard
39663 IC_LEFT() IC_RESULT()
39668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39671 \begin_layout Standard
39679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39682 \begin_layout Standard
39685 IC_RESULT = - IC_LEFT;
39691 <row topline="true">
39692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39695 \begin_layout Standard
39703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39706 \begin_layout Standard
39714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39717 \begin_layout Standard
39720 Push the operand into stack
39725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39728 \begin_layout Standard
39737 <row topline="true">
39738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39741 \begin_layout Standard
39749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39752 \begin_layout Standard
39760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39763 \begin_layout Standard
39766 Pop the operand from the stack
39771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39774 \begin_layout Standard
39783 <row topline="true">
39784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39787 \begin_layout Standard
39795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39798 \begin_layout Standard
39801 IC_LEFT() IC_RESULT()
39806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39809 \begin_layout Standard
39812 Call the function represented by IC_LEFT
39817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39820 \begin_layout Standard
39823 IC_RESULT = IC_LEFT();
39829 <row topline="true">
39830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39833 \begin_layout Standard
39841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39844 \begin_layout Standard
39847 IC_LEFT() IC_RESULT()
39852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39855 \begin_layout Standard
39858 Call via function pointer
39863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39866 \begin_layout Standard
39869 IC_RESULT = (*IC_LEFT)();
39875 <row topline="true">
39876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39879 \begin_layout Standard
39887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39890 \begin_layout Standard
39898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39901 \begin_layout Standard
39904 Return the value in operand IC_LEFT
39909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39912 \begin_layout Standard
39921 <row topline="true">
39922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39925 \begin_layout Standard
39933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39936 \begin_layout Standard
39944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39947 \begin_layout Standard
39955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39958 \begin_layout Standard
39967 <row topline="true">
39968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39971 \begin_layout Standard
39979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39982 \begin_layout Standard
39990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39993 \begin_layout Standard
40001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40004 \begin_layout Standard
40013 <row topline="true">
40014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40017 \begin_layout Standard
40025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40028 \begin_layout Standard
40031 IC_LEFT() IC_RIGHT() IC_RESULT()
40036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40039 \begin_layout Standard
40047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40050 \begin_layout Standard
40053 IC_RESULT = IC_LEFT + IC_RIGHT
40059 <row topline="true">
40060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40063 \begin_layout Standard
40071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40074 \begin_layout Standard
40077 IC_LEFT() IC_RIGHT() IC_RESULT()
40082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40085 \begin_layout Standard
40093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40096 \begin_layout Standard
40099 IC_RESULT = IC_LEFT - IC_RIGHT
40105 <row topline="true">
40106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40109 \begin_layout Standard
40117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40120 \begin_layout Standard
40123 IC_LEFT() IC_RIGHT() IC_RESULT()
40128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40131 \begin_layout Standard
40139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40142 \begin_layout Standard
40145 IC_RESULT = IC_LEFT * IC_RIGHT;
40151 <row topline="true">
40152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40155 \begin_layout Standard
40163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40166 \begin_layout Standard
40169 IC_LEFT() IC_RIGHT() IC_RESULT()
40174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40177 \begin_layout Standard
40185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40188 \begin_layout Standard
40191 IC_RESULT = IC_LEFT / IC_RIGHT;
40197 <row topline="true">
40198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40201 \begin_layout Standard
40209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40212 \begin_layout Standard
40215 IC_LEFT() IC_RIGHT() IC_RESULT()
40220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40223 \begin_layout Standard
40231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40234 \begin_layout Standard
40237 IC_RESULT = IC_LEFT % IC_RIGHT;
40243 <row topline="true">
40244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40247 \begin_layout Standard
40255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40258 \begin_layout Standard
40261 IC_LEFT() IC_RIGHT() IC_RESULT()
40266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40269 \begin_layout Standard
40277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40280 \begin_layout Standard
40283 IC_RESULT = IC_LEFT < IC_RIGHT;
40289 <row topline="true">
40290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40293 \begin_layout Standard
40301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40304 \begin_layout Standard
40307 IC_LEFT() IC_RIGHT() IC_RESULT()
40312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40315 \begin_layout Standard
40323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40326 \begin_layout Standard
40329 IC_RESULT = IC_LEFT > IC_RIGHT;
40335 <row topline="true">
40336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40339 \begin_layout Standard
40347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40350 \begin_layout Standard
40353 IC_LEFT() IC_RIGHT() IC_RESULT()
40358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40361 \begin_layout Standard
40369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40372 \begin_layout Standard
40375 IC_RESULT = IC_LEFT == IC_RIGHT;
40381 <row topline="true">
40382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40385 \begin_layout Standard
40393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40396 \begin_layout Standard
40399 IC_LEFT() IC_RIGHT() IC_RESULT()
40404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40407 \begin_layout Standard
40410 Logical and operation
40415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40418 \begin_layout Standard
40421 IC_RESULT = IC_LEFT && IC_RIGHT;
40427 <row topline="true">
40428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40431 \begin_layout Standard
40439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40442 \begin_layout Standard
40445 IC_LEFT() IC_RIGHT() IC_RESULT()
40450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40453 \begin_layout Standard
40456 Logical or operation
40461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40464 \begin_layout Standard
40467 IC_RESULT = IC_LEFT || IC_RIGHT;
40473 <row topline="true">
40474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40477 \begin_layout Standard
40485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40488 \begin_layout Standard
40491 IC_LEFT() IC_RIGHT() IC_RESULT()
40496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40499 \begin_layout Standard
40507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40510 \begin_layout Standard
40513 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40519 <row topline="true">
40520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40523 \begin_layout Standard
40531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40534 \begin_layout Standard
40537 IC_LEFT() IC_RIGHT() IC_RESULT()
40542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40545 \begin_layout Standard
40553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40556 \begin_layout Standard
40559 IC_RESULT = IC_LEFT | IC_RIGHT;
40565 <row topline="true">
40566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40569 \begin_layout Standard
40577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40580 \begin_layout Standard
40583 IC_LEFT() IC_RIGHT() IC_RESULT()
40588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40591 \begin_layout Standard
40599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40602 \begin_layout Standard
40605 IC_RESULT = IC_LEFT & IC_RIGHT;
40611 <row topline="true">
40612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40615 \begin_layout Standard
40623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40626 \begin_layout Standard
40629 IC_LEFT() IC_RIGHT() IC_RESULT()
40634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40637 \begin_layout Standard
40645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40648 \begin_layout Standard
40651 IC_RESULT = IC_LEFT << IC_RIGHT
40657 <row topline="true">
40658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40661 \begin_layout Standard
40669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40672 \begin_layout Standard
40675 IC_LEFT() IC_RIGHT() IC_RESULT()
40680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40683 \begin_layout Standard
40691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40694 \begin_layout Standard
40697 IC_RESULT = IC_LEFT >> IC_RIGHT
40703 <row topline="true">
40704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40707 \begin_layout Standard
40717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40720 \begin_layout Standard
40723 IC_LEFT() IC_RESULT()
40728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40731 \begin_layout Standard
40739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40742 \begin_layout Standard
40745 IC_RESULT = (*IC_LEFT);
40751 <row topline="true">
40752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40755 \begin_layout Standard
40763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40766 \begin_layout Standard
40769 IC_RIGHT() IC_RESULT()
40774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40777 \begin_layout Standard
40785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40788 \begin_layout Standard
40791 (*IC_RESULT) = IC_RIGHT;
40797 <row topline="true">
40798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40801 \begin_layout Standard
40809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40812 \begin_layout Standard
40815 IC_RIGHT() IC_RESULT()
40820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40823 \begin_layout Standard
40831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40834 \begin_layout Standard
40837 IC_RESULT = IC_RIGHT;
40843 <row topline="true">
40844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40847 \begin_layout Standard
40855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40858 \begin_layout Standard
40861 IC_COND IC_TRUE IC_LABEL
40866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40869 \begin_layout Standard
40873 If true label is present then jump to true label if condition is true else
40874 jump to false label if condition is false
40879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40882 \begin_layout Standard
40885 if (IC_COND) goto IC_TRUE;
40891 If (!IC_COND) goto IC_FALSE;
40897 <row topline="true">
40898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40901 \begin_layout Standard
40909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40912 \begin_layout Standard
40915 IC_LEFT() IC_RESULT()
40920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40923 \begin_layout Standard
40931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40934 \begin_layout Standard
40937 IC_RESULT = &IC_LEFT();
40943 <row topline="true">
40944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40947 \begin_layout Standard
40955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40958 \begin_layout Standard
40961 IC_JTCOND IC_JTLABELS
40966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40969 \begin_layout Standard
40972 Jump to list of labels depending on the value of JTCOND
40977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40980 \begin_layout Standard
40989 <row topline="true">
40990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40993 \begin_layout Standard
41001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41004 \begin_layout Standard
41007 IC_RIGHT() IC_LEFT() IC_RESULT()
41012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41015 \begin_layout Standard
41023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41026 \begin_layout Standard
41029 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41035 <row topline="true">
41036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41039 \begin_layout Standard
41047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41050 \begin_layout Standard
41058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41061 \begin_layout Standard
41064 This is used for passing parameters in registers;
41066 move IC_LEFT to the next
41067 available parameter register.
41072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41075 \begin_layout Standard
41084 <row topline="true">
41085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41088 \begin_layout Standard
41096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41099 \begin_layout Standard
41107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41110 \begin_layout Standard
41113 This is used for receiving parameters passed in registers;
41116 in the next parameter register to IC_RESULT
41121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41124 \begin_layout Standard
41133 <row topline="true" bottomline="true">
41134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41137 \begin_layout Standard
41141 (some more have been added)
41146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41149 \begin_layout Standard
41155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41158 \begin_layout Standard
41164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41167 \begin_layout Standard
41200 \begin_layout Standard
41201 \begin_inset Note Note
41204 \begin_layout Standard
41205 In the original article Figure II was announced to be downloadable on
41210 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41218 \begin_layout Paragraph*
41220 \begin_inset LatexCommand index
41228 \begin_layout Standard
41229 This section shows some details of iCode.
41230 The example C code does not do anything useful; it is used as an example
41231 to illustrate the intermediate code generated by the compiler.
41234 \begin_layout Verse
41244 /* This function does nothing useful.
41251 for the purpose of explaining iCode */
41254 short function (data
41263 short i=10; \InsetSpace ~
41265 /* dead initialization eliminated */
41271 /* dead initialization eliminated */
41299 /* compiler detects i,j to be induction
41304 for (i = 0, j = 10 ; i < 10 ; i++, j
41310 \begin_layout Standard
41333 mul += i * 3; \InsetSpace ~
41335 /* this multiplication remains */
41342 j * 3;\InsetSpace ~
41344 /* this multiplication changed to addition */
41358 \begin_layout Standard
41359 In addition to the operands each iCode contains information about the filename
41360 and line it corresponds to in the source file.
41361 The first field in the listing should be interpreted as follows:
41366 Filename(linenumber: iCode Execution sequence number : ICode hash table
41367 key : loop depth of the iCode).
41372 Then follows the human readable form of the ICode operation.
41373 Each operand of this triplet form can be of three basic types a) compiler
41374 generated temporary b) user defined variable c) a constant value.
41375 Note that local variables and parameters are replaced by compiler generated
41378 \begin_inset LatexCommand index
41379 name "Live range analysis"
41383 are computed only for temporaries (i.e.
41384 live ranges are not computed for global variables).
41386 \begin_inset LatexCommand index
41387 name "Register allocation"
41391 are allocated for temporaries only.
41392 Operands are formatted in the following manner:
41397 Operand Name [lr live-from : live-to ] { type information } [ registers
41403 As mentioned earlier the live ranges are computed in terms of the execution
41404 sequence number of the iCodes, for example
41406 the iTemp0 is live from (i.e.
41407 first defined in iCode with execution sequence number 3, and is last used
41408 in the iCode with sequence number 5).
41409 For induction variables such as iTemp21 the live range computation extends
41410 the lifetime from the start to the end of the loop.
41412 The register allocator
41413 used the live range information to allocate registers, the same registers
41414 may be used for different temporaries if their live ranges do not overlap,
41415 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41416 ranges do not overlap.
41417 In addition the allocator also takes into consideration the type and usage
41418 of a temporary, for example itemp6 is a pointer to near space and is used
41419 as to fetch data from (i.e.
41420 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41421 Some short lived temporaries are allocated to special registers which have
41422 meaning to the code generator e.g.
41423 iTemp13 is allocated to a pseudo register CC which tells the back end that
41424 the temporary is used only for a conditional jump the code generation makes
41425 use of this information to optimize a compare and jump ICode.
41429 \begin_inset LatexCommand index
41430 name "Loop optimization"
41434 performed by the compiler.
41435 It can detect induction variables iTemp21(i) and iTemp23(j).
41436 Also note the compiler does selective strength reduction
41437 \begin_inset LatexCommand index
41438 name "Strength reduction"
41443 the multiplication of an induction variable in line 18 (gint = j * 3) is
41444 changed to addition, a new temporary iTemp17 is allocated and assigned
41445 a initial value, a constant 3 is then added for each iteration of the loop.
41446 The compiler does not change the multiplication
41447 \begin_inset LatexCommand index
41448 name "Multiplication"
41452 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41455 Note the dead code elimination
41456 \begin_inset LatexCommand index
41457 name "Dead-code elimination"
41461 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41467 \begin_layout Standard
41470 Sample.c (5:1:0:0) _entry($9) :
41473 \begin_layout Standard
41476 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41479 \begin_layout Standard
41482 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41485 \begin_layout Standard
41488 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41491 \begin_layout Standard
41494 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41498 \begin_layout Standard
41501 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41504 \begin_layout Standard
41507 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41511 \begin_layout Standard
41514 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41517 \begin_layout Standard
41520 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41524 \begin_layout Standard
41527 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41531 \begin_layout Standard
41534 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41538 \begin_layout Standard
41541 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41545 \begin_layout Standard
41548 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41549 * int}[r0] + 0x2 {short}
41552 \begin_layout Standard
41555 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41558 \begin_layout Standard
41561 Sample.c(11:17:21:0)_whilebreak_0($3) :
41564 \begin_layout Standard
41567 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41570 \begin_layout Standard
41573 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41576 \begin_layout Standard
41579 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41582 \begin_layout Standard
41585 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41588 \begin_layout Standard
41591 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41594 \begin_layout Standard
41597 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41600 \begin_layout Standard
41603 Sample.c(15:24:26:1)_forcond_0($4) :
41606 \begin_layout Standard
41609 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41613 \begin_layout Standard
41616 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41619 \begin_layout Standard
41622 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41623 + ITemp21 [lr21:38]{short}[r4]
41626 \begin_layout Standard
41629 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41633 \begin_layout Standard
41636 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41637 + iTemp15 [lr29:30]{short}[r1]
41640 \begin_layout Standard
41643 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41647 \begin_layout Standard
41650 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41654 \begin_layout Standard
41657 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41661 \begin_layout Standard
41664 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41668 \begin_layout Standard
41671 Sample.c(19:38:47:1) goto _forcond_0($4)
41674 \begin_layout Standard
41677 Sample.c(19:39:48:0)_forbreak_0($7) :
41680 \begin_layout Standard
41683 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41684 + ITemp11 [lr19:40]{short}[r3]
41687 \begin_layout Standard
41690 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41693 \begin_layout Standard
41696 Sample.c(20:42:51:0)_return($8) :
41699 \begin_layout Standard
41702 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41708 Finally the code generated for this function:
41713 \begin_layout Standard
41719 \begin_layout Standard
41725 \begin_layout Standard
41733 \begin_layout Standard
41739 \begin_layout Standard
41747 \begin_layout Standard
41753 \begin_layout Standard
41756 ; ----------------------------------------------
41759 \begin_layout Standard
41762 ; function function
41765 \begin_layout Standard
41768 ; ----------------------------------------------
41771 \begin_layout Standard
41777 \begin_layout Standard
41780 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41783 \begin_layout Standard
41791 \begin_layout Standard
41794 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41797 \begin_layout Standard
41805 \begin_layout Standard
41808 ;_whilecontinue_0($1) :
41811 \begin_layout Standard
41817 \begin_layout Standard
41820 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41823 \begin_layout Standard
41826 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41829 \begin_layout Standard
41837 \begin_layout Standard
41845 \begin_layout Standard
41853 \begin_layout Standard
41861 \begin_layout Standard
41869 \begin_layout Standard
41877 \begin_layout Standard
41885 \begin_layout Standard
41891 \begin_layout Standard
41894 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41897 \begin_layout Standard
41905 \begin_layout Standard
41913 \begin_layout Standard
41916 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41919 \begin_layout Standard
41927 \begin_layout Standard
41935 \begin_layout Standard
41943 \begin_layout Standard
41951 \begin_layout Standard
41959 \begin_layout Standard
41967 \begin_layout Standard
41970 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
41973 \begin_layout Standard
41981 \begin_layout Standard
41989 \begin_layout Standard
41997 \begin_layout Standard
42005 \begin_layout Standard
42013 \begin_layout Standard
42016 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42019 \begin_layout Standard
42027 \begin_layout Standard
42035 \begin_layout Standard
42043 \begin_layout Standard
42046 ; iTemp6 [lr5:16]{_near * int}[r0] =
42049 \begin_layout Standard
42052 ; iTemp6 [lr5:16]{_near * int}[r0] +
42055 \begin_layout Standard
42061 \begin_layout Standard
42069 \begin_layout Standard
42072 ; goto _whilecontinue_0($1)
42075 \begin_layout Standard
42083 \begin_layout Standard
42086 ; _whilebreak_0($3) :
42089 \begin_layout Standard
42095 \begin_layout Standard
42098 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42101 \begin_layout Standard
42109 \begin_layout Standard
42112 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42115 \begin_layout Standard
42123 \begin_layout Standard
42126 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42129 \begin_layout Standard
42137 \begin_layout Standard
42140 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42143 \begin_layout Standard
42151 \begin_layout Standard
42159 \begin_layout Standard
42162 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42165 \begin_layout Standard
42173 \begin_layout Standard
42181 \begin_layout Standard
42187 \begin_layout Standard
42193 \begin_layout Standard
42196 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42199 \begin_layout Standard
42202 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42205 \begin_layout Standard
42213 \begin_layout Standard
42221 \begin_layout Standard
42229 \begin_layout Standard
42237 \begin_layout Standard
42245 \begin_layout Standard
42251 \begin_layout Standard
42254 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42257 \begin_layout Standard
42260 ; iTemp21 [lr21:38]{short}[r4]
42263 \begin_layout Standard
42271 \begin_layout Standard
42279 \begin_layout Standard
42287 \begin_layout Standard
42290 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42293 \begin_layout Standard
42301 \begin_layout Standard
42309 \begin_layout Standard
42317 \begin_layout Standard
42325 \begin_layout Standard
42328 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42331 \begin_layout Standard
42334 ; iTemp15 [lr29:30]{short}[r1]
42337 \begin_layout Standard
42345 \begin_layout Standard
42353 \begin_layout Standard
42356 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42359 \begin_layout Standard
42367 \begin_layout Standard
42375 \begin_layout Standard
42383 \begin_layout Standard
42391 \begin_layout Standard
42399 \begin_layout Standard
42407 \begin_layout Standard
42410 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42413 \begin_layout Standard
42421 \begin_layout Standard
42429 \begin_layout Standard
42437 \begin_layout Standard
42445 \begin_layout Standard
42453 \begin_layout Standard
42461 \begin_layout Standard
42464 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42467 \begin_layout Standard
42475 \begin_layout Standard
42478 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42481 \begin_layout Standard
42489 \begin_layout Standard
42494 cjne r5,#0xff,00104$
42497 \begin_layout Standard
42505 \begin_layout Standard
42508 ; goto _forcond_0($4)
42511 \begin_layout Standard
42519 \begin_layout Standard
42522 ; _forbreak_0($7) :
42525 \begin_layout Standard
42531 \begin_layout Standard
42534 ; ret iTemp24 [lr40:41]{short}
42537 \begin_layout Standard
42545 \begin_layout Standard
42553 \begin_layout Standard
42561 \begin_layout Standard
42567 \begin_layout Standard
42573 \begin_layout Standard
42583 \begin_layout Section
42584 A few words about basic block successors, predecessors and dominators
42587 \begin_layout Standard
42588 Successors are basic blocks
42589 \begin_inset LatexCommand index
42590 name "Basic blocks"
42594 that might execute after this basic block.
42596 Predecessors are basic blocks
42597 that might execute before reaching this basic block.
42599 Dominators are basic
42600 blocks that WILL execute before reaching this basic block.
42605 \begin_layout Standard
42609 \begin_layout Standard
42613 \begin_layout Standard
42621 \begin_layout Standard
42625 \begin_layout Standard
42633 \begin_layout Standard
42639 \begin_layout Standard
42640 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42643 \begin_layout Standard
42644 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42647 \begin_layout Standard
42648 c) domVect of [BB4] = BB1 ...
42649 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42653 \begin_layout Chapter
42657 \begin_layout Standard
42658 \begin_inset LatexCommand url
42659 target "http://sdcc.sourceforge.net/#Who"
42669 Thanks to all the other volunteer developers who have helped with coding,
42670 testing, web-page creation, distribution sets, etc.
42671 You know who you are :-)
42679 Thanks to Sourceforge
42680 \begin_inset LatexCommand url
42681 target "http://www.sf.net"
42685 which has hosted the project since 1999 and donates significant download
42694 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42695 cycles and bandwidth for snapshot builds.
42700 \begin_layout Standard
42701 This document was initially written by Sandeep Dutta
42704 \begin_layout Standard
42705 All product names mentioned herein may be trademarks
42706 \begin_inset LatexCommand index
42711 of their respective companies.
42715 \begin_layout Section*
42719 \begin_layout Standard
42720 To avoid confusion, the installation and building options for SDCC itself
42721 (chapter 2) are not part of the index.
42724 \begin_layout Standard
42725 \begin_inset LatexCommand printindex